Skip to content

Commit e57908a

Browse files
novemberbornsindresorhus
authored andcommitted
watch mode always runs all exclusive tests
Fixes #635.
1 parent 08ce255 commit e57908a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

docs/recipes/watch-mode.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ AVA tracks which source files your test files depend on. If you change such a de
6969

7070
Dependency tracking works for required modules. Custom extensions and transpilers are supported, provided you loaded them using the [`--require` CLI flag] and not from inside your test file. Files accessed using the `fs` module are not tracked.
7171

72+
## Watch mode and the `.only` modifier
73+
74+
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.
75+
7276
## Manually rerunning all tests
7377

7478
You can quickly rerun all tests by typing <kbd>r</kbd> on the console, followed by <kbd>Enter</kbd>.
@@ -96,3 +100,4 @@ Watch mode is relatively new and there might be some rough edges. Please [report
96100
[`ignore-by-default`]: https://github.com/novemberborn/ignore-by-default
97101
[`--require` CLI flag]: https://github.com/sindresorhus/ava#cli
98102
[`--source` CLI flag]: https://github.com/sindresorhus/ava#cli
103+
[`.only` modifier]: https://github.com/sindresorhus/ava#running-specific-tests

lib/watcher.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ function Watcher(logger, api, files, sources) {
4747
}, this);
4848

4949
runOnlyExclusive = exclusiveFiles.length !== this.filesWithExclusiveTests.length;
50+
51+
if (runOnlyExclusive) {
52+
// The test files that previously contained exclusive tests are always
53+
// run, together with the remaining specific files.
54+
var remainingFiles = diff(specificFiles, exclusiveFiles);
55+
specificFiles = this.filesWithExclusiveTests.concat(remainingFiles);
56+
}
5057
}
5158

5259
this.busy = api.run(specificFiles || files, {

test/watcher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ group('chokidar is installed', function (beforeEach, test, group) {
938938
change(t4);
939939
return debounce(2).then(function () {
940940
t.ok(api.run.calledTwice);
941-
t.same(api.run.secondCall.args, [[t3, t4], {runOnlyExclusive: true}]);
941+
t.same(api.run.secondCall.args, [[t1, t2, t3, t4], {runOnlyExclusive: true}]);
942942
});
943943
});
944944

@@ -950,7 +950,7 @@ group('chokidar is installed', function (beforeEach, test, group) {
950950
change(t4);
951951
return debounce(2).then(function () {
952952
t.ok(api.run.calledTwice);
953-
t.same(api.run.secondCall.args, [[t1, t4], {runOnlyExclusive: true}]);
953+
t.same(api.run.secondCall.args, [[t1, t2, t4], {runOnlyExclusive: true}]);
954954
});
955955
});
956956

0 commit comments

Comments
 (0)