mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
watch: fix infinite loop when passing --watch=true flag
PR-URL: https://github.com/nodejs/node/pull/51160 Fixes: https://github.com/nodejs/node/issues/51159 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
1 parent
09519c6655
commit
07da4e9b58
2 files changed
+19
-3
No files matched your search
@@ -41,7 +41,7 @@ const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' '));
|
||||
const args = ArrayPrototypeFilter(process.execArgv, (arg, i, arr) =>
|
||||
!StringPrototypeStartsWith(arg, '--watch-path') &&
|
||||
(!arr[i - 1] || !StringPrototypeStartsWith(arr[i - 1], '--watch-path')) &&
|
||||
arg !== '--watch' && arg !== '--watch-preserve-output');
|
||||
arg !== '--watch' && !StringPrototypeStartsWith(arg, '--watch=') && arg !== '--watch-preserve-output');
|
||||
ArrayPrototypePushApply(args, kCommand);
|
||||
|
||||
const watcher = new FilesWatcher({ debounce: 200, mode: kShouldFilterModules ? 'filter' : 'all' });
|
||||
|
||||
@@ -30,9 +30,9 @@ function createTmpFile(content = 'console.log("running");', ext = '.js', basenam
|
||||
}
|
||||
|
||||
async function runWriteSucceed({
|
||||
file, watchedFile, args = [file], completed = 'Completed running', restarts = 2
|
||||
file, watchedFile, watchFlag = '--watch', args = [file], completed = 'Completed running', restarts = 2, options = {}
|
||||
}) {
|
||||
const child = spawn(execPath, ['--watch', '--no-warnings', ...args], { encoding: 'utf8', stdio: 'pipe' });
|
||||
const child = spawn(execPath, [watchFlag, '--no-warnings', ...args], { encoding: 'utf8', stdio: 'pipe', ...options });
|
||||
let completes = 0;
|
||||
let cancelRestarts = () => {};
|
||||
let stderr = '';
|
||||
@@ -88,6 +88,22 @@ async function failWriteSucceed({ file, watchedFile }) {
|
||||
tmpdir.refresh();
|
||||
|
||||
describe('watch mode', { concurrency: true, timeout: 60_000 }, () => {
|
||||
it('should watch changes to a file', async () => {
|
||||
const file = createTmpFile();
|
||||
const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: file, watchFlag: '--watch=true', options: {
|
||||
timeout: 10000
|
||||
} });
|
||||
|
||||
assert.strictEqual(stderr, '');
|
||||
assert.deepStrictEqual(stdout, [
|
||||
'running',
|
||||
`Completed running ${inspect(file)}`,
|
||||
`Restarting ${inspect(file)}`,
|
||||
'running',
|
||||
`Completed running ${inspect(file)}`,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should watch changes to a file - event loop ended', async () => {
|
||||
const file = createTmpFile();
|
||||
const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: file });
|
||||
|
||||
Reference in new issue
Block a user