Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion __tests__/server/stores.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,17 @@ describe('the server with stores', () => {
const port = 21000 + Math.floor(Math.random() * 1000)
const { passthrough } = await import('msw')
server.use(http.all(`http://127.0.0.1:${port}/*`, () => passthrough()))
server.use(http.post(`${api}/app/installations/7/access_tokens`, () => new Promise(() => {})))
// @octokit/auth-app shares one pending-request map per installation across every
// createAppAuth in the process, so a token request this test never answered would
// hang the next test of this file that mints a token for installation 7
let abandonToken!: () => void
const tokenHeld = new Promise<void>((resolve) => {
abandonToken = resolve
})
server.use(http.post(`${api}/app/installations/7/access_tokens`, async () => {
await tokenHeld
return new Response('abandoned by the test', { status: 500 })
}))
const listening = main({ ...env, PORT: String(port), PROW_SHUTDOWN_GRACE_MS: '30' }, signals)
try {
await listening.ready
Expand All @@ -234,6 +244,9 @@ describe('the server with stores', () => {
await vi.waitFor(() => expect(exit).toHaveBeenCalledWith(0))
}
finally {
abandonToken()
await vi.waitFor(() => expect(write.mock.calls.map(call => JSON.parse(String(call[0])) as { level: string })).toContainEqual(expect.objectContaining({ level: 'error' })))
await listening.close(0)
write.mockRestore()
}
})
Expand Down
12 changes: 11 additions & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ range of its own, is counted correctly.
Vitest runs the tests of a file in source order, so a test that leaves state
behind is only noticed by the tests that happen to follow it. `npm run
test:shuffle` runs every file's tests in a random order (the seed is printed
with the failure; `--sequence.seed=<n>` repeats it). The three ways a test has
with the failure; `--sequence.seed=<n>` repeats it). The four ways a test has
leaked into its neighbour here, and how each file now avoids them:

- **A mutated fixture.** The JSON fixtures are imported once per file, so
Expand All @@ -151,6 +151,16 @@ leaked into its neighbour here, and how each file now avoids them:
`utils.newRun()`. A file that uses `vi.resetModules()` must import
`@actions/core` and the module under test fresh together, or the assertion
spies on a different `core` instance than the one the module warns through.
- **An installation-token request that never settles.** `@octokit/auth-app`
deduplicates concurrent token requests for one installation in a map that is
shared by every `createAppAuth` in the process, not one per App. An msw
handler for `POST /app/installations/{id}/access_tokens` that returns a
promise which never resolves therefore parks every later mint for that
installation in the same file, however many receivers the tests build — the
next test that mints a token hangs until its timeout without issuing a
request. Hold the handler on a promise the test settles in its `finally`
(a 500 ends the delivery with no further requests), and wait for the parked
delivery's failure line before restoring the spies it logs through.

### Mutation checks

Expand Down
Loading