|
@ -3,8 +3,9 @@ module.exports = TestCollection; |
|
|
|
|
|
|
|
|
function TestCollection() { |
|
|
function TestCollection() { |
|
|
if (!(this instanceof TestCollection)) { |
|
|
if (!(this instanceof TestCollection)) { |
|
|
throw new Error('must use `new TestCollection()`'); |
|
|
throw new TypeError('Class constructor TestCollection cannot be invoked without \'new\''); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.serial = []; |
|
|
this.serial = []; |
|
|
this.concurrent = []; |
|
|
this.concurrent = []; |
|
|
this.tests = { |
|
|
this.tests = { |
|
@ -19,24 +20,31 @@ function TestCollection() { |
|
|
TestCollection.prototype.add = function (test) { |
|
|
TestCollection.prototype.add = function (test) { |
|
|
var metadata = test.metadata; |
|
|
var metadata = test.metadata; |
|
|
var type = metadata.type; |
|
|
var type = metadata.type; |
|
|
|
|
|
|
|
|
if (!type) { |
|
|
if (!type) { |
|
|
throw new Error('test type must be specified'); |
|
|
throw new Error('test type must be specified'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (type === 'test') { |
|
|
if (type === 'test') { |
|
|
if (this.hasExclusive && !metadata.exclusive) { |
|
|
if (this.hasExclusive && !metadata.exclusive) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (metadata.exclusive && !this.hasExclusive) { |
|
|
if (metadata.exclusive && !this.hasExclusive) { |
|
|
this.hasExclusive = true; |
|
|
this.hasExclusive = true; |
|
|
this.serial = []; |
|
|
this.serial = []; |
|
|
this.concurrent = []; |
|
|
this.concurrent = []; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
(metadata.serial ? this.serial : this.concurrent).push(test); |
|
|
(metadata.serial ? this.serial : this.concurrent).push(test); |
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (metadata.exclusive) { |
|
|
if (metadata.exclusive) { |
|
|
throw new Error('you can\'t use "only" with a ' + type + ' test'); |
|
|
throw new Error('you can\'t use "only" with a ' + type + ' test'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.tests[type].push(test); |
|
|
this.tests[type].push(test); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -65,9 +73,11 @@ function computeTitle(entry) { |
|
|
function buildHooks(hookArray, title, contextRef, report) { |
|
|
function buildHooks(hookArray, title, contextRef, report) { |
|
|
return hookArray.map(function (hook) { |
|
|
return hookArray.map(function (hook) { |
|
|
var test = buildHook(hook, title, contextRef, report); |
|
|
var test = buildHook(hook, title, contextRef, report); |
|
|
|
|
|
|
|
|
if (hook.metadata.skipped) { |
|
|
if (hook.metadata.skipped) { |
|
|
return skipRunner(test, report); |
|
|
return skipRunner(test, report); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return test; |
|
|
return test; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
@ -103,9 +113,11 @@ function buildTestWithHooks(entry, beforeEach, afterEach, report) { |
|
|
if (entry.metadata.skipped) { |
|
|
if (entry.metadata.skipped) { |
|
|
return [skipRunner(buildTest(entry), report)]; |
|
|
return [skipRunner(buildTest(entry), report)]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var contextRef = {context: {}}; |
|
|
var contextRef = {context: {}}; |
|
|
var arr = buildHooks(beforeEach, entry.title, contextRef, report); |
|
|
var arr = buildHooks(beforeEach, entry.title, contextRef, report); |
|
|
arr.push(buildTest(entry, contextRef, report)); |
|
|
arr.push(buildTest(entry, contextRef, report)); |
|
|
|
|
|
|
|
|
return arr.concat(buildHooks(afterEach, entry.title, contextRef, report)); |
|
|
return arr.concat(buildHooks(afterEach, entry.title, contextRef, report)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -127,6 +139,7 @@ TestCollection.prototype.buildPhases = function (report) { |
|
|
if (entry.metadata.skipped) { |
|
|
if (entry.metadata.skipped) { |
|
|
return skipRunner(entry, report); |
|
|
return skipRunner(entry, report); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return buildTest(entry, null, report); |
|
|
return buildTest(entry, null, report); |
|
|
})), |
|
|
})), |
|
|
new Sequence([ |
|
|
new Sequence([ |
|
@ -141,6 +154,7 @@ TestCollection.prototype.buildPhases = function (report) { |
|
|
if (entry.metadata.skipped) { |
|
|
if (entry.metadata.skipped) { |
|
|
return skipRunner(entry, report); |
|
|
return skipRunner(entry, report); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return buildTest(entry, null, report); |
|
|
return buildTest(entry, null, report); |
|
|
})) |
|
|
})) |
|
|
], |
|
|
], |
|
|