Skip to content

Commit

Permalink
Fix "Test files must be run with the AVA CLI" warning. (#862)
Browse files Browse the repository at this point in the history
We used to have a nice warning, telling people to use the CLI if they ran `node path/to/testfile.js`. It was broken by requiring `test-worker` to early. `test-worker` tries `JSON.parse(process.argv[2])`, which will likely throw. Preventing the helpful message.

This adds a fix, and a regression test.
  • Loading branch information
jamestalmage committed May 24, 2016
1 parent e01ee00 commit 0ef6dc4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ var globals = require('./lib/globals');
var Runner = require('./lib/runner');
var send = require('./lib/send');

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

var opts = globals.options;
var runner = new Runner({
serial: opts.serial,
Expand All @@ -28,6 +25,9 @@ if (!isForked) {
process.exit(1); // eslint-disable-line
}

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

// if fail-fast is enabled, use this variable to detect
// that no more tests should be logged
var isFailed = false;
Expand Down
8 changes: 8 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,11 @@ test('works when no files are found', function (t) {
t.end();
});
});

test('should warn ava is required without the cli', function (t) {
childProcess.execFile(process.execPath, [path.resolve(__dirname, '../index.js')], function (error) {
t.ok(error);
t.match(error.message, /Test files must be run with the AVA CLI/);
t.end();
});
});

0 comments on commit 0ef6dc4

Please sign in to comment.