Skip to content

Commit

Permalink
test: assert that app exited without signal (#74087)
Browse files Browse the repository at this point in the history
we've seen these tests flake with this error:
```
    expect(received).toBe(expected) // Object.is equality

    Expected: 0
    Received: null

      234 |         // App finally shuts down
      235 |         await appKilledPromise
    > 236 |         expect(app.exitCode).toBe(0)
          |                              ^
      237 |       })
      238 |     })
      239 |   }

      at Object.toBe (production/graceful-shutdown/index.test.ts:236:
```
this PR doesn't fix that, but it should make it easier to see why the
code was `null` -- if signal is nonnull, we'll see what it was.

note: `once(app, 'exit')` returns the arguments passed to the `exit`
callback, which are `(code, signal)`
  • Loading branch information
lubieowoce authored Dec 18, 2024
1 parent a216207 commit bfa75ed
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/production/graceful-shutdown/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { once } from 'events'

const appDir = join(__dirname, './src')
let appPort
let app
let app: Awaited<ReturnType<typeof launchApp>>

function assertDefined<T>(value: T | void): asserts value is T {
expect(value).toBeDefined()
Expand Down Expand Up @@ -143,7 +143,7 @@ function runTests(dev = false) {
expect(app.exitCode).toBe(null)

// App finally shuts down
await appKilledPromise
expect(await appKilledPromise).toEqual([0, null])
expect(app.exitCode).toBe(0)
})
} else {
Expand Down Expand Up @@ -180,7 +180,7 @@ function runTests(dev = false) {
expect(responseResolved).toBe(true)

// App finally shuts down
await appKilledPromise
expect(await appKilledPromise).toEqual([0, null])
expect(app.exitCode).toBe(0)
})

Expand Down Expand Up @@ -215,7 +215,7 @@ function runTests(dev = false) {
expect(app.exitCode).toBe(null)

// App finally shuts down
await appKilledPromise
expect(await appKilledPromise).toEqual([0, null])
expect(app.exitCode).toBe(0)
})

Expand All @@ -232,7 +232,7 @@ function runTests(dev = false) {
).rejects.toThrow()

// App finally shuts down
await appKilledPromise
expect(await appKilledPromise).toEqual([0, null])
expect(app.exitCode).toBe(0)
})
})
Expand Down

0 comments on commit bfa75ed

Please sign in to comment.