Skip to content

Commit 17a18de

Browse files
authored
Ensure the watcher supports custom extensions
Fixes #1881.
1 parent c9361cb commit 17a18de

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

lib/cli.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ exports.run = () => { // eslint-disable-line complexity
188188
}
189189

190190
const match = arrify(conf.match);
191+
const resolveTestsFrom = cli.input.length === 0 ? projectDir : process.cwd();
191192
const api = new Api({
192193
failFast: conf.failFast,
193194
failWithoutAssertions: conf.failWithoutAssertions !== false,
@@ -198,7 +199,7 @@ exports.run = () => { // eslint-disable-line complexity
198199
extensions,
199200
match,
200201
babelConfig,
201-
resolveTestsFrom: cli.input.length === 0 ? projectDir : process.cwd(),
202+
resolveTestsFrom,
202203
projectDir,
203204
timeout: conf.timeout,
204205
concurrency: conf.concurrency ? parseInt(conf.concurrency, 10) : 0,
@@ -234,7 +235,14 @@ exports.run = () => { // eslint-disable-line complexity
234235
const files = cli.input.length > 0 ? cli.input : arrify(conf.files);
235236

236237
if (conf.watch) {
237-
const watcher = new Watcher(reporter, api, files, arrify(conf.sources));
238+
const watcher = new Watcher({
239+
api,
240+
reporter,
241+
extensions: extensions.all,
242+
files,
243+
sources: arrify(conf.sources),
244+
resolveTestsFrom
245+
});
238246
watcher.observeStdin(process.stdin);
239247
} else {
240248
api.run(files).then(runStatus => {

lib/watcher.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ class TestDependency {
7878
}
7979

8080
class Watcher {
81-
constructor(reporter, api, files, sources) {
81+
constructor({reporter, api, extensions, files, sources, resolveTestsFrom}) {
8282
this.debouncer = new Debouncer(this);
8383
this.avaFiles = new AvaFiles({
84+
cwd: resolveTestsFrom,
85+
extensions,
8486
files,
8587
sources
8688
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"ava": {
3+
"babel": {
4+
"extensions": [
5+
"foo"
6+
]
7+
}
8+
}
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../../../..';
2+
3+
test('works', t => {
4+
t.pass();
5+
});

test/integration/watcher.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ test('watcher reruns test files when they changed', t => {
3030
});
3131
});
3232

33+
test('watcher respects custom test file extensions', t => {
34+
let killed = false;
35+
36+
const child = execCli(['--verbose', '--watch'], {dirname: 'fixture/watcher/custom-extensions', env: {CI: ''}}, err => {
37+
t.ok(killed);
38+
t.ifError(err);
39+
t.end();
40+
});
41+
42+
let buffer = '';
43+
let passedFirst = false;
44+
child.stdout.on('data', str => {
45+
buffer += str;
46+
if (/1 test passed/.test(buffer)) {
47+
if (!passedFirst) {
48+
touch.sync(path.join(__dirname, '../fixture/watcher/custom-extensions/test.foo'));
49+
buffer = '';
50+
passedFirst = true;
51+
} else if (!killed) {
52+
child.kill();
53+
killed = true;
54+
}
55+
}
56+
});
57+
});
58+
3359
test('watcher reruns test files when source dependencies change', t => {
3460
let killed = false;
3561

test/watcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ group('chokidar', (beforeEach, test, group) => {
147147
Subject = proxyWatcher();
148148
});
149149

150-
const start = (specificFiles, sources) => new Subject(reporter, api, specificFiles || files, sources || []);
150+
const start = (specificFiles, sources) => new Subject({reporter, api, files: specificFiles || files, sources: sources || []});
151151

152152
const emitChokidar = (event, path) => {
153153
chokidarEmitter.emit('all', event, path);

0 commit comments

Comments
 (0)