diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fcd611..eed6d24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 3.4.0 + +- Await pending `Meteor.startup()` callbacks before running tests, so async startup work (e.g. ensuring MongoDB indices) finishes before `mocha.run()` fires on Meteor 3.x. [PR #177](https://github.com/Meteor-Community-Packages/meteor-mocha/pull/177) + ## 3.0.0 - Meteor 3.0 compatibility; drop Fibers diff --git a/package/.versions b/package/.versions index b456b30..0e35f0b 100644 --- a/package/.versions +++ b/package/.versions @@ -1,19 +1,19 @@ -babel-compiler@7.11.3 +babel-compiler@7.14.1 babel-runtime@1.5.2 core-runtime@1.0.0 dynamic-import@0.7.4 -ecmascript@0.16.10 +ecmascript@0.18.1 ecmascript-runtime@0.8.3 -ecmascript-runtime-client@0.12.3 +ecmascript-runtime-client@0.13.0 ecmascript-runtime-server@0.11.1 -fetch@0.1.6 +fetch@0.2.0 inter-process-messaging@0.1.2 -meteor@2.1.0 +meteor@2.3.1 meteortesting:browser-tests@1.8.0 -meteortesting:mocha@3.3.0 +meteortesting:mocha@3.4.0-rc.1 meteortesting:mocha-core@8.3.1-rc300.1 -modern-browsers@0.2.1 +modern-browsers@0.2.3 modules@0.20.3 modules-runtime@0.13.2 promise@1.0.0 -react-fast-refresh@0.2.9 +react-fast-refresh@0.3.0 diff --git a/package/package.js b/package/package.js index be24c34..57f1455 100644 --- a/package/package.js +++ b/package/package.js @@ -3,7 +3,7 @@ Package.describe({ summary: 'Run Meteor package or app tests with Mocha', git: 'https://github.com/meteortesting/meteor-mocha.git', documentation: '../README.md', - version: '3.3.0', + version: '3.4.0-rc.1', testOnly: true, }); diff --git a/package/server.js b/package/server.js index 8439af4..4b100c8 100644 --- a/package/server.js +++ b/package/server.js @@ -203,8 +203,14 @@ function clientTests() { }); } -// Before Meteor calls the `start` function, app tests will be parsed and loaded by Mocha +// Run tests from a new startup hook so every hook already queued, including +// async ones, completes first. Awaiting a callback added to the startup queue +// here would deadlock: this function itself is run by that queue. function start() { + Meteor.startup(runTests); +} + +function runTests() { const args = setArgs(); runnerOptions = args.runnerOptions; coverageOptions = args.coverageOptions; diff --git a/tests/dummy_app/server/async-startup.tests.js b/tests/dummy_app/server/async-startup.tests.js new file mode 100644 index 0000000..04fee7b --- /dev/null +++ b/tests/dummy_app/server/async-startup.tests.js @@ -0,0 +1,21 @@ +/* eslint-env mocha */ +import { Meteor } from 'meteor/meteor'; +import assert from 'assert'; + +// Simulate async startup work (e.g. ensuring MongoDB indices, initializing +// collections). Without the fix in server.js, mocha.run() can fire before +// this callback completes, causing the test below to fail. +let startupCompleted = false; + +Meteor.startup(async () => { + await new Promise(resolve => setTimeout(resolve, 50)); + startupCompleted = true; +}); + +describe('async Meteor.startup()', function () { + it('should complete before tests run', function () { + assert.strictEqual(startupCompleted, true, + 'Async Meteor.startup() callback did not complete before tests ran. ' + + 'See https://github.com/Meteor-Community-Packages/meteor-mocha/issues/176'); + }); +});