Skip to content

Commit 0e69c4d

Browse files
committed
test
1 parent 31caef8 commit 0e69c4d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/sequential/test-watch-mode.mjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,4 +884,51 @@ process.on('message', (message) => {
884884
await done();
885885
}
886886
});
887+
888+
it('should watch changes even when there is syntax errors during esm loading', async () => {
889+
// Create initial file with valid code
890+
const initialContent = `console.log('hello, world');`;
891+
const file = createTmpFile(initialContent, '.mjs');
892+
893+
const { done, restart } = runInBackground({
894+
args: ['--watch', file],
895+
completed: 'Completed running',
896+
shouldFail: true,
897+
});
898+
899+
try {
900+
const { stdout, stderr } = await restart();
901+
assert.strictEqual(stderr, '');
902+
assert.deepStrictEqual(stdout, [
903+
'hello, world',
904+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
905+
])
906+
907+
// Update file with syntax error
908+
const syntaxErrorContent = `console.log('hello, wor`;
909+
writeFileSync(file, syntaxErrorContent);
910+
911+
// Wait for the failed restart
912+
const { stderr: stderr2, stdout: stdout2 } = await restart();
913+
assert.match(stderr2, /SyntaxError: Invalid or unexpected token/);
914+
assert.deepStrictEqual(stdout2, [
915+
`Restarting ${inspect(file)}`,
916+
`Failed running ${inspect(file)}. Waiting for file changes before restarting...`,
917+
])
918+
919+
writeFileSync(file, `console.log('hello again, world');`);
920+
921+
const { stderr: stderr3, stdout: stdout3 } = await restart();
922+
923+
// Verify it recovered and ran successfully
924+
assert.strictEqual(stderr3, '');
925+
assert.deepStrictEqual(stdout3, [
926+
`Restarting ${inspect(file)}`,
927+
'hello again, world',
928+
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
929+
]);
930+
} finally {
931+
await done();
932+
}
933+
});
887934
});

0 commit comments

Comments
 (0)