Skip to content

Commit 0c8e112

Browse files
committed
test_runner: add new test file scenario into test-runner-watch
1 parent 5887f33 commit 0c8e112

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

test/parallel/test-runner-run-watch.mjs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function refresh() {
3838

3939
const runner = join(import.meta.dirname, '..', 'fixtures', 'test-runner-watch.mjs');
4040

41-
async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.path }) {
41+
async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.path, fileToCreate }) {
4242
const ran1 = util.createDeferredPromise();
4343
const ran2 = util.createDeferredPromise();
4444
const args = [runner];
@@ -123,10 +123,35 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
123123
}
124124
};
125125

126+
const testCreate = async () => {
127+
await ran1.promise;
128+
const newFilePath = tmpdir.resolve(fileToCreate);
129+
const interval = setInterval(
130+
() => writeFileSync(
131+
newFilePath,
132+
'module.exports = {};'
133+
),
134+
common.platformTimeout(1000)
135+
);
136+
await ran2.promise;
137+
runs.push(currentRun);
138+
clearInterval(interval);
139+
child.kill();
140+
await once(child, 'exit');
141+
142+
for (const run of runs) {
143+
assert.match(run, /# tests 1/);
144+
assert.match(run, /# pass 1/);
145+
assert.match(run, /# fail 0/);
146+
assert.match(run, /# cancelled 0/);
147+
}
148+
};
149+
126150
action === 'update' && await testUpdate();
127151
action === 'rename' && await testRename();
128152
action === 'rename2' && await testRename();
129153
action === 'delete' && await testDelete();
154+
action === 'create' && await testCreate();
130155
}
131156

132157
describe('test runner watch mode', () => {
@@ -172,4 +197,8 @@ describe('test runner watch mode', () => {
172197
action: 'rename2'
173198
});
174199
});
200+
201+
it('should run new tests when a new file is created in the watched directory', async () => {
202+
await testWatch({ action: 'create', fileToCreate: 'new-test-file.test.js' });
203+
});
175204
});

0 commit comments

Comments
 (0)