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

Function runTests

test/integration/api-support/test/index.test.ts:28–645  ·  view source on GitHub ↗
(dev = false)

Source from the content-addressed store, hash-verified

26let app
27
28function runTests(dev = false) {
29 beforeAll(() => {
30 // isNextDev is used for getDistDir, where it is used for reading the build manifest files.
31 global.isNextDev = dev
32 })
33 afterAll(() => {
34 global.isNextDev = originalIsNextDev
35 })
36
37 it('should not strip .json from API route', async () => {
38 const res = await fetchViaHTTP(appPort, '/api/hello.json')
39 expect(res.status).toBe(200)
40 expect(await res.json()).toEqual({ post: 'hello.json' })
41 })
42
43 it('should handle proxying to self correctly', async () => {
44 const res1 = await fetchViaHTTP(appPort, '/api/proxy-self')
45 expect(res1.status).toBe(200)
46 expect(await res1.text()).toContain('User')
47
48 const buildId = dev
49 ? 'development'
50 : await fs.readFile(join(appDir, '.next', 'BUILD_ID'), 'utf8')
51
52 const res2 = await fetchViaHTTP(
53 appPort,
54 `/api/proxy-self?buildId=${buildId}`
55 )
56 expect(res2.status).toBe(200)
57 expect(await res2.text()).toContain('__SSG_MANIFEST')
58 })
59
60 it('should respond from /api/auth/[...nextauth] correctly', async () => {
61 const res = await fetchViaHTTP(appPort, '/api/auth/signin', undefined, {
62 redirect: 'manual',
63 })
64 expect(res.status).toBe(200)
65 expect(await res.json()).toEqual({ from: 'auth' })
66 })
67
68 it('should handle 204 status correctly', async () => {
69 const res = await fetchViaHTTP(appPort, '/api/status-204', undefined, {
70 redirect: 'manual',
71 })
72 expect(res.status).toBe(204)
73 expect(res.headers.get('content-type')).toBe(null)
74 expect(res.headers.get('content-length')).toBe(null)
75 expect(res.headers.get('transfer-encoding')).toBe(null)
76
77 const stderrIdx = stderr.length
78 const res2 = await fetchViaHTTP(
79 appPort,
80 '/api/status-204',
81 { invalid: '1' },
82 {
83 redirect: 'manual',
84 }
85 )

Callers 1

index.test.tsFile · 0.70

Calls 15

abortMethod · 0.95
writeMethod · 0.95
deleteMethod · 0.95
fetchViaHTTPFunction · 0.90
joinFunction · 0.90
checkFunction · 0.90
renderViaHTTPFunction · 0.90
nextBuildFunction · 0.90
encodeURIComponentFunction · 0.85
thenMethod · 0.80

Tested by

no test coverage detected