Skip to content

Commit

Permalink
test tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Oct 30, 2023
1 parent 4c65e96 commit c76040b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 19 deletions.
15 changes: 0 additions & 15 deletions test/e2e/app-dir/app/pages/gsp.js

This file was deleted.

88 changes: 88 additions & 0 deletions test/e2e/app-dir/app/standalone-gsp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { createNextDescribe } from 'e2e-utils'
import fs from 'fs-extra'
import os from 'os'
import path from 'path'
import {
findPort,
initNextServerScript,
killApp,
fetchViaHTTP,
} from 'next-test-utils'

if (!(globalThis as any).isNextStart) {
it('should skip for non-next start', () => {})
} else {
createNextDescribe(
'output: standalone with getStaticProps',
{
files: __dirname,
skipStart: true,
dependencies: {
swr: 'latest',
},
},
({ next }) => {
beforeAll(async () => {
await next.patchFile(
'next.config.js',
(await next.readFile('next.config.js')).replace('// output', 'output')
)

await next.patchFile(
'pages/gsp.js',
`
import useSWR from 'swr'
console.log(useSWR)
export default function Home() {
return <h1>Hello</h1>
}
export async function getStaticProps() {
return {
props: {
foo: "bar",
},
};
}
`
)

await next.start()
})

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

try {
const testServer = path.join(tmpFolder, 'server.js')
const appPort = await findPort()
server = await initNextServerScript(
testServer,
/- Local:/,
{
...process.env,
PORT: appPort.toString(),
},
undefined,
{
cwd: tmpFolder,
}
)

const res = await fetchViaHTTP(appPort, '/gsp')
expect(res.status).toBe(200)
} finally {
if (server) await killApp(server)
await fs.remove(tmpFolder)
}
})
}
)
}
4 changes: 0 additions & 4 deletions test/e2e/app-dir/app/standalone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ if (!(globalThis as any).isNextStart) {
{
files: __dirname,
skipStart: true,
dependencies: {
swr: 'latest',
},
},
({ next }) => {
beforeAll(async () => {
Expand Down Expand Up @@ -93,7 +90,6 @@ if (!(globalThis as any).isNextStart) {
'/dashboard/hello',
'/dashboard/project/123',
'/catch-all/first',
'/gsp',
]) {
const res = await fetchViaHTTP(appPort, testPath)
expect(res.status).toBe(200)
Expand Down

0 comments on commit c76040b

Please sign in to comment.