Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/internal/main/watch_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const {
ArrayPrototypePush,
ArrayPrototypePushApply,
ArrayPrototypeSlice,
StringPrototypeIncludes,
StringPrototypeStartsWith,
} = primordials;

Expand Down Expand Up @@ -44,8 +43,10 @@ const argsWithoutWatchOptions = [];
for (let i = 0; i < process.execArgv.length; i++) {
const arg = process.execArgv[i];
if (StringPrototypeStartsWith(arg, '--watch')) {
if (!StringPrototypeIncludes(arg, '=')) {
i++;
i++;
const nextArg = process.execArgv[i];
if (nextArg && StringPrototypeStartsWith(nextArg, '-')) {
ArrayPrototypePush(argsWithoutWatchOptions, nextArg);
}
continue;
}
Expand Down
45 changes: 44 additions & 1 deletion test/sequential/test-watch-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ async function runWriteSucceed({
options = {},
shouldFail = false
}) {
const child = spawn(execPath, [watchFlag, '--no-warnings', ...args], { encoding: 'utf8', stdio: 'pipe', ...options });
args.unshift('--no-warnings');
if (watchFlag !== null) args.unshift(watchFlag);
const child = spawn(execPath, args, { encoding: 'utf8', stdio: 'pipe', ...options });
let completes = 0;
let cancelRestarts = () => {};
let stderr = '';
Expand Down Expand Up @@ -531,4 +533,45 @@ console.log(values.random);
`Completed running ${inspect(file)}`,
]);
});

it('should run when `--watch --inspect`', async () => {
const file = createTmpFile();
const args = ['--watch', '--inspect', file];
const { stdout, stderr } = await runWriteSucceed({ file, watchedFile: file, watchFlag: null, args });

assert.match(stderr, /listening on ws:\/\//);
assert.deepStrictEqual(stdout, [
'running',
`Completed running ${inspect(file)}`,
`Restarting ${inspect(file)}`,
'running',
`Completed running ${inspect(file)}`,
]);
});

it('should run when `--watch -r ./foo.js`', async () => {
const projectDir = tmpdir.resolve('project7');
mkdirSync(projectDir);

const dir = path.join(projectDir, 'watched-dir');
mkdirSync(dir);
writeFileSync(path.join(projectDir, 'some.js'), "console.log('hello')");

const file = createTmpFile("console.log('running');", '.js', projectDir);
const args = ['--watch', '-r', './some.js', file];
const { stdout, stderr } = await runWriteSucceed({
file, watchedFile: file, watchFlag: null, args, options: { cwd: projectDir }
});

assert.strictEqual(stderr, '');
assert.deepStrictEqual(stdout, [
'hello',
'running',
`Completed running ${inspect(file)}`,
`Restarting ${inspect(file)}`,
'hello',
'running',
`Completed running ${inspect(file)}`,
]);
});
});