From 23723a76e15730735ad5a6951c8e8752b623cbca Mon Sep 17 00:00:00 2001 From: Andrew Safigan Date: Tue, 12 Jul 2016 17:53:13 -0400 Subject: [PATCH 1/6] added failing test for expected error --- test/runner.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/runner.js b/test/runner.js index 37df7938e..3095cc199 100644 --- a/test/runner.js +++ b/test/runner.js @@ -13,6 +13,22 @@ 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: 'Cannot have nested tests or hooks'}); + }); + + runner.run({}).then(function () { + t.end(); + }); +}); + test('runner emits a "test" event', function (t) { var runner = new Runner(); From 780051a0882790979c9d70eab6a05bbf87f7de24 Mon Sep 17 00:00:00 2001 From: Andrew Safigan Date: Tue, 12 Jul 2016 18:04:19 -0400 Subject: [PATCH 2/6] tests passed: waiting for review --- lib/runner.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/runner.js b/lib/runner.js index 250159372..2e5956d7b 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -46,6 +46,7 @@ function Runner(options) { this.results = []; this.tests = new TestCollection(); + this.hasBegunRunning = false; this._bail = options.bail; this._serial = options.serial; this._match = options.match || []; @@ -61,6 +62,10 @@ optionChain(chainableMethods, function (opts, args) { var fn; var macroArgIndex; + if (this.hasBegunRunning) { + throw new Error('Cannot have nested tests or hooks'); + } + if (typeof args[0] === 'string') { title = args[0]; fn = args[1]; @@ -196,5 +201,7 @@ Runner.prototype.run = function (options) { this.tests.on('test', this._addTestResult); + this.hasBegunRunning = true; + return Promise.resolve(this.tests.build(this._bail).run()).then(this._buildStats); }; From 6f77043dc794ccdb8b8d17023febfed3a819bd53 Mon Sep 17 00:00:00 2001 From: Andrew Safigan Date: Wed, 13 Jul 2016 14:33:35 -0400 Subject: [PATCH 3/6] added test --- test/runner.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/runner.js b/test/runner.js index 3095cc199..d14261045 100644 --- a/test/runner.js +++ b/test/runner.js @@ -21,7 +21,8 @@ test('nested tests and hooks aren\'t allowed', function (t) { runner.test(function () { t.throws(function () { runner.test(noop); - }, {message: 'Cannot have nested tests or hooks'}); + }, {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 () { @@ -29,6 +30,21 @@ test('nested tests and hooks aren\'t allowed', function (t) { }); }); +test('tests must be declared synchronously', function (t) { + 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.'}); +}); + test('runner emits a "test" event', function (t) { var runner = new Runner(); From ed980df1e7149732e1bab792572246d326dd4846 Mon Sep 17 00:00:00 2001 From: Andrew Safigan Date: Wed, 13 Jul 2016 14:40:39 -0400 Subject: [PATCH 4/6] changed error message --- lib/runner.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/runner.js b/lib/runner.js index 2e5956d7b..bd72bdb83 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -63,7 +63,8 @@ optionChain(chainableMethods, function (opts, args) { var macroArgIndex; if (this.hasBegunRunning) { - throw new Error('Cannot have nested tests or hooks'); + 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') { From bda70a44ef52fa6c80086bfc49927c34c8bec5fc Mon Sep 17 00:00:00 2001 From: Andrew Safigan Date: Wed, 13 Jul 2016 14:52:21 -0400 Subject: [PATCH 5/6] fixed error in test --- test/runner.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/runner.js b/test/runner.js index d14261045..ef52674e6 100644 --- a/test/runner.js +++ b/test/runner.js @@ -31,18 +31,22 @@ test('nested tests and hooks aren\'t allowed', function (t) { }); test('tests must be declared synchronously', function (t) { + t.plan(1); + var runner = new Runner(); runner.test(function () { return Promise.resolve(); }); - runner.run(); + 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) { From 735ad0939983bfff55bc6fbcf50108a57c2097cd Mon Sep 17 00:00:00 2001 From: Andrew Safigan Date: Wed, 13 Jul 2016 20:58:24 -0400 Subject: [PATCH 6/6] changed 'hasBegunRunning' to 'hasStarted' --- lib/runner.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/runner.js b/lib/runner.js index bd72bdb83..2bc30ef54 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -46,7 +46,7 @@ function Runner(options) { this.results = []; this.tests = new TestCollection(); - this.hasBegunRunning = false; + this.hasStarted = false; this._bail = options.bail; this._serial = options.serial; this._match = options.match || []; @@ -62,7 +62,7 @@ optionChain(chainableMethods, function (opts, args) { var fn; var macroArgIndex; - if (this.hasBegunRunning) { + 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.'); } @@ -202,7 +202,7 @@ Runner.prototype.run = function (options) { this.tests.on('test', this._addTestResult); - this.hasBegunRunning = true; + this.hasStarted = true; return Promise.resolve(this.tests.build(this._bail).run()).then(this._buildStats); };