Skip to content

Commit 015ccd7

Browse files
test_runner: test ordering events emission when watching
1 parent db93037 commit 015ccd7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ describe('test runner watch mode', () => {
258258
});
259259

260260
it('should emits test:watch:restarted when file is updated', async () => {
261+
let alreadyDrained = false;
262+
const events = [];
261263
const testWatchRestarted = common.mustCall(1);
262264

263265
const controller = new AbortController();
@@ -266,9 +268,15 @@ describe('test runner watch mode', () => {
266268
watch: true,
267269
signal: controller.signal,
268270
}).on('data', function({ type }) {
271+
events.push(type);
269272
if (type === 'test:watch:restarted') {
270273
testWatchRestarted();
271-
controller.abort();
274+
}
275+
if (type === 'test:watch:drained') {
276+
if (alreadyDrained) {
277+
controller.abort();
278+
}
279+
alreadyDrained = true;
272280
}
273281
});
274282

@@ -278,6 +286,12 @@ describe('test runner watch mode', () => {
278286

279287
// eslint-disable-next-line no-unused-vars
280288
for await (const _ of stream);
289+
290+
assert.partialDeepStrictEqual(events, [
291+
'test:watch:drained',
292+
'test:watch:restarted',
293+
'test:watch:drained',
294+
]);
281295
});
282296

283297
it('should not emit test:watch:restarted since watch mode is disabled', async () => {

0 commit comments

Comments
 (0)