|
@ -28,6 +28,7 @@ function Api(options) { |
|
|
|
|
|
|
|
|
this.options = options || {}; |
|
|
this.options = options || {}; |
|
|
this.options.require = (this.options.require || []).map(resolveCwd); |
|
|
this.options.require = (this.options.require || []).map(resolveCwd); |
|
|
|
|
|
this.options.match = this.options.match || []; |
|
|
|
|
|
|
|
|
this.excludePatterns = [ |
|
|
this.excludePatterns = [ |
|
|
'!**/node_modules/**', |
|
|
'!**/node_modules/**', |
|
@ -194,35 +195,57 @@ Api.prototype.run = function (files) { |
|
|
var tests = files.map(self._runFile); |
|
|
var tests = files.map(self._runFile); |
|
|
|
|
|
|
|
|
// receive test count from all files and then run the tests
|
|
|
// receive test count from all files and then run the tests
|
|
|
var statsCount = 0; |
|
|
var unreportedFiles = self.fileCount; |
|
|
|
|
|
|
|
|
return new Promise(function (resolve) { |
|
|
return new Promise(function (resolve) { |
|
|
tests.forEach(function (test) { |
|
|
function run() { |
|
|
function tryRun() { |
|
|
if (self.options.match.length > 0 && !self.hasExclusive) { |
|
|
if (++statsCount === self.fileCount) { |
|
|
self._handleExceptions({ |
|
|
self.emit('ready'); |
|
|
exception: new AvaError('Couldn\'t find any matching tests'), |
|
|
|
|
|
file: undefined |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
tests.forEach(function (test) { |
|
|
|
|
|
// No tests will be run so tear down the child processes.
|
|
|
|
|
|
test.send('teardown'); |
|
|
|
|
|
}); |
|
|
|
|
|
resolve([]); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var method = self.options.serial ? 'mapSeries' : 'map'; |
|
|
self.emit('ready'); |
|
|
var options = { |
|
|
|
|
|
runOnlyExclusive: self.hasExclusive |
|
|
var method = self.options.serial ? 'mapSeries' : 'map'; |
|
|
|
|
|
var options = { |
|
|
|
|
|
runOnlyExclusive: self.hasExclusive |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
resolve(Promise[method](files, function (file, index) { |
|
|
|
|
|
return tests[index].run(options).catch(function (err) { |
|
|
|
|
|
// The test failed catastrophically. Flag it up as an
|
|
|
|
|
|
// exception, then return an empty result. Other tests may
|
|
|
|
|
|
// continue to run.
|
|
|
|
|
|
self._handleExceptions({ |
|
|
|
|
|
exception: err, |
|
|
|
|
|
file: file |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
stats: {passCount: 0, skipCount: 0, todoCount: 0, failCount: 0}, |
|
|
|
|
|
tests: [] |
|
|
}; |
|
|
}; |
|
|
|
|
|
}); |
|
|
|
|
|
})); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
resolve(Promise[method](files, function (file, index) { |
|
|
tests.forEach(function (test) { |
|
|
return tests[index].run(options).catch(function (err) { |
|
|
var tried = false; |
|
|
// The test failed catastrophically. Flag it up as an
|
|
|
function tryRun() { |
|
|
// exception, then return an empty result. Other tests may
|
|
|
if (!tried) { |
|
|
// continue to run.
|
|
|
unreportedFiles--; |
|
|
self._handleExceptions({ |
|
|
if (unreportedFiles === 0) { |
|
|
exception: err, |
|
|
run(); |
|
|
file: file |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
stats: {passCount: 0, skipCount: 0, todoCount: 0, failCount: 0}, |
|
|
|
|
|
tests: [] |
|
|
|
|
|
}; |
|
|
|
|
|
}); |
|
|
|
|
|
})); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|