diff options
Diffstat (limited to 'node_modules/ava/lib/test-collection.js')
-rw-r--r-- | node_modules/ava/lib/test-collection.js | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/node_modules/ava/lib/test-collection.js b/node_modules/ava/lib/test-collection.js index 91c604e06..fd34bc489 100644 --- a/node_modules/ava/lib/test-collection.js +++ b/node_modules/ava/lib/test-collection.js @@ -33,6 +33,7 @@ class TestCollection extends EventEmitter { this._emitTestResult = this._emitTestResult.bind(this); } + add(test) { const metadata = test.metadata; const type = metadata.type; @@ -91,6 +92,7 @@ class TestCollection extends EventEmitter { this.tests.concurrent.push(test); } } + _skippedTest(test) { return { run: () => { @@ -103,10 +105,12 @@ class TestCollection extends EventEmitter { } }; } + _emitTestResult(result) { this.pendingTestInstances.delete(result.result); this.emit('test', result); } + _buildHooks(hooks, testTitle, context) { return hooks.map(hook => { const test = this._buildHook(hook, testTitle, context); @@ -118,6 +122,7 @@ class TestCollection extends EventEmitter { return test; }); } + _buildHook(hook, testTitle, contextRef) { let title = hook.title; @@ -141,6 +146,7 @@ class TestCollection extends EventEmitter { this.pendingTestInstances.add(test); return test; } + _buildTest(test, contextRef) { if (!contextRef) { contextRef = null; @@ -158,6 +164,7 @@ class TestCollection extends EventEmitter { this.pendingTestInstances.add(test); return test; } + _buildTestWithHooks(test) { if (test.metadata.skipped || test.metadata.todo) { return new Sequence([this._skippedTest(this._buildTest(test))], true); @@ -175,24 +182,41 @@ class TestCollection extends EventEmitter { } return sequence; } + _buildTests(tests) { return tests.map(test => this._buildTestWithHooks(test)); } - build() { - const beforeHooks = new Sequence(this._buildHooks(this.hooks.before)); - const afterHooks = new Sequence(this._buildHooks(this.hooks.after)); + _hasUnskippedTests() { + return this.tests.serial.concat(this.tests.concurrent) + .some(test => { + return !(test.metadata && test.metadata.skipped === true); + }); + } + + build() { const serialTests = new Sequence(this._buildTests(this.tests.serial), this.bail); const concurrentTests = new Concurrent(this._buildTests(this.tests.concurrent), this.bail); const allTests = new Sequence([serialTests, concurrentTests]); - let finalTests = new Sequence([beforeHooks, allTests, afterHooks], true); + let finalTests; + // Only run before and after hooks when there are unskipped tests + if (this._hasUnskippedTests()) { + const beforeHooks = new Sequence(this._buildHooks(this.hooks.before)); + const afterHooks = new Sequence(this._buildHooks(this.hooks.after)); + finalTests = new Sequence([beforeHooks, allTests, afterHooks], true); + } else { + finalTests = new Sequence([allTests], true); + } + if (this.hooks.afterAlways.length > 0) { const afterAlwaysHooks = new Sequence(this._buildHooks(this.hooks.afterAlways)); finalTests = new Sequence([finalTests, afterAlwaysHooks], false); } + return finalTests; } + attributeLeakedError(err) { for (const test of this.pendingTestInstances) { if (test.attributeLeakedError(err)) { |