Skip to content

Commit 7647250

Browse files
StefanStojanovictargos
authored andcommitted
test: fix test-watch-mode
Refs: #44898 PR-URL: #45585 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Erick Wendel <erick.workspace@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent cd36250 commit 7647250

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

test/sequential/test-watch-mode.mjs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ if (common.isIBMi)
1515
common.skip('IBMi does not support `fs.watch()`');
1616

1717
const supportsRecursive = common.isOSX || common.isWindows;
18+
let disableRestart = false;
1819

1920
function restart(file) {
2021
// To avoid flakiness, we save the file repeatedly until test is done
2122
writeFileSync(file, readFileSync(file));
22-
const timer = setInterval(() => writeFileSync(file, readFileSync(file)), 1000);
23+
const timer = setInterval(() => {
24+
if (!disableRestart) {
25+
writeFileSync(file, readFileSync(file));
26+
}
27+
}, common.platformTimeout(1000));
2328
return () => clearInterval(timer);
2429
}
2530

@@ -38,11 +43,15 @@ async function spawnWithRestarts({
3843
let stdout = '';
3944
let cancelRestarts;
4045

46+
disableRestart = true;
4147
const child = spawn(execPath, ['--watch', '--no-warnings', ...args], { encoding: 'utf8' });
4248
child.stderr.on('data', (data) => {
4349
stderr += data;
4450
});
4551
child.stdout.on('data', async (data) => {
52+
if (data.toString().includes('Restarting')) {
53+
disableRestart = true;
54+
}
4655
stdout += data;
4756
const restartsCount = stdout.match(new RegExp(`Restarting ${printedArgs.replace(/\\/g, '\\\\')}`, 'g'))?.length ?? 0;
4857
if (restarts === 0 || !isReady(data.toString())) {
@@ -54,6 +63,9 @@ async function spawnWithRestarts({
5463
return;
5564
}
5665
cancelRestarts ??= restart(watchedFile);
66+
if (isReady(data.toString())) {
67+
disableRestart = false;
68+
}
5769
});
5870

5971
await once(child, 'exit');
@@ -97,9 +109,9 @@ async function failWriteSucceed({ file, watchedFile }) {
97109

98110
tmpdir.refresh();
99111

100-
// Warning: this suite can run safely with concurrency: true
101-
// only if tests do not watch/depend on the same files
102-
describe('watch mode', { concurrency: true, timeout: 60_000 }, () => {
112+
// Warning: this suite cannot run safely with concurrency: true
113+
// because of the disableRestart flag used for controlling restarts
114+
describe('watch mode', { concurrency: false, timeout: 60_000 }, () => {
103115
it('should watch changes to a file - event loop ended', async () => {
104116
const file = createTmpFile();
105117
const { stderr, stdout } = await spawnWithRestarts({ file });

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy