Thanks, Tom! That looks like it’ll solve the issue of Mocha choking on Meteor package imports. It doesn’t address the fact that my imports are mostly absolute paths, which Mocha doesn’t like. I suppose I could go through my whole project and change everything to relative, but I’ve got a pretty deep folder hierarchy, and would wind up with imports like:
import Thing from '../../../../client/components/Thing';
There must be a way to get Mocha to recognize absolute paths!
EDIT: To be clear, I’m referring to the import statements in my actual code, not the Mocha tests.
Holy crap, THANK YOU. This appears to work, as the test no longer throws an error on the importing from /lib/collections anymore. So now it’s throwing an error here:
Error: Cannot find module 'meteor/mongo'
at Function.Module._resolveFilename (module.js:438:15)
at Function.Module._load (module.js:386:25)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (tags.js:1:1)
at Module._compile (module.js:541:32)
...
Which is understandable. The proxyquire solution that @tomRedox posted above should address the importation of Meteor packages.
Hi, @ffxsam How did you manage to solve the issue? I’m having the exact same problem. Can’t get the test to work.
Error: Cannot find module 'meteor/mongo’
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object. (posts.js:1:1)
at Module._compile (module.js:541:32)
I tried the solutions mentioned above but still can’t get it to work.
In my case, What happened was I had a schema defined together with the collection on one file. So when I imported the schema it also includes import {Mongo} from 'meteor/mongo';. So what I did was just separate the collection and the schema into two files and that fixed my problem.