Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbopack build: Skip experimental.fallbackNodePolyfills tests #68825

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/04-architecture/turbopack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ These features are currently not supported:
- We are planning to implement this in the future.
- `experimental.sri.algorithm`
- We are planning to implement this in the future.
- `experimental.fallbackNodePolyfills`
- We are planning to implement this in the future.
- `experimental.esmExternals`
- We are currently not planning to support the legacy esmExternals configuration in Next.js with Turbopack.
- [AMP](/docs/pages/building-your-application/configuring/amp).
Expand Down
84 changes: 44 additions & 40 deletions test/production/disable-fallback-polyfills/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { createNext } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'

describe('Disable fallback polyfills', () => {
let next: NextInstance
// TODO: Implement experimental.fallbackNodePolyfills
;(process.env.TURBOPACK ? describe.skip : describe)(
'Disable fallback polyfills',
() => {
let next: NextInstance

function getFirstLoadSize(output: string) {
const firstLoadRe =
/○ \/.*? (?<size>\d.*?) [^\d]{2} (?<firstLoad>\d.*?) [^\d]{2}/
return Number(output.match(firstLoadRe).groups.firstLoad)
}
function getFirstLoadSize(output: string) {
const firstLoadRe =
/○ \/.*? (?<size>\d.*?) [^\d]{2} (?<firstLoad>\d.*?) [^\d]{2}/
return Number(output.match(firstLoadRe).groups.firstLoad)
}

beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
import { useEffect } from 'react'
import crypto from 'crypto'

Expand All @@ -24,40 +27,40 @@ describe('Disable fallback polyfills', () => {
return <p>hello world</p>
}
`,
},
dependencies: {
axios: '0.27.2',
},
},
dependencies: {
axios: '0.27.2',
},
})
await next.stop()
})
await next.stop()
})
afterAll(() => next.destroy())
afterAll(() => next.destroy())

it('Fallback polyfills added by default', async () => {
expect(getFirstLoadSize(next.cliOutput)).not.toBeLessThan(200)
})
it('Fallback polyfills added by default', async () => {
expect(getFirstLoadSize(next.cliOutput)).not.toBeLessThan(200)
})

it('Reduced bundle size when polyfills are disabled', async () => {
await next.patchFile(
'next.config.js',
`module.exports = {
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()
)
await next.start()
await next.stop()

expect(getFirstLoadSize(next.cliOutput)).toBeLessThan(200)
})
expect(getFirstLoadSize(next.cliOutput)).toBeLessThan(200)
})

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'
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() {
Expand All @@ -67,8 +70,9 @@ describe('Disable fallback polyfills', () => {

return "hello world"
}`
)
)

await expect(next.start()).not.toReject()
})
})
await expect(next.start()).not.toReject()
})
}
)
9 changes: 4 additions & 5 deletions test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15788,14 +15788,13 @@
"runtimeError": false
},
"test/production/disable-fallback-polyfills/index.test.ts": {
"passed": [
"Disable fallback polyfills Fallback polyfills added by default"
],
"failed": [
"passed": [],
"failed": [],
"pending": [
"Disable fallback polyfills Fallback polyfills added by default",
"Disable fallback polyfills Pass build without error if non-polyfilled module is unreachable",
"Disable fallback polyfills Reduced bundle size when polyfills are disabled"
],
"pending": [],
"flakey": [],
"runtimeError": false
},
Expand Down
Loading