Files
Arian Tron 61f56f997c
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
first commit
2026-03-10 19:37:31 +03:30

107 lines
3.1 KiB
TypeScript

import { createNext } from 'e2e-utils'
import type { NextInstance } from 'e2e-utils'
import { statSync } from 'fs'
import { join } from 'path'
// TODO: Implement experimental.fallbackNodePolyfills
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
'Disable fallback polyfills',
() => {
let next: NextInstance
async function getIndexPageSize() {
// Read build manifest to get chunk files for the index page
// this only works reliably for pages router and simple examples.
const buildManifest = await next.readJSON('.next/build-manifest.json')
// Get chunks for the '/' page
const indexPageChunks = buildManifest.pages['/'] || []
// Calculate total size of all chunks for the index page
let totalSize = 0
for (const chunkPath of indexPageChunks) {
const fullChunkPath = join(next.testDir, '.next', chunkPath)
try {
const stats = statSync(fullChunkPath)
totalSize += stats.size
} catch (error) {
console.warn(`Could not read chunk: ${chunkPath}`, error.message)
}
}
// Convert to kB for easier comparison
return totalSize / 1024
}
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
import { useEffect } from 'react'
import crypto from 'crypto'
export default function Page() {
useEffect(() => {
crypto;
}, [])
return <p>hello world</p>
}
`,
},
dependencies: {
axios: '0.27.2',
},
})
await next.stop()
})
afterAll(() => next.destroy())
it('Fallback polyfills added by default', async () => {
const indexPageSizeKB = await getIndexPageSize()
console.log(
`Index page size (with polyfills): ${indexPageSizeKB.toFixed(2)} kB`
)
expect(indexPageSizeKB).not.toBeLessThan(400)
})
it('Reduced bundle size when polyfills are disabled', async () => {
await next.patchFile(
'next.config.js',
`module.exports = {
experimental: {
fallbackNodePolyfills: false
}
}`
)
await next.start()
await next.stop()
const indexPageSizeKB = await getIndexPageSize()
console.log(
`Index page size (without polyfills): ${indexPageSizeKB.toFixed(2)} kB`
)
expect(indexPageSizeKB).toBeLessThan(400)
})
it('Pass build without error if non-polyfilled module is unreachable', async () => {
// `axios` uses `Buffer`, but it should be unreachable in the browser.
// https://github.com/axios/axios/blob/649d739288c8e2c55829ac60e2345a0f3439c730/lib/helpers/toFormData.js#L138
await next.patchFile(
'pages/index.js',
`import axios from 'axios'
import { useEffect } from 'react'
export default function Home() {
useEffect(() => {
axios.get('/api')
}, [])
return "hello world"
}`
)
await expect(next.start()).not.toReject()
})
}
)