Unverified Commit 2e36e7d8 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Fix middleware-general test for Turbopack (#56211)

This test failed for Turbopack because of the rename from `i18n` to `__i18n` to not use that config. Turbopack does checking of config options to ensure it doesn't run when an option is not implemented, so that caused the test run to bail out.
parent 55a638ba
module.exports = {
experimental: {
webpackBuildWorker: true,
},
i18n: {
locales: ['en', 'fr', 'nl'],
defaultLocale: 'en',
},
redirects() {
return [
{
source: '/redirect-1',
destination: '/somewhere/else',
permanent: false,
},
]
},
rewrites() {
return [
{
source: '/rewrite-1',
destination: '/ssr-page?from=config',
},
{
source: '/rewrite-2',
destination: '/about/a?from=next-config',
},
{
source: '/sha',
destination: '/shallow',
},
{
source: '/rewrite-3',
destination: '/blog/middleware-rewrite?hello=config',
},
]
},
}
...@@ -18,47 +18,72 @@ describe('Middleware Runtime', () => { ...@@ -18,47 +18,72 @@ describe('Middleware Runtime', () => {
let next: NextInstance let next: NextInstance
const setup = ({ i18n }: { i18n: boolean }) => { const setup = ({ i18n }: { i18n: boolean }) => {
let nextConfigContent = ''
const nextConfigPath = join(__dirname, '../app/next.config.js')
afterAll(async () => { afterAll(async () => {
await next.destroy() await next.destroy()
if (nextConfigContent) {
await fs.writeFile(nextConfigPath, nextConfigContent)
}
}) })
beforeAll(async () => { beforeAll(async () => {
if (!i18n) {
nextConfigContent = await fs.readFile(nextConfigPath, 'utf8')
await fs.writeFile(
nextConfigPath,
nextConfigContent.replace('i18n', '__i18n')
)
}
next = await createNext({ next = await createNext({
files: { files: {
'next.config.js': new FileRef(
join(__dirname, '../app/next.config.js')
),
'middleware.js': new FileRef(join(__dirname, '../app/middleware.js')), 'middleware.js': new FileRef(join(__dirname, '../app/middleware.js')),
pages: new FileRef(join(__dirname, '../app/pages')), pages: new FileRef(join(__dirname, '../app/pages')),
'shared-package': new FileRef( 'shared-package': new FileRef(
join(__dirname, '../app/node_modules/shared-package') join(__dirname, '../app/node_modules/shared-package')
), ),
}, },
nextConfig: {
experimental: {
webpackBuildWorker: true,
},
...(i18n
? {
i18n: {
locales: ['en', 'fr', 'nl'],
defaultLocale: 'en',
},
}
: {}),
async redirects() {
return [
{
source: '/redirect-1',
destination: '/somewhere/else',
permanent: false,
},
]
},
async rewrites() {
return [
{
source: '/rewrite-1',
destination: '/ssr-page?from=config',
},
{
source: '/rewrite-2',
destination: '/about/a?from=next-config',
},
{
source: '/sha',
destination: '/shallow',
},
{
source: '/rewrite-3',
destination: '/blog/middleware-rewrite?hello=config',
},
]
},
},
packageJson: { packageJson: {
scripts: { scripts: {
setup: `cp -r ./shared-package ./node_modules`, setup: `cp -r ./shared-package ./node_modules`,
build: 'yarn setup && next build', build: 'pnpm run setup && next build',
dev: `yarn setup && next ${ dev: `pnpm run setup && next ${
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev' shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
}`, }`,
start: 'next start', start: 'next start',
}, },
}, },
startCommand: (global as any).isNextDev ? 'yarn dev' : 'yarn start', startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start',
buildCommand: 'yarn build', buildCommand: 'pnpm run build',
env: { env: {
ANOTHER_MIDDLEWARE_TEST: 'asdf2', ANOTHER_MIDDLEWARE_TEST: 'asdf2',
STRING_ENV_VAR: 'asdf3', STRING_ENV_VAR: 'asdf3',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment