Skip to content
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions package/.versions
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
8 changes: 7 additions & 1 deletion package/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions tests/dummy_app/server/async-startup.tests.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
Loading