2022-12-21 14:16:52 +01:00
|
|
|
import { createNextDescribe } from 'e2e-utils'
|
2022-12-02 03:13:54 +01:00
|
|
|
import fs from 'fs-extra'
|
|
|
|
import os from 'os'
|
|
|
|
import path from 'path'
|
|
|
|
import {
|
|
|
|
findPort,
|
|
|
|
initNextServerScript,
|
|
|
|
killApp,
|
2022-12-19 10:20:01 +01:00
|
|
|
fetchViaHTTP,
|
2022-12-02 03:13:54 +01:00
|
|
|
} from 'next-test-utils'
|
|
|
|
|
2022-12-19 10:20:01 +01:00
|
|
|
if (!(globalThis as any).isNextStart) {
|
|
|
|
it('should skip for non-next start', () => {})
|
|
|
|
} else {
|
|
|
|
createNextDescribe(
|
|
|
|
'output: standalone with app dir',
|
|
|
|
{
|
2022-12-21 14:16:52 +01:00
|
|
|
files: __dirname,
|
2022-12-02 03:13:54 +01:00
|
|
|
skipStart: true,
|
2022-12-19 10:20:01 +01:00
|
|
|
},
|
|
|
|
({ next }) => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await next.patchFile(
|
|
|
|
'next.config.js',
|
|
|
|
(await next.readFile('next.config.js')).replace('// output', 'output')
|
|
|
|
)
|
|
|
|
await next.start()
|
|
|
|
})
|
2022-12-02 03:13:54 +01:00
|
|
|
|
2022-12-19 10:20:01 +01:00
|
|
|
it('should handle trace files correctly for route groups (nodejs only)', async () => {
|
|
|
|
expect(next.cliOutput).not.toContain('Failed to copy traced files')
|
|
|
|
const serverDirPath = path.join(
|
|
|
|
next.testDir,
|
|
|
|
'.next/standalone/.next/server'
|
|
|
|
)
|
|
|
|
for (const page of [
|
|
|
|
'(newroot)/dashboard/another',
|
|
|
|
'(newroot)/dashboard/project/[projectId]',
|
|
|
|
'(rootonly)/dashboard/changelog',
|
|
|
|
]) {
|
|
|
|
const pagePath = path.join(serverDirPath, 'app', page)
|
2022-12-02 03:13:54 +01:00
|
|
|
|
2022-12-19 10:20:01 +01:00
|
|
|
expect(
|
|
|
|
await fs.pathExists(path.join(pagePath, 'page.js.nft.json'))
|
|
|
|
).toBe(true)
|
2022-12-13 04:06:40 +01:00
|
|
|
|
2022-12-19 10:20:01 +01:00
|
|
|
const files = (
|
|
|
|
await fs.readJSON(path.join(pagePath, 'page.js.nft.json'))
|
|
|
|
).files as string[]
|
2022-12-13 04:06:40 +01:00
|
|
|
|
2022-12-19 10:20:01 +01:00
|
|
|
for (const file of files) {
|
|
|
|
expect(await fs.pathExists(path.join(pagePath, file))).toBe(true)
|
|
|
|
}
|
2022-12-13 04:06:40 +01:00
|
|
|
}
|
2022-12-19 10:20:01 +01:00
|
|
|
})
|
2022-12-13 04:06:40 +01:00
|
|
|
|
2022-12-19 10:20:01 +01:00
|
|
|
it('should work correctly with output standalone', async () => {
|
|
|
|
const tmpFolder = path.join(
|
|
|
|
os.tmpdir(),
|
|
|
|
'next-standalone-' + Date.now()
|
|
|
|
)
|
|
|
|
await fs.move(path.join(next.testDir, '.next/standalone'), tmpFolder)
|
|
|
|
let server: any
|
2022-12-02 03:13:54 +01:00
|
|
|
|
2022-12-19 10:20:01 +01:00
|
|
|
try {
|
|
|
|
const testServer = path.join(tmpFolder, 'server.js')
|
|
|
|
const appPort = await findPort()
|
|
|
|
server = await initNextServerScript(
|
|
|
|
testServer,
|
2023-09-05 13:40:00 +02:00
|
|
|
/- Local:/,
|
2022-12-19 10:20:01 +01:00
|
|
|
{
|
|
|
|
...process.env,
|
2023-06-23 19:42:50 +02:00
|
|
|
PORT: appPort.toString(),
|
2022-12-19 10:20:01 +01:00
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
{
|
|
|
|
cwd: tmpFolder,
|
|
|
|
}
|
|
|
|
)
|
2022-12-02 03:13:54 +01:00
|
|
|
|
2022-12-19 10:20:01 +01:00
|
|
|
for (const testPath of [
|
|
|
|
'/',
|
|
|
|
'/api/hello',
|
|
|
|
'/blog/first',
|
|
|
|
'/dashboard',
|
|
|
|
'/dashboard/another',
|
|
|
|
'/dashboard/changelog',
|
|
|
|
'/dashboard/deployments/breakdown',
|
|
|
|
'/dashboard/deployments/123',
|
|
|
|
'/dashboard/hello',
|
|
|
|
'/dashboard/project/123',
|
|
|
|
'/catch-all/first',
|
|
|
|
]) {
|
|
|
|
const res = await fetchViaHTTP(appPort, testPath)
|
|
|
|
expect(res.status).toBe(200)
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (server) await killApp(server)
|
|
|
|
await fs.remove(tmpFolder)
|
|
|
|
}
|
|
|
|
})
|
2022-12-02 03:13:54 +01:00
|
|
|
}
|
2022-12-19 10:20:01 +01:00
|
|
|
)
|
|
|
|
}
|