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
89 lines
3.2 KiB
TypeScript
89 lines
3.2 KiB
TypeScript
import { isNextDev, nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('node-worker-threads', () => {
|
|
const { next, skipped, isTurbopack } = nextTestSetup({
|
|
files: __dirname,
|
|
skipDeployment: true,
|
|
dependencies: {
|
|
pino: '9.6.0',
|
|
},
|
|
})
|
|
|
|
if (skipped) {
|
|
return
|
|
}
|
|
|
|
// These tests are Turbopack-specific since they rely on Turbopack's worker bundling
|
|
if (!isTurbopack) {
|
|
it.skip('webpack doesnt support bundling worker-threads', () => {})
|
|
return
|
|
}
|
|
|
|
it('should handle simple worker with relative path', async () => {
|
|
const res = await next.fetch('/api/simple-worker-test')
|
|
const data = await res.json()
|
|
expect(res.status).toBe(200)
|
|
expect(data.success).toBe(true)
|
|
expect(data.message).toBe('pong from simple worker')
|
|
})
|
|
|
|
it('should handle self-referencing worker with __filename', async () => {
|
|
const res = await next.fetch('/api/worker-test')
|
|
const data = await res.json()
|
|
expect(res.status).toBe(200)
|
|
expect(data.success).toBe(true)
|
|
expect(data.message).toBe('pong')
|
|
})
|
|
|
|
it('should handle pino logger with transport (thread-stream)', async () => {
|
|
// Pino with transports uses thread-stream internally, which creates worker_threads
|
|
// with a broad pattern like join(__dirname, 'lib', 'worker.js') that can match
|
|
// non-evaluatable files like package.json. This tests that we properly downgrade
|
|
// those errors to warnings via loose_errors.
|
|
const res = await next.fetch('/api/pino-test')
|
|
const data = await res.json()
|
|
expect(res.status).toBe(200)
|
|
expect(data.success).toBe(true)
|
|
})
|
|
|
|
it('should not expose __turbopack internal workerData to user code', async () => {
|
|
// Verify that internal __turbopack_globals__ data used to forward globals
|
|
// is not visible to user code accessing workerData
|
|
const res = await next.fetch('/api/workerdata-check')
|
|
const data = await res.json()
|
|
expect(res.status).toBe(200)
|
|
expect(data.success).toBe(true)
|
|
// The __turbopack_globals__ key should NOT be visible to user code
|
|
expect(data.hasTurbopackKeys).toBe(false)
|
|
expect(data.turbopackKeys).toEqual([])
|
|
})
|
|
|
|
it('should handle PNG file import in worker', async () => {
|
|
// Test that static assets (like PNG images) can be imported and used in workers
|
|
// The server worker returns the PNG URL, then we fetch it from the client
|
|
// to verify the URL is correctly formed and accessible
|
|
const res = await next.fetch('/api/png-worker-test')
|
|
const data = await res.json()
|
|
expect(res.status).toBe(200)
|
|
expect(data.success).toBe(true)
|
|
expect(data.pngInfo).toBeDefined()
|
|
expect(data.pngInfo.width).toBe(1)
|
|
expect(data.pngInfo.height).toBe(1)
|
|
|
|
const url = new URL(data.pngInfo.url, 'http://localhost')
|
|
expect(url.pathname).toMatch(
|
|
/\/_next\/static.*\/test-image\.[a-f0-9]+\.png/
|
|
)
|
|
if (!isNextDev) {
|
|
expect(next.assetToken).toMatch(/.+/)
|
|
expect(url.searchParams.get('dpl')).toBe(next.assetToken)
|
|
}
|
|
|
|
// Now fetch the PNG URL from the client to verify it's accessible
|
|
// This tests that the URL generated by the server worker is correct
|
|
const pngRes = await next.fetch(data.pngInfo.url)
|
|
expect(pngRes.status).toBe(200)
|
|
expect(pngRes.headers.get('content-type')).toBe('image/png')
|
|
})
|
|
})
|