testingmeteortinytest

Is it safe to rely on 'Facts' package internals for package testing purposes?


I have a package (yeputons/meteor-smart-publish) which uses observeChanges a lot, and I want to add a test (I use TinyTest right now) which allows me to ensure that all such observers are terminated in the end and no handle.stop() was skipped.

The straightforward way is: add the 'Facts' package (which is Meteor-internal), subscribe to 'meteor_facts' and check for observe-handles property of item with _id="mongo-livedata", which is not very safe because it's all undocumented and can be modified in any way in the future.

Is there any more documented way of checking such things?


Solution

  • Facts package was built with a sole purpose to show some moving numbers in a dashboard of your admin interface.

    Here is my proposed solution which is still hacky, but at least can be implemented w/o touching facts and subscriptions on the client:

    You can monkey patch the constructors and stop methods of oplog-observe-driver and polling-driver classes. By wrapping them with a function that just calls the original but validates some state in your tests you can achieve your testing goals:

    https://github.com/meteor/meteor/blob/cf4477ff27cba9f8a8f63ec2f435969af0b6707c/packages/mongo/oplog_observe_driver.js#L29

    https://github.com/meteor/meteor/blob/cf4477ff27cba9f8a8f63ec2f435969af0b6707c/packages/mongo/oplog_observe_driver.js#L853

    https://github.com/meteor/meteor/blob/cf4477ff27cba9f8a8f63ec2f435969af0b6707c/packages/mongo/polling_observe_driver.js#L1

    https://github.com/meteor/meteor/blob/cf4477ff27cba9f8a8f63ec2f435969af0b6707c/packages/mongo/polling_observe_driver.js#L181