Skip to content

Commit

Permalink
Exit with error if --watch is used in CI (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
forresst authored and Vadim Demedes committed Jan 23, 2017
1 parent 83937bf commit 0606ff7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/recipes/watch-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Dependency tracking works for required modules. Custom extensions and transpiler

The [`.only` modifier] disables watch mode's dependency tracking algorithm. When a change is made, all `.only` tests will be rerun, regardless of whether the test depends on the changed file.

## Watch mode and CI

If you run AVA in your CI with watch mode, the execution will exit with a error. AVA will not run with the `--watch` (`-w`) option in CI, because CI processes should terminate, and with the `--watch` option, AVA will never terminate.

## Manually rerunning all tests

You can quickly rerun all tests by typing <kbd>r</kbd> on the console, followed by <kbd>Enter</kbd>.
Expand Down
4 changes: 4 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ exports.run = () => {
throw new Error(colors.error(figures.cross) + ' The TAP reporter is not available when using watch mode.');
}

if ((hasFlag('--watch') || hasFlag('-w')) && isCi) {
throw new Error(colors.error(figures.cross) + ' AVA will not run with the --watch (-w) option in CI, because CI processes should terminate, and with the --watch option, AVA will never terminate.');
}

if (hasFlag('--require') || hasFlag('-r')) {
throw new Error(colors.error(figures.cross) + ' The --require and -r flags are deprecated. Requirements should be configured in package.json - see documentation.');
}
Expand Down
10 changes: 10 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ test('bails when config contains `"tap": true` and `"watch": true`', t => {
});
});

['--watch', '-w'].forEach(watchFlag => {
test(`bails when CI is used while ${watchFlag} is given`, t => {
execCli([watchFlag, 'test.js'], {dirname: 'fixture/watcher', env: {CI: true}}, (err, stdout, stderr) => {
t.is(err.code, 1);
t.match(stderr, 'AVA will not run with the --watch (-w) option in CI, because CI processes should terminate, and with the --watch option, AVA will never terminate.');
t.end();
});
});
});

test('--match works', t => {
execCli(['-m=foo', '-m=bar', '-m=!baz', '-m=t* a* f*', '-m=!t* a* n* f*', 'fixture/matcher-skip.js'], err => {
t.ifError(err);
Expand Down

0 comments on commit 0606ff7

Please sign in to comment.