diff --git a/docs/recipes/watch-mode.md b/docs/recipes/watch-mode.md index 2f3badce8..2c4a29c5e 100644 --- a/docs/recipes/watch-mode.md +++ b/docs/recipes/watch-mode.md @@ -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 r on the console, followed by Enter. diff --git a/lib/cli.js b/lib/cli.js index dd32a0eee..8e9fb53b3 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -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.'); } diff --git a/test/cli.js b/test/cli.js index a9f9a174a..5b180ca20 100644 --- a/test/cli.js +++ b/test/cli.js @@ -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);