Run unit tests without building Meteor app

Has anyone been able to run a suite of tests that doesn’t require Meteor to be built and running?

I’d like to drastically speed up test writing, especially since a lot of tests don’t require Meteor to be running, yet I still have to wait for the whole app to rebuild every time I make a change.

Ideally there’d be some way of figuring out whether any meteor-related dependency has been imported and don’t run those tests. Wondering if anyone has tried something similar to this?

I’ve taken the time to isolate a lot of my business logic into modules that don’t require any Meteor dependencies.

When they need to write to a database I pass in a Repository object that I can easily mock out during tests.

Yeah I use Jest to run unit tests outside Meteor. There’s an option to instruct Jest where to find modules, I use it like this

"moduleNameMapper": {
    "^meteor/(.*)": "<rootDir>/tests/meteor-mocks/$1.js",
    "^[/](.*)": "<rootDir>/$1"
  },

The first one maps imports from meteor/x to a file in tests/meteor-mocks with the same name. So importing meteor/accounts uses tests/meteor-mocks/accounts.js.

Second one makes sure that absolute path imports (/src/imports/foo) work correctly

1 Like

Ah, that’s great advice!

I ended up purchasing a copy of wallabyJS and following some of the great (though sometimes slightly dated) tips on the forums at these links:


https://forums.meteor.com/t/meteor-1-3-testing-with-meteor-meteor-x-package-imports?source_topic_id=38135
The dev branch of this repo: