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

Fix middleware-general test for Turbopack #56211

Merged
merged 4 commits into from
Sep 29, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 0 additions & 38 deletions test/e2e/middleware-general/app/next.config.js

This file was deleted.

67 changes: 46 additions & 21 deletions test/e2e/middleware-general/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,72 @@ describe('Middleware Runtime', () => {
let next: NextInstance

const setup = ({ i18n }: { i18n: boolean }) => {
let nextConfigContent = ''
const nextConfigPath = join(__dirname, '../app/next.config.js')

afterAll(async () => {
await next.destroy()

if (nextConfigContent) {
await fs.writeFile(nextConfigPath, nextConfigContent)
}
})
beforeAll(async () => {
if (!i18n) {
nextConfigContent = await fs.readFile(nextConfigPath, 'utf8')
await fs.writeFile(
nextConfigPath,
nextConfigContent.replace('i18n', '__i18n')
)
}
next = await createNext({
files: {
'next.config.js': new FileRef(
join(__dirname, '../app/next.config.js')
),
'middleware.js': new FileRef(join(__dirname, '../app/middleware.js')),
pages: new FileRef(join(__dirname, '../app/pages')),
'shared-package': new FileRef(
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: {
scripts: {
setup: `cp -r ./shared-package ./node_modules`,
build: 'yarn setup && next build',
dev: `yarn setup && next ${
build: 'pnpm run setup && next build',
dev: `pnpm run setup && next ${
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
}`,
start: 'next start',
},
},
startCommand: (global as any).isNextDev ? 'yarn dev' : 'yarn start',
buildCommand: 'yarn build',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start',
buildCommand: 'pnpm run build',
env: {
ANOTHER_MIDDLEWARE_TEST: 'asdf2',
STRING_ENV_VAR: 'asdf3',
Expand Down