(dev = false)
| 119 | }) |
| 120 | |
| 121 | function runTests(dev = false) { |
| 122 | if (dev) { |
| 123 | it('should shut down child immediately', async () => { |
| 124 | const appKilledPromise = once(app, 'exit') |
| 125 | |
| 126 | // let the dev server compile the route before running the test |
| 127 | await expect( |
| 128 | fetchViaHTTP(appPort, '/api/long-running') |
| 129 | ).resolves.toBeDefined() |
| 130 | |
| 131 | const resPromise = fetchViaHTTP(appPort, '/api/long-running') |
| 132 | |
| 133 | // yield event loop to kick off request before killing the app |
| 134 | await waitFor(20) |
| 135 | process.kill(app.pid, 'SIGTERM') |
| 136 | expect(app.exitCode).toBe(null) |
| 137 | |
| 138 | // `next dev` should kill the child immediately |
| 139 | let start = Date.now() |
| 140 | await expect(resPromise).rejects.toThrow() |
| 141 | expect(Date.now() - start).toBeLessThan(LONG_RUNNING_MS) |
| 142 | |
| 143 | // `next dev` parent process is still running cleanup |
| 144 | expect(app.exitCode).toBe(null) |
| 145 | |
| 146 | // App finally shuts down |
| 147 | expect(await appKilledPromise).toEqual([0, null]) |
| 148 | expect(app.exitCode).toBe(0) |
| 149 | }) |
| 150 | } else { |
| 151 | // TODO: investigate this is constantly failing |
| 152 | it.skip('should wait for requests to complete before exiting', async () => { |
| 153 | const appKilledPromise = once(app, 'exit') |
| 154 | |
| 155 | let responseResolved = false |
| 156 | const resPromise = fetchViaHTTP(appPort, '/api/long-running') |
| 157 | .then((res) => { |
| 158 | responseResolved = true |
| 159 | return res |
| 160 | }) |
| 161 | .catch(() => {}) |
| 162 | |
| 163 | // yield event loop to kick off request before killing the app |
| 164 | await waitFor(20) |
| 165 | process.kill(app.pid, 'SIGTERM') |
| 166 | expect(app.exitCode).toBe(null) |
| 167 | |
| 168 | // Long running response should still be running after a bit |
| 169 | await waitFor(LONG_RUNNING_MS / 2) |
| 170 | expect(app.exitCode).toBe(null) |
| 171 | expect(responseResolved).toBe(false) |
| 172 | |
| 173 | // App responds as expected without being interrupted |
| 174 | const res = await resPromise |
| 175 | assertDefined(res) |
| 176 | expect(res.status).toBe(200) |
| 177 | expect(await res.json()).toStrictEqual({ hello: 'world' }) |
| 178 |
no test coverage detected