Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function Runner(options) {

this.results = [];
this.tests = new TestCollection();
this.hasStarted = false;
this._bail = options.bail;
this._serial = options.serial;
this._match = options.match || [];
Expand All @@ -61,6 +62,11 @@ optionChain(chainableMethods, function (opts, args) {
var fn;
var macroArgIndex;

if (this.hasStarted) {
throw new Error('All tests and hooks must be declared synchronously in your ' +
'test file, and cannot be nested within other tests or hooks.');
}

if (typeof args[0] === 'string') {
title = args[0];
fn = args[1];
Expand Down Expand Up @@ -196,5 +202,7 @@ Runner.prototype.run = function (options) {

this.tests.on('test', this._addTestResult);

this.hasStarted = true;

return Promise.resolve(this.tests.build(this._bail).run()).then(this._buildStats);
};
36 changes: 36 additions & 0 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,42 @@ test('must be called with new', function (t) {
t.end();
});

test('nested tests and hooks aren\'t allowed', function (t) {
t.plan(1);

var runner = new Runner();

runner.test(function () {
t.throws(function () {
runner.test(noop);
}, {message: 'All tests and hooks must be declared synchronously in your ' +
'test file, and cannot be nested within other tests or hooks.'});
});

runner.run({}).then(function () {
t.end();
});
});

test('tests must be declared synchronously', function (t) {
t.plan(1);

var runner = new Runner();

runner.test(function () {
return Promise.resolve();
});

runner.run({});

t.throws(function () {
runner.test(noop);
}, {message: 'All tests and hooks must be declared synchronously in your ' +
'test file, and cannot be nested within other tests or hooks.'});

t.end();
});

test('runner emits a "test" event', function (t) {
var runner = new Runner();

Expand Down