I’m building a project with Meteor, MongoDB, and React, and I’ve added meteortesting:mocha to handle my tests. The .test.js files inside imports/ui/… are detected and executed correctly. However, the tests inside my custom Meteor package are not being recognized or run.
Given that practicalmeteor:mocha is deprecated and Meteor’s official documentation hasn’t been updated for current tools, what’s the recommended way to structure and execute meteor testing for packages? Do I need to configure something specific to get package tests to run properly with meteortesting:mocha?
Hey @anusha_gg
I had the same issue and realized that meteortesting:mocha
only picks up test files explicitly loaded in a test runner app.
For package testing, what worked for me was creating a dedicated test app (inside /tests/ or a sibling directory
), and adding the local package via package.js or meteor add ../your-package
.
Then, in that test app’s main.js, I explicitly imported the test files from the package like:
import '../packages/your-package/tests/package.test.js';
This way, meteortesting:mocha
executes them as part of the test app run. It’s a bit of a manual step, but it’s reliable.
Hope you got it , if any issues feel free to shoot your doubts.
Well , well In my case, the tests inside the package directory weren’t running because they weren’t included in the app context.
I ended up restructuring the package slightly: I added a tests/ folder inside the package with test files like your-package.tests.js, and then used api.mainModule('tests/your-package.tests.js', 'client');
in package.js.
Then from a test app, I just included the package normally and let Mocha run the tests automatically. You do need to set up meteortesting:mocha
in the test app itself, not the package.
This kept the package self-contained while allowing me to test it.
I took a simpler route by symlinking
the test files from my package into the /imports/tests/
directory of my main Meteor app.
That way, they were picked up like any other unit test without needing to modify package.js.
Not super elegant, but it let me avoid creating a separate test harness or modifying build logic.
For local development, this hack worked just fine, and I added a small script to sync the links for CI.