({
cwd,
projectName,
isApp = true,
isApi = false,
isEmpty = false,
}: {
cwd: string
projectName: string
isApp?: boolean
isApi?: boolean
isEmpty?: boolean
})
| 43 | }) |
| 44 | |
| 45 | export async function tryNextDev({ |
| 46 | cwd, |
| 47 | projectName, |
| 48 | isApp = true, |
| 49 | isApi = false, |
| 50 | isEmpty = false, |
| 51 | }: { |
| 52 | cwd: string |
| 53 | projectName: string |
| 54 | isApp?: boolean |
| 55 | isApi?: boolean |
| 56 | isEmpty?: boolean |
| 57 | }) { |
| 58 | const dir = join(cwd, projectName) |
| 59 | const port = await findPort() |
| 60 | const app = await launchApp(dir, port, { |
| 61 | nextBin: join(dir, 'node_modules/next/dist/bin/next'), |
| 62 | }) |
| 63 | |
| 64 | try { |
| 65 | const res = await fetchViaHTTP(port, '/') |
| 66 | if (isEmpty || isApi) { |
| 67 | expect(await res.text()).toContain('Hello world!') |
| 68 | } else { |
| 69 | const responseText = await res.text() |
| 70 | // App Router uses page.tsx/page.js, Pages Router uses index.tsx/index.js |
| 71 | const hasAppRouterText = |
| 72 | responseText.includes('To get started, edit the page.tsx file.') || |
| 73 | responseText.includes('To get started, edit the page.js file.') |
| 74 | const hasPagesRouterText = |
| 75 | responseText.includes('To get started, edit the index.tsx file.') || |
| 76 | responseText.includes('To get started, edit the index.js file.') |
| 77 | expect(hasAppRouterText || hasPagesRouterText).toBe(true) |
| 78 | } |
| 79 | expect(res.status).toBe(200) |
| 80 | |
| 81 | if (!isApp && !isEmpty) { |
| 82 | const apiRes = await fetchViaHTTP(port, '/api/hello') |
| 83 | expect(await apiRes.json()).toEqual({ name: 'John Doe' }) |
| 84 | expect(apiRes.status).toBe(200) |
| 85 | } |
| 86 | } finally { |
| 87 | await killApp(app) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | export { |
| 92 | createNextApp, |
no test coverage detected
searching dependent graphs…