(dev = false)
| 26 | let app |
| 27 | |
| 28 | function 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 | ) |
no test coverage detected