Files
4588a73542 Convert tests using createNext -> nextTestSetup (#93767)
## What?

Converts existing `createNext()` usage into `nextTestSetup()`. 

`createNext()` was the setup step we had before `nextTestSetup()` was
added.

This PR focused on the simple conversion cases. There will be a
follow-up to complete the last few.

---------

Co-authored-by: Cursor <[email protected]>
2026-05-12 13:16:31 +02:00

60 lines
1.6 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import { fetchViaHTTP } from 'next-test-utils'
describe('Edge compiler module exports preference', () => {
if ((global as any).isNextDeploy) {
// this test is skipped when deployed because it manually creates a package in the node_modules directory
// which is unsupported
it('should skip next deploy', () => {})
return
}
const { next } = nextTestSetup({
files: {
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`,
'middleware.js': `
import { NextResponse } from 'next/server';
import lib from 'my-lib';
export default (req) => {
return NextResponse.next({
headers: {
'x-imported': lib
}
})
}
`,
'node_modules/my-lib/package.json': JSON.stringify({
name: 'my-lib',
version: '1.0.0',
main: 'index.js',
browser: 'browser.js',
}),
'node_modules/my-lib/index.js': `module.exports = "Node.js"`,
'node_modules/my-lib/browser.js': `module.exports = "Browser"`,
},
packageJson: {
scripts: {
build: 'next build',
dev: 'next dev',
start: 'next start',
},
},
installCommand: 'pnpm i',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start',
buildCommand: 'pnpm run build',
dependencies: {},
})
it('favors the browser export', async () => {
const response = await fetchViaHTTP(next.url, '/')
expect(Object.fromEntries(response.headers)).toMatchObject({
'x-imported': 'Browser',
})
})
})