-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow parallel worker builds when worker plugins is a function #14113
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9eccd4d
feat: allow parallel worker builds when worker plugins is a function
jamsinclair 8cf251b
test: add base unit tests for worker config
jamsinclair 379f4fe
test: add integration tests for parallel and serial worker builds
jamsinclair 8633fa4
test: remove rogue only
jamsinclair 2955c97
chore: fix debug worker plugin logging
jamsinclair d7f294b
chore: remove unused import
jamsinclair 8f5e428
test: fix erroneous count increment from state plugin
jamsinclair 9449d65
test: flip expected state value order
jamsinclair 552c1da
test: switch to asserting the values are different
jamsinclair f95cdd9
test: tidy up type names
jamsinclair 8c11f99
chore: fix up vite config files
jamsinclair 0361480
test: add deeply nested worker test
jamsinclair 88f2ee2
test: add plugin to include deeply nested worker in parallel test
jamsinclair d5b3057
test: fix serial tests
jamsinclair File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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
35 changes: 35 additions & 0 deletions
35
playground/worker/__tests__/parallel/parallel-worker-build.spec.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { describe, test } from 'vitest' | ||
import { isBuild, page, untilUpdated } from '~utils' | ||
|
||
test('deeply nested workers', async () => { | ||
await untilUpdated( | ||
async () => page.textContent('.deeply-nested-worker'), | ||
/Hello\sfrom\sroot.*\/parallel\/.+deeply-nested-worker\.js/, | ||
true, | ||
) | ||
await untilUpdated( | ||
async () => page.textContent('.deeply-nested-second-worker'), | ||
/Hello\sfrom\ssecond.*\/parallel\/.+second-worker\.js/, | ||
true, | ||
) | ||
await untilUpdated( | ||
async () => page.textContent('.deeply-nested-third-worker'), | ||
/Hello\sfrom\sthird.*\/parallel\/.+third-worker\.js/, | ||
true, | ||
) | ||
}) | ||
|
||
describe.runIf(isBuild)('build', () => { | ||
test('expect the plugin state to be unpolluted and match across worker builds', async () => { | ||
await untilUpdated( | ||
() => page.textContent('.nested-worker-plugin-state'), | ||
'"data":1', | ||
true, | ||
) | ||
await untilUpdated( | ||
() => page.textContent('.sub-worker-plugin-state'), | ||
'"data":1', | ||
true, | ||
) | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
playground/worker/__tests__/serial/serial-worker-build.spec.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { isBuild, page, untilUpdated } from '~utils' | ||
|
||
describe.runIf(isBuild)('build', () => { | ||
test('expect the plugin state to be polluted and not match across worker builds', async () => { | ||
await untilUpdated( | ||
() => page.textContent('.nested-worker-plugin-state'), | ||
'"type":"workerPluginState"', | ||
true, | ||
) | ||
await untilUpdated( | ||
() => page.textContent('.sub-worker-plugin-state'), | ||
'"type":"subWorkerPluginState"', | ||
true, | ||
) | ||
|
||
const nestedWorkerPluginState = JSON.parse( | ||
await page.textContent('.nested-worker-plugin-state'), | ||
) | ||
const subWorkerPluginState = JSON.parse( | ||
await page.textContent('.sub-worker-plugin-state'), | ||
) | ||
// The plugin state is polluted and should have a different data value from the sub worker | ||
expect(nestedWorkerPluginState.data).not.toEqual(subWorkerPluginState.data) | ||
}) | ||
}) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
self.postMessage({ | ||
type: 'deeplyNestedSecondWorker', | ||
data: [ | ||
'Hello from second level nested worker', | ||
import.meta.env.BASE_URL, | ||
self.location.url, | ||
import.meta.url, | ||
].join(' '), | ||
}) | ||
|
||
const deeplyNestedThirdWorker = new Worker( | ||
new URL('deeply-nested-third-worker.js', import.meta.url), | ||
{ type: 'module' }, | ||
) | ||
deeplyNestedThirdWorker.addEventListener('message', (ev) => { | ||
self.postMessage(ev.data) | ||
}) | ||
|
||
console.log('deeply-nested-second-worker.js') |
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
self.postMessage({ | ||
type: 'deeplyNestedThirdWorker', | ||
data: [ | ||
'Hello from third level nested worker', | ||
import.meta.env.BASE_URL, | ||
self.location.url, | ||
import.meta.url, | ||
].join(' '), | ||
}) | ||
|
||
console.log('deeply-nested-third-worker.js') |
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
self.postMessage({ | ||
type: 'deeplyNestedWorker', | ||
data: [ | ||
'Hello from root worker', | ||
import.meta.env.BASE_URL, | ||
self.location.url, | ||
import.meta.url, | ||
].join(' '), | ||
}) | ||
|
||
const deeplyNestedSecondWorker = new Worker( | ||
new URL('deeply-nested-second-worker.js', import.meta.url), | ||
{ type: 'module' }, | ||
) | ||
deeplyNestedSecondWorker.addEventListener('message', (ev) => { | ||
self.postMessage(ev.data) | ||
}) | ||
|
||
console.log('deeply-nested-worker.js') |
Oops, something went wrong.
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.
Might need to add some comments. The assumption is that the user
worker.plugins
function would be side effect free. This allows us to pre-process relevant hook/config updates but still allow fresh plugin instantiation per worker build.Does that make sense? 馃槄