MCPcopy
hub / github.com/vercel/next.js / tryNextDev

Function tryNextDev

test/integration/create-next-app/utils.ts:45–89  ·  view source on GitHub ↗
({
  cwd,
  projectName,
  isApp = true,
  isApi = false,
  isEmpty = false,
}: {
  cwd: string
  projectName: string
  isApp?: boolean
  isApi?: boolean
  isEmpty?: boolean
})

Source from the content-addressed store, hash-verified

43 })
44
45export 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
91export {
92 createNextApp,

Callers 4

app.test.tsFile · 0.90
app-api.test.tsFile · 0.90
pages.test.tsFile · 0.90
matrix.test.tsFile · 0.90

Calls 9

joinFunction · 0.90
findPortFunction · 0.90
launchAppFunction · 0.90
fetchViaHTTPFunction · 0.90
killAppFunction · 0.90
includesMethod · 0.80
textMethod · 0.65
expectFunction · 0.50
jsonMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…