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

Ensure required-server-files test can exit cleanly #66765

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ describe('required server files app router', () => {
cwd: next.testDir,
}
)

if (process.platform === 'darwin') {
appPort = `http://127.0.0.1:${appPort}`
}
}

beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ describe('required server files i18n', () => {
},
}
)

if (process.platform === 'darwin') {
appPort = `http://127.0.0.1:${appPort}`
}
})

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ describe('required server files app router', () => {
cwd: next.testDir,
}
)

if (process.platform === 'darwin') {
appPort = `http://127.0.0.1:${appPort}`
}
}

beforeAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@ describe('required server files', () => {
let errors = []
let stderr = ''
let requiredFilesManifest
let minimalMode = true
unstubbable marked this conversation as resolved.
Show resolved Hide resolved

const setupNext = async ({
nextEnv,
minimalMode,
}: {
nextEnv?: boolean
minimalMode?: boolean
}) => {
const setupNext = async ({ nextEnv }: { nextEnv?: boolean }) => {
// test build against environment with next support
process.env.NOW_BUILDER = nextEnv ? '1' : ''

Expand Down Expand Up @@ -109,18 +104,31 @@ describe('required server files', () => {
await fs.remove(join(next.testDir, '.next/server', file))
}
}
}

beforeAll(async () => {
await setupNext({ nextEnv: true })
})

beforeEach(async () => {
errors = []
stderr = ''

const testServerFilename = join(next.testDir, 'standalone/server.js')
const testServerContent = await fs.readFile(testServerFilename, 'utf8')

const testServer = join(next.testDir, 'standalone/server.js')
await fs.writeFile(
testServer,
(await fs.readFile(testServer, 'utf8')).replace(
'port:',
`minimalMode: ${minimalMode},port:`
testServerFilename,
testServerContent.replace(
/(startServer\({\s*)(minimalMode: (true|false),\n {2})?/,
`$1minimalMode: ${minimalMode},\n `
)
)

appPort = await findPort()

server = await initNextServerScript(
testServer,
testServerFilename,
/- Local:/,
{
...process.env,
Expand All @@ -136,24 +144,14 @@ describe('required server files', () => {
},
}
)

if (process.platform === 'darwin') {
appPort = `http://127.0.0.1:${appPort}`
}
}

beforeAll(async () => {
await setupNext({ nextEnv: true, minimalMode: true })
})

beforeEach(() => {
errors = []
stderr = ''
afterEach(async () => {
await killApp(server)
})

afterAll(async () => {
await next.destroy()
if (server) await killApp(server)
})

it('should resolve correctly when a redirect is returned', async () => {
Expand Down Expand Up @@ -1279,51 +1277,29 @@ describe('required server files', () => {
expect(envVariables.envFromHost).toBe('FOOBAR')
})

// FIXME: update to not mutate the global state
it('should run middleware correctly (without minimalMode, with wasm)', async () => {
const standaloneDir = join(next.testDir, 'standalone')

const testServer = join(standaloneDir, 'server.js')
await fs.writeFile(
testServer,
(await fs.readFile(testServer, 'utf8')).replace(
'minimalMode: true',
'minimalMode: false'
)
)
appPort = await findPort()
server = await initNextServerScript(
testServer,
/- Local:/,
{
...process.env,
PORT: `${appPort}`,
},
undefined,
{
cwd: next.testDir,
onStderr(msg) {
errors.push(msg)
stderr += msg
},
}
)
describe('without minimalMode, with wasm', () => {
beforeAll(() => {
minimalMode = false
})

const res = await fetchViaHTTP(appPort, '/')
expect(res.status).toBe(200)
expect(await res.text()).toContain('index page')
it('should run middleware correctly', async () => {
const standaloneDir = join(next.testDir, 'standalone')
const res = await fetchViaHTTP(appPort, '/')
expect(res.status).toBe(200)
expect(await res.text()).toContain('index page')

expect(fs.existsSync(join(standaloneDir, '.next/server/edge-chunks'))).toBe(
true
)
expect(
fs.existsSync(join(standaloneDir, '.next/server/edge-chunks'))
).toBe(true)

const resImageResponse = await fetchViaHTTP(
appPort,
'/a-non-existent-page/to-test-with-middleware'
)
const resImageResponse = await fetchViaHTTP(
appPort,
'/a-non-existent-page/to-test-with-middleware'
)

expect(resImageResponse.status).toBe(200)
expect(resImageResponse.headers.get('content-type')).toBe('image/png')
expect(resImageResponse.status).toBe(200)
expect(resImageResponse.headers.get('content-type')).toBe('image/png')
})
})

it('should correctly handle a mismatch in buildIds when normalizing next data', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16054,11 +16054,11 @@
"required server files should resolve correctly when a redirect is returned",
"required server files should return data correctly with x-matched-path",
"required server files should return data correctly with x-matched-path for optional catch-all route",
"required server files should run middleware correctly (without minimalMode, with wasm)",
"required server files should set correct SWR headers with notFound gsp",
"required server files should set correct SWR headers with notFound gssp",
"required server files should show invariant when an automatic static page is requested",
"required server files should warn when \"next\" is imported directly"
"required server files should warn when \"next\" is imported directly",
"required server files without minimalMode, with wasm should run middleware correctly"
],
"pending": [],
"flakey": [],
Expand Down
Loading