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
202 lines
6.9 KiB
TypeScript
202 lines
6.9 KiB
TypeScript
import { join } from 'path'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('node builtins', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'node-builtins'),
|
|
})
|
|
|
|
it('should have polyfilled node.js builtins for the browser correctly', async () => {
|
|
const browser = await next.browser('/')
|
|
|
|
await browser.waitForCondition('window.didRender', 15000)
|
|
|
|
const data = await browser
|
|
.waitForElementByCss('#node-browser-polyfills')
|
|
.text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.process).toBe('browser')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should have polyfilled node.js builtins for the browser correctly in client component', async () => {
|
|
const browser = await next.browser('/client-component')
|
|
|
|
await browser.waitForCondition('window.didRender', 15000)
|
|
|
|
const data = await browser
|
|
.waitForElementByCss('#node-browser-polyfills')
|
|
.text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.process).toBe('browser')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should support node.js builtins', async () => {
|
|
const $ = await next.render$('/server')
|
|
|
|
const data = $('#node-browser-polyfills').text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.process).toInclude('next-server')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should support node.js builtins prefixed by node:', async () => {
|
|
const $ = await next.render$('/server-node-schema')
|
|
|
|
const data = $('#node-browser-polyfills').text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.process).toInclude('next-server')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should support node.js builtins in server component', async () => {
|
|
const $ = await next.render$('/server-component')
|
|
|
|
const data = $('#node-browser-polyfills').text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should support node.js builtins prefixed by node: in server component', async () => {
|
|
const $ = await next.render$('/server-component/node-schema')
|
|
|
|
const data = $('#node-browser-polyfills').text()
|
|
const parsedData = JSON.parse(data)
|
|
|
|
expect(parsedData.vm).toBe(105)
|
|
expect(parsedData.hash).toBe(
|
|
'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
)
|
|
expect(parsedData.buffer).toBe('hello world')
|
|
expect(parsedData.stream).toBe(true)
|
|
expect(parsedData.assert).toBe(true)
|
|
expect(parsedData.constants).toBe(7)
|
|
expect(parsedData.domain).toBe(true)
|
|
expect(parsedData.http).toBe(true)
|
|
expect(parsedData.https).toBe(true)
|
|
expect(parsedData.os).toBe('\n')
|
|
expect(parsedData.path).toBe('/hello/world/test.txt')
|
|
expect(parsedData.querystring).toBe('a=b')
|
|
expect(parsedData.stringDecoder).toBe(true)
|
|
expect(parsedData.sys).toBe(true)
|
|
expect(parsedData.timers).toBe(true)
|
|
})
|
|
|
|
it('should throw when unsupported builtins are used in middleware', async () => {
|
|
const res = await next.fetch('/middleware-test')
|
|
expect(res.status).toBe(200)
|
|
expect(JSON.parse(res.headers.get('supported-result')))
|
|
.toMatchInlineSnapshot(`
|
|
{
|
|
"assert": true,
|
|
"buffer": "hello world",
|
|
"eventEmitter": true,
|
|
"util": true,
|
|
}
|
|
`)
|
|
expect(JSON.parse(res.headers.get('unsupported-result')))
|
|
.toMatchInlineSnapshot(`
|
|
{
|
|
"constants": false,
|
|
"crypto": false,
|
|
"domain": false,
|
|
"http": false,
|
|
"https": false,
|
|
"os": false,
|
|
"path": false,
|
|
"stream": false,
|
|
"timers": false,
|
|
"tty": false,
|
|
"vm": false,
|
|
"zlib": false,
|
|
}
|
|
`)
|
|
})
|
|
})
|