Run Jest tests from meteor test-packages?

Is there a way to run Jest tests from meteor test-packages?

Interesting question. Thus far, I wrote my jest tests such that i don’t have to spin up a meteor server (which I considered a big plus). So I never used jest as a subcommand of meteor. But naively, I would guess you need wrap the jest runner into a package similar to https://github.com/meteortesting/meteor-mocha/tree/master/package. Then you could do something along the lines of meteor test-packages ./ --driver-package captainn:jest.

Question is though, what’s the requirement behind this? To be more specific, why don’t you run your tests w/o meteor like jest path/to/package/test.js?

The Meteor packages make Jest finicky to use. Jest mocks work fine to get around most of the Meteor API, but for more complex integration tests a proper meteor test runner would be helpful. For example, tests that need access to a DB to validate reads and writes.

I was trying to port a set of jest tests (from react-loadable) which leveraged Jest’s snapshot feature heavily. I ended up sort of faking jest’s .toMatchSnapshot, by converting some of the tests and doing the prettyFormat stuff manually, so they can still check against the snaps from the old project. This is probably not maintainable (I have no great way to update new snaps if things change), but it works to validate the component.

I’m using mongodb-memory-server for that part. I’m running all my tests outside of meteor. Which is working fine.

But, I’m not sure if that’s a solution for @captainn, as this involves a meteor package that requires to be tested.

Are you using the meteor mongo API still? If so, how are you getting that to work with Jest? Do the mocks just “proxy” over to the in memory db?

Yes, but I only use rawCollection. That way I have support for the latest Mongo stuff, and I don’t depend on meteor specific wrappers. But meteor will still manage my connection.

These tests don’t really use Meteor at all - I guess I could have ported the tests to use JEST, and had one for each of the client server bundles. Doh! That’d have been easier lol. At least I learned something :slight_smile:

Oh nice! Any code snippets you’d be able to share? Curious to see how you have it set up. Hope you don’t mind me asking.