Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
184 lines
5.6 KiB
TypeScript
184 lines
5.6 KiB
TypeScript
import { isNextDeploy, isNextStart, nextTestSetup } from 'e2e-utils'
|
|
import { retry } from 'next-test-utils'
|
|
import { Page } from 'playwright'
|
|
|
|
describe('app dir - workers', () => {
|
|
const { next, isTurbopack } = nextTestSetup({
|
|
files: __dirname,
|
|
env: {
|
|
NEXT_DEPLOYMENT_ID: isNextStart ? 'test-deployment-id' : undefined,
|
|
},
|
|
disableAutoSkewProtection: true,
|
|
})
|
|
|
|
function beforePageLoad(page: Page) {
|
|
// TODO fix deployment id for webpack
|
|
if (isTurbopack && (isNextDeploy || isNextStart)) {
|
|
page.on('request', (request) => {
|
|
const url = request.url()
|
|
if (url.includes('/_next/')) {
|
|
let parsed = new URL(url, next.url)
|
|
expect(parsed.searchParams.get('dpl')).toBe(next.assetToken)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
it('should support web workers with dynamic imports', async () => {
|
|
const browser = await next.browser('/classic', {
|
|
beforePageLoad,
|
|
})
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe('default')
|
|
|
|
await browser.elementByCss('button').click()
|
|
|
|
await retry(async () =>
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe(
|
|
'worker.ts:worker-dep'
|
|
)
|
|
)
|
|
})
|
|
|
|
it('should support module web workers with dynamic imports', async () => {
|
|
const browser = await next.browser('/module', {
|
|
beforePageLoad,
|
|
})
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe('default')
|
|
|
|
await browser.elementByCss('button').click()
|
|
|
|
await retry(async () =>
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe(
|
|
'worker.ts:worker-dep'
|
|
)
|
|
)
|
|
})
|
|
|
|
it('should not bundle web workers with string specifiers', async () => {
|
|
const browser = await next.browser('/string', {
|
|
beforePageLoad,
|
|
})
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe('default')
|
|
|
|
await browser.elementByCss('button').click()
|
|
|
|
await retry(async () =>
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe(
|
|
'unbundled-worker'
|
|
)
|
|
)
|
|
})
|
|
|
|
if (isNextDeploy || isNextStart) {
|
|
it('should have access to NEXT_DEPLOYMENT_ID in web worker', async () => {
|
|
const browser = await next.browser('/deployment-id', {
|
|
beforePageLoad,
|
|
})
|
|
|
|
// Verify main thread has deployment ID and it's not empty
|
|
const mainDeploymentId = await browser
|
|
.elementByCss('#main-deployment-id')
|
|
.text()
|
|
expect(mainDeploymentId).toBe(next.deploymentId)
|
|
|
|
// Initial worker state should be default
|
|
expect(await browser.elementByCss('#worker-deployment-id').text()).toBe(
|
|
'default'
|
|
)
|
|
|
|
// Trigger worker to get deployment ID
|
|
await browser.elementByCss('button').click()
|
|
|
|
// Wait for worker to respond and verify it matches main thread
|
|
await retry(async () => {
|
|
const workerDeploymentId = await browser
|
|
.elementByCss('#worker-deployment-id')
|
|
.text()
|
|
expect(workerDeploymentId).toBe(next.deploymentId)
|
|
})
|
|
})
|
|
}
|
|
|
|
it('should support loading WASM files in workers', async () => {
|
|
const browser = await next.browser('/wasm', {
|
|
beforePageLoad,
|
|
})
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe('default')
|
|
|
|
await browser.elementByCss('button').click()
|
|
|
|
// The WASM add_one(41) should return 42
|
|
await retry(async () =>
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe(
|
|
'result:42'
|
|
)
|
|
)
|
|
})
|
|
|
|
it('should support shared workers', async () => {
|
|
if (!isTurbopack) {
|
|
// webpack requires a magic attribute for shared workers to function
|
|
return
|
|
}
|
|
const browser = await next.browser('/shared', {
|
|
beforePageLoad,
|
|
})
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe('default')
|
|
|
|
await browser.elementByCss('button').click()
|
|
|
|
await retry(async () =>
|
|
expect(await browser.elementByCss('#worker-state').text()).toBe(
|
|
'shared-worker.ts:worker-dep:2'
|
|
)
|
|
)
|
|
})
|
|
|
|
it('should support loading PNG files in web workers', async () => {
|
|
const browser = await next.browser('/png', {
|
|
beforePageLoad,
|
|
})
|
|
// Initial state should be default
|
|
expect(await browser.elementByCss('#png-url').text()).toBe('default')
|
|
|
|
// Trigger worker to get PNG info
|
|
await browser.elementByCss('button').click()
|
|
|
|
// Wait for worker to respond and verify PNG info
|
|
await retry(async () => {
|
|
const pngUrl = await browser.elementByCss('#png-url').text()
|
|
expect(pngUrl).toContain('test-image')
|
|
expect(pngUrl).toContain('.png')
|
|
})
|
|
|
|
await retry(async () => {
|
|
const pngWidth = await browser.elementByCss('#png-width').text()
|
|
expect(pngWidth).toBe('1')
|
|
})
|
|
|
|
await retry(async () => {
|
|
const pngHeight = await browser.elementByCss('#png-height').text()
|
|
expect(pngHeight).toBe('1')
|
|
})
|
|
|
|
// Verify the worker actually fetched the PNG (proves asset URL works in worker)
|
|
await retry(async () => {
|
|
const fetchStatus = await browser.elementByCss('#fetch-status').text()
|
|
expect(fetchStatus).toBe('200')
|
|
})
|
|
|
|
await retry(async () => {
|
|
const contentType = await browser.elementByCss('#content-type').text()
|
|
expect(contentType).toBe('image/png')
|
|
})
|
|
|
|
// Log the full verification info for visual inspection
|
|
const fetchedFrom = await browser.elementByCss('#fetched-from').text()
|
|
console.log('Web Worker PNG verification:', {
|
|
fetchedFrom,
|
|
contentType: await browser.elementByCss('#content-type').text(),
|
|
status: await browser.elementByCss('#fetch-status').text(),
|
|
})
|
|
})
|
|
})
|