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
25 changes: 5 additions & 20 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var fs = require('fs');
var flatten = require('arr-flatten');
var Promise = require('bluebird');
var figures = require('figures');
var assign = require('object-assign');
var objectAssign = require('object-assign');
var globby = require('globby');
var chalk = require('chalk');
var fork = require('./lib/fork');
Expand All @@ -18,7 +18,8 @@ function Api(files, options) {

EventEmitter.call(this);

assign(this, options);
objectAssign(this, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't just remove this. The options are used directly on this in the code and needs to be changed to use this.options.x.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assign(this, options); has been replaced with objectAssign(this, options);

this.options = options;

this.rejectionCount = 0;
this.exceptionCount = 0;
Expand All @@ -40,23 +41,7 @@ util.inherits(Api, EventEmitter);
module.exports = Api;

Api.prototype._runFile = function (file) {
var args = [file];

if (this.failFast) {
args.push('--fail-fast');
}

if (this.serial) {
args.push('--serial');
}

// Forward the `time-require` `--sorted` flag.
// Intended for internal optimization tests only.
if (this._sorted) {
args.push('--sorted');
}

return fork(args)
return fork(file, this.options)
.on('stats', this._handleStats)
.on('test', this._handleTest)
.on('unhandledRejections', this._handleRejections)
Expand Down Expand Up @@ -162,7 +147,7 @@ Api.prototype.run = function () {
if (++statsCount === self.fileCount) {
self.emit('ready');

var method = self.serial ? 'mapSeries' : 'map';
var method = self.options.serial ? 'mapSeries' : 'map';

deferred.resolve(Promise[method](files, function (file, index) {
return tests[index].run();
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use strict';
var relative = require('path').relative;
var hasFlag = require('has-flag');
var chalk = require('chalk');
var serializeError = require('serialize-error');
var globals = require('./lib/globals');
var Runner = require('./lib/runner');
var send = require('./lib/send');
var log = require('./lib/logger');

var runner = new Runner();

// note that test files have require('ava')
require('./lib/babel').avaRequired = true;

var opts = JSON.parse(process.argv[2]);

var runner = new Runner(opts);

// check if the test is being run without AVA cli
var isForked = typeof process.send === 'function';

Expand Down Expand Up @@ -45,7 +46,7 @@ function test(props) {

send('test', props);

if (props.error && hasFlag('fail-fast')) {
if (props.error && opts.failFast) {
isFailed = true;
exit();
}
Expand Down
9 changes: 8 additions & 1 deletion lib/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

var debug = require('debug')('ava');

var opts = JSON.parse(process.argv[2]);

if (debug.enabled) {
// Forward the `time-require` `--sorted` flag.
// Intended for internal optimization tests only.
if (opts._sorted) {
process.argv.push('--sorted');
}
require('time-require');
}

Expand Down Expand Up @@ -31,7 +38,7 @@ var hasGenerator = require('has-generator');
var serializeError = require('serialize-error');
var send = require('./send');

var testPath = process.argv[2];
var testPath = opts.file;

// include local babel and fallback to ava's babel
var babel;
Expand Down
11 changes: 5 additions & 6 deletions lib/fork.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
'use strict';
var childProcess = require('child_process');
var path = require('path');
var objectAssign = require('object-assign');
var Promise = require('bluebird');
var debug = require('debug')('ava');
var send = require('./send');

module.exports = function (args) {
if (!Array.isArray(args)) {
args = [args];
}

module.exports = function (file, opts) {
var filepath = path.join(__dirname, 'babel.js');
var file = args[0];
opts = objectAssign({file: file}, opts);

var options = {
cwd: path.dirname(file),
stdio: ['ignore', process.stderr, process.stderr]
};

var args = [JSON.stringify(opts)];

var ps = childProcess.fork(filepath, args, options);

var promise = new Promise(function (resolve, reject) {
Expand Down
5 changes: 3 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var Promise = require('bluebird');
var hasFlag = require('has-flag');
var Test = require('./test');
var Hook = require('./hook');
var objectAssign = require('object-assign');
Expand All @@ -24,6 +23,8 @@ function Runner(opts) {

EventEmitter.call(this);

this.options = opts || {};

this.results = [];
this.tests = [];

Expand Down Expand Up @@ -130,7 +131,7 @@ Runner.prototype._runTest = function (test) {
};

Runner.prototype._runConcurrent = function (tests) {
if (hasFlag('serial')) {
if (this.options.serial) {
return this._runSerial(tests);
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"figures": "^1.4.0",
"fn-name": "^2.0.0",
"globby": "^4.0.0",
"has-flag": "^1.0.0",
"has-generator": "^1.0.0",
"is-generator-fn": "^1.0.0",
"is-observable": "^0.1.0",
Expand Down