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
17 changes: 15 additions & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var commonPathPrefix = require('common-path-prefix');
var resolveCwd = require('resolve-cwd');
var uniqueTempDir = require('unique-temp-dir');
var findCacheDir = require('find-cache-dir');
var slash = require('slash');
var AvaError = require('./lib/ava-error');
var fork = require('./lib/fork');
var formatter = require('./lib/enhance-assert').formatter();
Expand Down Expand Up @@ -64,6 +65,7 @@ Api.prototype._runFile = function (file) {
});

return fork(file, options)
.on('teardown', this._handleTeardown)
.on('stats', this._handleStats)
.on('test', this._handleTest)
.on('unhandledRejections', this._handleRejections)
Expand Down Expand Up @@ -96,6 +98,10 @@ Api.prototype._handleExceptions = function (data) {
this.errors.push(err);
};

Api.prototype._handleTeardown = function (data) {
this.emit('dependencies', data.file, data.dependencies);
};

Api.prototype._handleStats = function (stats) {
this.testCount += stats.testCount;
};
Expand Down Expand Up @@ -242,10 +248,17 @@ function handlePaths(files, excludePatterns) {
return files
.map(function (file) {
if (fs.statSync(file).isDirectory()) {
return handlePaths([path.join(file, '**', '*.js')], excludePatterns);
var pattern = path.join(file, '**', '*.js');
if (process.platform === 'win32') {
// Always use / in patterns, harmonizing matching across platforms.
pattern = slash(pattern);
}
return handlePaths([pattern], excludePatterns);
}

return file;
// globby returns slashes even on Windows. Normalize here so the file
// paths are consistently platform-accurate as tests are run.
return path.normalize(file);
})
.then(flatten)
.filter(function (file) {
Expand Down
5 changes: 3 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var verboseReporter = require('./lib/reporters/verbose');
var miniReporter = require('./lib/reporters/mini');
var tapReporter = require('./lib/reporters/tap');
var Logger = require('./lib/logger');
var watcher = require('./lib/watcher');
var Watcher = require('./lib/watcher');
var Api = require('./api');

// Bluebird specific
Expand Down Expand Up @@ -133,7 +133,8 @@ if (files.length === 0) {

if (cli.flags.watch) {
try {
watcher.start(logger, api, files, arrify(cli.flags.source), process.stdin);
var watcher = new Watcher(logger, api, files, arrify(cli.flags.source));
watcher.observeStdin(process.stdin);
} catch (err) {
if (err.name === 'AvaError') {
// An AvaError may be thrown if chokidar is not installed. Log it nicely.
Expand Down
26 changes: 24 additions & 2 deletions lib/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ module.constructor._nodeModulePaths = function () {
return ret;
};

var dependencies = [];
Object.keys(require.extensions).forEach(function (ext) {
var wrappedHandler = require.extensions[ext];
require.extensions[ext] = function (module, filename) {
if (filename !== testPath) {
dependencies.push(filename);
}
wrappedHandler(module, filename);
};
});

require(testPath);

process.on('uncaughtException', function (exception) {
Expand Down Expand Up @@ -122,11 +133,19 @@ process.on('ava-exit', function () {
}, delay);
});

var tearingDown = false;
process.on('ava-teardown', function () {
// ava-teardown can be sent more than once.
if (tearingDown) {
return;
}
tearingDown = true;

var rejections = loudRejection.currentlyUnhandled();

if (rejections.length === 0) {
return exit();
exit();
return;
}

rejections = rejections.map(function (rejection) {
Expand All @@ -142,5 +161,8 @@ process.on('ava-teardown', function () {
});

function exit() {
send('teardown');
// Include dependencies in the final teardown message. This ensures the full
// set of dependencies is included no matter how the process exits, unless
// it flat out crashes.
send('teardown', {dependencies: dependencies});
}
Loading