-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
watch: track worker thread entry files in --watch mode #62368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SudhansuBandha
wants to merge
5
commits into
nodejs:main
Choose a base branch
from
SudhansuBandha:watch-worker-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+285
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f9beab0
watch: track worker thread entry files in --watch mode
SudhansuBandha ba11d26
test: add test coverage for worker entry files in --watch mode
SudhansuBandha c9f14a3
wacth: track worker thread dependencies in --watch mode for cjs files
SudhansuBandha 930dc62
watch: track worker thread dependencies in --watch mode for esm modules
SudhansuBandha 634a756
watch: added tests for worker in -- watch mode to include worker file…
SudhansuBandha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -922,4 +922,238 @@ process.on('message', (message) => { | |
| await done(); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it('should watch changes to worker - cjs', async () => { | ||
| const dir = tmpdir.resolve(`watch-worker-cjs-${Date.now()}`); | ||
| mkdirSync(dir); | ||
|
|
||
| const worker = path.join(dir, 'worker.js'); | ||
|
|
||
| writeFileSync(worker, ` | ||
| console.log("worker running"); | ||
| `); | ||
|
|
||
| const file = createTmpFile(` | ||
| const { Worker } = require('node:worker_threads'); | ||
|
|
||
| const w = new Worker(${JSON.stringify(worker)}); | ||
| w.on('exit', () => { | ||
| console.log('running'); | ||
| }); | ||
| `, '.js', dir); | ||
|
|
||
| const { stderr, stdout } = await runWriteSucceed({ | ||
| file, | ||
| watchedFile: worker, | ||
| }); | ||
|
|
||
| assert.strictEqual(stderr, ''); | ||
| assert.deepStrictEqual(stdout, [ | ||
| 'worker running', | ||
| 'running', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| `Restarting ${inspect(file)}`, | ||
| 'worker running', | ||
| 'running', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should watch changes to worker dependencies - cjs', async () => { | ||
| const dir = tmpdir.resolve(`watch-worker-dep-cjs-${Date.now()}`); | ||
| mkdirSync(dir); | ||
|
|
||
| const dep = path.join(dir, 'dep.js'); | ||
| const worker = path.join(dir, 'worker.js'); | ||
|
|
||
| writeFileSync(dep, ` | ||
| module.exports = 'dep v1'; | ||
| `); | ||
|
|
||
| writeFileSync(worker, ` | ||
| const dep = require('./dep.js'); | ||
| console.log(dep); | ||
| `); | ||
|
|
||
| const file = createTmpFile(` | ||
| const { Worker } = require('node:worker_threads'); | ||
|
|
||
| const w = new Worker(${JSON.stringify(worker)}); | ||
| w.on('exit', () => { | ||
| console.log('running'); | ||
|
Comment on lines
+982
to
+983
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is confusing |
||
| }); | ||
| `, '.js', dir); | ||
|
|
||
| const { stderr, stdout } = await runWriteSucceed({ | ||
| file, | ||
| watchedFile: dep, | ||
| }); | ||
|
|
||
| assert.strictEqual(stderr, ''); | ||
| assert.deepStrictEqual(stdout, [ | ||
| 'dep v1', | ||
| 'running', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| `Restarting ${inspect(file)}`, | ||
| 'dep v1', | ||
| 'running', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should watch changes to nested worker dependencies - cjs', async () => { | ||
| const dir = tmpdir.resolve(`watch-worker-dep-cjs-${Date.now()}`); | ||
| mkdirSync(dir); | ||
|
|
||
| const subDep = path.join(dir, 'sub-dep.js'); | ||
| const dep = path.join(dir, 'dep.js'); | ||
| const worker = path.join(dir, 'worker.js'); | ||
|
|
||
| writeFileSync(subDep, ` | ||
| module.exports = 'sub-dep v1'; | ||
| `); | ||
|
|
||
| writeFileSync(dep, ` | ||
| const subDep = require('./sub-dep.js'); | ||
| console.log(subDep); | ||
| module.exports = 'dep v1'; | ||
| `); | ||
|
|
||
| writeFileSync(worker, ` | ||
| const dep = require('./dep.js'); | ||
| `); | ||
|
|
||
| const file = createTmpFile(` | ||
| const { Worker } = require('node:worker_threads'); | ||
|
|
||
| const w = new Worker(${JSON.stringify(worker)}); | ||
| w.on('exit', () => { | ||
| console.log('running'); | ||
| }); | ||
| `, '.js', dir); | ||
|
|
||
| const { stderr, stdout } = await runWriteSucceed({ | ||
| file, | ||
| watchedFile: subDep, | ||
| }); | ||
|
|
||
| assert.strictEqual(stderr, ''); | ||
| assert.deepStrictEqual(stdout, [ | ||
| 'sub-dep v1', | ||
| 'running', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| `Restarting ${inspect(file)}`, | ||
| 'sub-dep v1', | ||
| 'running', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should watch changes to worker - esm', async () => { | ||
| const dir = tmpdir.resolve(`watch-worker-esm-${Date.now()}`); | ||
| mkdirSync(dir); | ||
|
|
||
| const worker = path.join(dir, 'worker.mjs'); | ||
|
|
||
| writeFileSync(worker, ` | ||
| console.log("worker running"); | ||
| `); | ||
|
|
||
| const file = createTmpFile(` | ||
| import { Worker } from 'node:worker_threads'; | ||
| new Worker(new URL(${JSON.stringify(pathToFileURL(worker))})); | ||
| `, '.mjs', dir); | ||
|
|
||
| const { stderr, stdout } = await runWriteSucceed({ | ||
| file, | ||
| watchedFile: worker, | ||
| }); | ||
|
|
||
| assert.strictEqual(stderr, ''); | ||
| assert.deepStrictEqual(stdout, [ | ||
| 'worker running', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| `Restarting ${inspect(file)}`, | ||
| 'worker running', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should watch changes to worker dependencies - esm', async () => { | ||
| const dir = tmpdir.resolve(`watch-worker-dep-esm-${Date.now()}`); | ||
| mkdirSync(dir); | ||
|
|
||
| const dep = path.join(dir, 'dep.mjs'); | ||
| const worker = path.join(dir, 'worker.mjs'); | ||
|
|
||
| writeFileSync(dep, ` | ||
| export default 'dep v1'; | ||
| `); | ||
|
|
||
| writeFileSync(worker, ` | ||
| import dep from ${JSON.stringify(pathToFileURL(dep))}; | ||
| console.log(dep); | ||
| `); | ||
|
|
||
| const file = createTmpFile(` | ||
| import { Worker } from 'node:worker_threads'; | ||
| new Worker(new URL(${JSON.stringify(pathToFileURL(worker))})); | ||
| `, '.mjs', dir); | ||
|
|
||
| const { stderr, stdout } = await runWriteSucceed({ | ||
| file, | ||
| watchedFile: dep, | ||
| }); | ||
|
|
||
| assert.strictEqual(stderr, ''); | ||
| assert.deepStrictEqual(stdout, [ | ||
| 'dep v1', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| `Restarting ${inspect(file)}`, | ||
| 'dep v1', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should watch changes to nested worker dependencies - esm', async () => { | ||
| const dir = tmpdir.resolve(`watch-worker-dep-esm-${Date.now()}`); | ||
| mkdirSync(dir); | ||
|
|
||
| const subDep = path.join(dir, 'sub-dep.mjs'); | ||
| const dep = path.join(dir, 'dep.mjs'); | ||
| const worker = path.join(dir, 'worker.mjs'); | ||
|
|
||
| writeFileSync(subDep, ` | ||
| export default 'sub-dep v1'; | ||
| `); | ||
|
|
||
| writeFileSync(dep, ` | ||
| import subDep from ${JSON.stringify(pathToFileURL(subDep))}; | ||
| console.log(subDep); | ||
| export default 'dep v1'; | ||
| `); | ||
|
|
||
| writeFileSync(worker, ` | ||
| import dep from ${JSON.stringify(pathToFileURL(dep))}; | ||
| `); | ||
|
|
||
| const file = createTmpFile(` | ||
| import { Worker } from 'node:worker_threads'; | ||
| new Worker(new URL(${JSON.stringify(pathToFileURL(worker))})); | ||
| `, '.mjs', dir); | ||
|
|
||
| const { stderr, stdout } = await runWriteSucceed({ | ||
| file, | ||
| watchedFile: subDep, | ||
| }); | ||
|
|
||
| assert.strictEqual(stderr, ''); | ||
| assert.deepStrictEqual(stdout, [ | ||
| 'sub-dep v1', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| `Restarting ${inspect(file)}`, | ||
| 'sub-dep v1', | ||
| `Completed running ${inspect(file)}. Waiting for file changes before restarting...`, | ||
| ]); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? why not use tmpdir directly?