diff --git a/__tests__/cronJobTest/handleCronJob.test.ts b/__tests__/cronJobTest/handleCronJob.test.ts index f9cb310f..41e7c4d7 100644 --- a/__tests__/cronJobTest/handleCronJob.test.ts +++ b/__tests__/cronJobTest/handleCronJob.test.ts @@ -11,9 +11,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/cronJobTest/labelSync.test.ts b/__tests__/cronJobTest/labelSync.test.ts index 25d251e9..d1039347 100644 --- a/__tests__/cronJobTest/labelSync.test.ts +++ b/__tests__/cronJobTest/labelSync.test.ts @@ -18,9 +18,7 @@ vi.mock('../../src/utils/octokit', { spy: true }) const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/cronJobTest/lgtm.test.ts b/__tests__/cronJobTest/lgtm.test.ts index b488556e..5531afa3 100644 --- a/__tests__/cronJobTest/lgtm.test.ts +++ b/__tests__/cronJobTest/lgtm.test.ts @@ -62,9 +62,7 @@ const server = setupServer( ), ) beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/cronJobTest/sweep.test.ts b/__tests__/cronJobTest/sweep.test.ts index 85f9aea4..37a24b2c 100644 --- a/__tests__/cronJobTest/sweep.test.ts +++ b/__tests__/cronJobTest/sweep.test.ts @@ -14,7 +14,7 @@ import * as utils from '../testUtils' import { blobSha } from '../utils/ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issueCommentTest/approve.test.ts b/__tests__/issueCommentTest/approve.test.ts index 2905bb7e..890be7a9 100644 --- a/__tests__/issueCommentTest/approve.test.ts +++ b/__tests__/issueCommentTest/approve.test.ts @@ -16,9 +16,7 @@ import { baseBranch, blobSha, changedFiles, filesHandler, prCommentEvent, prHand const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) // a label command is followed by the needs-* re-check and the merge gate: no prow.yaml in any tier, no OWNERS files beforeEach(() => server.use(...utils.noOrgOrRepoConfigExcept(), utils.defaultBranchTree())) diff --git a/__tests__/issueCommentTest/approveMilestoneErrorPaths.test.ts b/__tests__/issueCommentTest/approveMilestoneErrorPaths.test.ts index a56db080..7bcc285f 100644 --- a/__tests__/issueCommentTest/approveMilestoneErrorPaths.test.ts +++ b/__tests__/issueCommentTest/approveMilestoneErrorPaths.test.ts @@ -17,9 +17,7 @@ vi.mock('../../src/utils/auth', { spy: true }) const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issueCommentTest/assign.test.ts b/__tests__/issueCommentTest/assign.test.ts index ff73e3e2..60966d53 100644 --- a/__tests__/issueCommentTest/assign.test.ts +++ b/__tests__/issueCommentTest/assign.test.ts @@ -12,9 +12,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) @@ -165,9 +163,9 @@ describe('/assign', () => { await handleIssueComment(commentContext) await observeReq.called() - expect(await observeReq.body()).toMatchObject({ - assignees: ['some-user', 'other-user'], - }) + // getOrgCollabCommentUsers collects users as their auth checks settle, so + // the order of assignees is not fixed + expect((await observeReq.body()).assignees.sort()).toEqual(['other-user', 'some-user']) }) it('assigns users from every /assign line in the comment', async () => { @@ -209,9 +207,7 @@ describe('/assign', () => { const setFailed = vi.spyOn(core, 'setFailed').mockImplementation(() => {}) await handleIssueComment(commentContext) await observeReq.called() - expect(await observeReq.body()).toEqual({ - assignees: ['some-user', 'other-user'], - }) + expect((await observeReq.body()).assignees.sort()).toEqual(['other-user', 'some-user']) expect(setFailed).not.toHaveBeenCalled() }) diff --git a/__tests__/issueCommentTest/cc.test.ts b/__tests__/issueCommentTest/cc.test.ts index 4178c7c2..2ce0f73b 100644 --- a/__tests__/issueCommentTest/cc.test.ts +++ b/__tests__/issueCommentTest/cc.test.ts @@ -12,9 +12,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) @@ -158,9 +156,9 @@ describe('/cc', () => { await handleIssueComment(commentContext) await observeReq.called() - expect(await observeReq.body()).toMatchObject({ - reviewers: ['some-user', 'other-user'], - }) + // getOrgCollabCommentUsers collects users as their auth checks settle, so + // the order of reviewers is not fixed + expect((await observeReq.body()).reviewers.sort()).toEqual(['other-user', 'some-user']) }) it('ccs user if they are an org member', async () => { diff --git a/__tests__/issueCommentTest/close.test.ts b/__tests__/issueCommentTest/close.test.ts index 7cedd484..63db8984 100644 --- a/__tests__/issueCommentTest/close.test.ts +++ b/__tests__/issueCommentTest/close.test.ts @@ -11,9 +11,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issueCommentTest/errorPaths.test.ts b/__tests__/issueCommentTest/errorPaths.test.ts index 41d9de62..1991f33b 100644 --- a/__tests__/issueCommentTest/errorPaths.test.ts +++ b/__tests__/issueCommentTest/errorPaths.test.ts @@ -21,9 +21,7 @@ vi.mock('../../src/utils/auth', { spy: true }) const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issueCommentTest/handleIssueComment.test.ts b/__tests__/issueCommentTest/handleIssueComment.test.ts index 193a0588..db0f1984 100644 --- a/__tests__/issueCommentTest/handleIssueComment.test.ts +++ b/__tests__/issueCommentTest/handleIssueComment.test.ts @@ -22,7 +22,7 @@ import * as utils from '../testUtils' import { prCommentEvent, prHandlers, pullHandler, repo } from '../utils/ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) // the dispatch tests below mock every command; the sweep that follows a command is stubbed the same way let sweepStubs: ReturnType[] diff --git a/__tests__/issueCommentTest/lock.test.ts b/__tests__/issueCommentTest/lock.test.ts index d92f32f3..52d29290 100644 --- a/__tests__/issueCommentTest/lock.test.ts +++ b/__tests__/issueCommentTest/lock.test.ts @@ -11,9 +11,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issueCommentTest/meow.test.ts b/__tests__/issueCommentTest/meow.test.ts index ef758e40..4c6ce634 100644 --- a/__tests__/issueCommentTest/meow.test.ts +++ b/__tests__/issueCommentTest/meow.test.ts @@ -13,7 +13,7 @@ import * as utils from '../testUtils' const catApi = 'https://api.thecatapi.com/v1/images/search' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) @@ -380,7 +380,7 @@ describe('/meow', () => { it('does not follow a redirect or forward the key', async () => { process.env['INPUT_CAT-API-KEY'] = 'secret-key' - // the redirect target is intentionally not mocked: onUnhandledRequest error + // the redirect target is intentionally not mocked: failOnUnhandledRequest // fails the test if the request is ever followed there server.use( http.get(catApi, () => diff --git a/__tests__/issueCommentTest/milestone.test.ts b/__tests__/issueCommentTest/milestone.test.ts index 1ee589bd..640f9692 100644 --- a/__tests__/issueCommentTest/milestone.test.ts +++ b/__tests__/issueCommentTest/milestone.test.ts @@ -12,9 +12,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issueCommentTest/reopen.test.ts b/__tests__/issueCommentTest/reopen.test.ts index 25e9bfc9..20099260 100644 --- a/__tests__/issueCommentTest/reopen.test.ts +++ b/__tests__/issueCommentTest/reopen.test.ts @@ -11,9 +11,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issueCommentTest/retitle.test.ts b/__tests__/issueCommentTest/retitle.test.ts index 879ec64e..b2264ea2 100644 --- a/__tests__/issueCommentTest/retitle.test.ts +++ b/__tests__/issueCommentTest/retitle.test.ts @@ -11,9 +11,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issueCommentTest/trigger.test.ts b/__tests__/issueCommentTest/trigger.test.ts index 938c8ee7..2379150c 100644 --- a/__tests__/issueCommentTest/trigger.test.ts +++ b/__tests__/issueCommentTest/trigger.test.ts @@ -14,7 +14,7 @@ import * as utils from '../testUtils' import { prCommentEvent, prHandlers, repo } from '../utils/ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => { server.resetHandlers() server.events.removeAllListeners() diff --git a/__tests__/issueCommentTest/unassign.test.ts b/__tests__/issueCommentTest/unassign.test.ts index 08119b95..52d4cf4f 100644 --- a/__tests__/issueCommentTest/unassign.test.ts +++ b/__tests__/issueCommentTest/unassign.test.ts @@ -12,9 +12,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issueCommentTest/uncc.test.ts b/__tests__/issueCommentTest/uncc.test.ts index 90934564..42d9356e 100644 --- a/__tests__/issueCommentTest/uncc.test.ts +++ b/__tests__/issueCommentTest/uncc.test.ts @@ -11,9 +11,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/issuesTest/handleIssues.test.ts b/__tests__/issuesTest/handleIssues.test.ts index 2418e4b6..1919e2a9 100644 --- a/__tests__/issuesTest/handleIssues.test.ts +++ b/__tests__/issuesTest/handleIssues.test.ts @@ -9,9 +9,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/area.test.ts b/__tests__/label/area.test.ts index c55720bf..90a68356 100644 --- a/__tests__/label/area.test.ts +++ b/__tests__/label/area.test.ts @@ -12,9 +12,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/dynamic.test.ts b/__tests__/label/dynamic.test.ts index 81cbce3c..e2cca0c1 100644 --- a/__tests__/label/dynamic.test.ts +++ b/__tests__/label/dynamic.test.ts @@ -12,9 +12,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/errorPaths.test.ts b/__tests__/label/errorPaths.test.ts index c62ad931..531c67a2 100644 --- a/__tests__/label/errorPaths.test.ts +++ b/__tests__/label/errorPaths.test.ts @@ -20,9 +20,7 @@ vi.mock('../../src/utils/auth', { spy: true }) const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/help.test.ts b/__tests__/label/help.test.ts index c519595c..1cd9defe 100644 --- a/__tests__/label/help.test.ts +++ b/__tests__/label/help.test.ts @@ -11,9 +11,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) // a label command is followed by the needs-* re-check and the merge gate: no prow.yaml in any tier, no OWNERS files beforeEach(() => server.use(...utils.noOrgOrRepoConfigExcept(), utils.defaultBranchTree())) diff --git a/__tests__/label/hold.test.ts b/__tests__/label/hold.test.ts index 5c5c7f3e..ff3e0624 100644 --- a/__tests__/label/hold.test.ts +++ b/__tests__/label/hold.test.ts @@ -13,9 +13,7 @@ import * as utils from '../testUtils' const server = setupServer(...utils.noOrgOrRepoConfigExcept()) beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/kind.test.ts b/__tests__/label/kind.test.ts index 309787e3..58a7148c 100644 --- a/__tests__/label/kind.test.ts +++ b/__tests__/label/kind.test.ts @@ -12,9 +12,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/label.test.ts b/__tests__/label/label.test.ts index 5421cb78..6b50a39c 100644 --- a/__tests__/label/label.test.ts +++ b/__tests__/label/label.test.ts @@ -14,9 +14,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/lgtm.test.ts b/__tests__/label/lgtm.test.ts index e9c2f92c..80a460a5 100644 --- a/__tests__/label/lgtm.test.ts +++ b/__tests__/label/lgtm.test.ts @@ -22,9 +22,7 @@ vi.mock('../../src/plugins/lgtmBinding', { spy: true }) const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) // a label command is followed by the needs-* re-check and the merge gate: no prow.yaml in any tier, no OWNERS files beforeEach(() => server.use(...utils.noOrgOrRepoConfigExcept(), utils.defaultBranchTree())) diff --git a/__tests__/label/lifecycle.test.ts b/__tests__/label/lifecycle.test.ts index b310823e..abc4d706 100644 --- a/__tests__/label/lifecycle.test.ts +++ b/__tests__/label/lifecycle.test.ts @@ -13,9 +13,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/prefixed.test.ts b/__tests__/label/prefixed.test.ts index ef755502..4d3b5046 100644 --- a/__tests__/label/prefixed.test.ts +++ b/__tests__/label/prefixed.test.ts @@ -8,7 +8,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/priority.test.ts b/__tests__/label/priority.test.ts index 88363b0b..2ad69935 100644 --- a/__tests__/label/priority.test.ts +++ b/__tests__/label/priority.test.ts @@ -12,9 +12,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/label/remove.test.ts b/__tests__/label/remove.test.ts index b5d1cb4e..dfcb3ec5 100644 --- a/__tests__/label/remove.test.ts +++ b/__tests__/label/remove.test.ts @@ -11,9 +11,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) // a label command is followed by the needs-* re-check and the merge gate: no prow.yaml in any tier, no OWNERS files beforeEach(() => server.use(...utils.noOrgOrRepoConfigExcept(), utils.defaultBranchTree())) diff --git a/__tests__/plugins/approveErrorPaths.test.ts b/__tests__/plugins/approveErrorPaths.test.ts index 00620736..a9438694 100644 --- a/__tests__/plugins/approveErrorPaths.test.ts +++ b/__tests__/plugins/approveErrorPaths.test.ts @@ -13,7 +13,7 @@ import * as utils from '../testUtils' import { prHandlers, repo } from '../utils/ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/plugins/approveEvents.test.ts b/__tests__/plugins/approveEvents.test.ts index 7066828b..63354e89 100644 --- a/__tests__/plugins/approveEvents.test.ts +++ b/__tests__/plugins/approveEvents.test.ts @@ -14,7 +14,7 @@ import * as utils from '../testUtils' import { prHandlers, repo } from '../utils/ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/plugins/blunderbuss.test.ts b/__tests__/plugins/blunderbuss.test.ts index 485d2b58..7a659513 100644 --- a/__tests__/plugins/blunderbuss.test.ts +++ b/__tests__/plugins/blunderbuss.test.ts @@ -15,7 +15,7 @@ import * as utils from '../testUtils' import { baseSha, changedFiles, filesHandler, prCommentEvent, repo, treeHandlers } from '../utils/ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/plugins/lgtmBinding.test.ts b/__tests__/plugins/lgtmBinding.test.ts index 39bd347f..55668610 100644 --- a/__tests__/plugins/lgtmBinding.test.ts +++ b/__tests__/plugins/lgtmBinding.test.ts @@ -12,7 +12,7 @@ import pullReqOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json' import * as utils from '../testUtils' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/plugins/ownersLabel.test.ts b/__tests__/plugins/ownersLabel.test.ts index cc4e2ab5..cf83d6c2 100644 --- a/__tests__/plugins/ownersLabel.test.ts +++ b/__tests__/plugins/ownersLabel.test.ts @@ -10,7 +10,7 @@ import * as utils from '../testUtils' import { baseSha, changedFiles, filesHandler, prHandlers, pullHandler, repo, treeHandlers } from '../utils/ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/plugins/pluginErrorPaths.test.ts b/__tests__/plugins/pluginErrorPaths.test.ts index 38618b96..5b395c5a 100644 --- a/__tests__/plugins/pluginErrorPaths.test.ts +++ b/__tests__/plugins/pluginErrorPaths.test.ts @@ -13,7 +13,7 @@ import * as utils from '../testUtils' import { prHandlers } from '../utils/ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) beforeEach(() => utils.setupActionsEnv()) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/plugins/requireMatchingLabel.test.ts b/__tests__/plugins/requireMatchingLabel.test.ts index 701c9214..cc012e58 100644 --- a/__tests__/plugins/requireMatchingLabel.test.ts +++ b/__tests__/plugins/requireMatchingLabel.test.ts @@ -18,7 +18,7 @@ import * as utils from '../testUtils' import { pullHandler } from '../utils/ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/plugins/tide.test.ts b/__tests__/plugins/tide.test.ts index 402e45eb..6aad78a3 100644 --- a/__tests__/plugins/tide.test.ts +++ b/__tests__/plugins/tide.test.ts @@ -18,9 +18,7 @@ import { prCommentEvent } from '../utils/ownersFixtures' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/plugins/tideMergeQueue.test.ts b/__tests__/plugins/tideMergeQueue.test.ts index 39e9194c..1e6b5d89 100644 --- a/__tests__/plugins/tideMergeQueue.test.ts +++ b/__tests__/plugins/tideMergeQueue.test.ts @@ -11,7 +11,7 @@ import pullReqOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json' import * as utils from '../testUtils' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/pullReqTest/handleCheckSuite.test.ts b/__tests__/pullReqTest/handleCheckSuite.test.ts index 653ea84c..5ca9cbb6 100644 --- a/__tests__/pullReqTest/handleCheckSuite.test.ts +++ b/__tests__/pullReqTest/handleCheckSuite.test.ts @@ -11,9 +11,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) const registeredHandlers = [...checkSuiteHandlers] beforeEach(() => { diff --git a/__tests__/pullReqTest/handlePullReq.test.ts b/__tests__/pullReqTest/handlePullReq.test.ts index 6ea99198..d7b72cc9 100644 --- a/__tests__/pullReqTest/handlePullReq.test.ts +++ b/__tests__/pullReqTest/handlePullReq.test.ts @@ -18,9 +18,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) const registeredHandlers = [...pullRequestHandlers] beforeEach(() => { diff --git a/__tests__/pullReqTest/handlePullReqReview.test.ts b/__tests__/pullReqTest/handlePullReqReview.test.ts index a98b1332..f78bf1e9 100644 --- a/__tests__/pullReqTest/handlePullReqReview.test.ts +++ b/__tests__/pullReqTest/handlePullReqReview.test.ts @@ -10,9 +10,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) const registeredHandlers = [...pullRequestReviewHandlers] beforeEach(() => { diff --git a/__tests__/pullReqTest/onPrLgtm.test.ts b/__tests__/pullReqTest/onPrLgtm.test.ts index 238fe4c6..6bdb08e2 100644 --- a/__tests__/pullReqTest/onPrLgtm.test.ts +++ b/__tests__/pullReqTest/onPrLgtm.test.ts @@ -15,9 +15,7 @@ const pullReqEvent = { ...pullReqOpenedEvent, action: 'synchronize' } const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/pullReqTest/readOnlyFork.test.ts b/__tests__/pullReqTest/readOnlyFork.test.ts index 1718819d..b1a8c849 100644 --- a/__tests__/pullReqTest/readOnlyFork.test.ts +++ b/__tests__/pullReqTest/readOnlyFork.test.ts @@ -11,7 +11,7 @@ import * as utils from '../testUtils' // no handler is served: any api call is an unhandled request and fails the test const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) const fork = 'octocat/Hello-World' const same = pullReqOpenedEvent.repository.full_name diff --git a/__tests__/testUtils.ts b/__tests__/testUtils.ts index 4e70c616..7b808ffc 100644 --- a/__tests__/testUtils.ts +++ b/__tests__/testUtils.ts @@ -13,6 +13,14 @@ type WebhookPayload = Context['payload'] export const api = 'https://api.github.com' +/** + * failOnUnhandledRequest makes `server.listen` reject any request no handler + * answers instead of passing it through to the network. msw 2 reads + * `onUnhandledRequest`, msw 3 reads `onUnhandledFrame`; naming both keeps the + * suite offline on either version. + */ +export const failOnUnhandledRequest = { onUnhandledRequest: 'error', onUnhandledFrame: 'error' } as const + /** every file the prow configuration loader probes for Codertocat/Hello-World, as `owner/repo:path` */ export const configProbes = [ 'Codertocat/.project:prow.yaml', diff --git a/__tests__/utils/auth.test.ts b/__tests__/utils/auth.test.ts index cdffa845..4da104ba 100644 --- a/__tests__/utils/auth.test.ts +++ b/__tests__/utils/auth.test.ts @@ -22,9 +22,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => { utils.setupActionsEnv() - server.listen({ - onUnhandledRequest: 'error', - }) + server.listen(utils.failOnUnhandledRequest) }) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/utils/comments.test.ts b/__tests__/utils/comments.test.ts index c56009d3..d17f6706 100644 --- a/__tests__/utils/comments.test.ts +++ b/__tests__/utils/comments.test.ts @@ -8,7 +8,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/utils/configLoader.test.ts b/__tests__/utils/configLoader.test.ts index ac0c340a..5ebe6d6e 100644 --- a/__tests__/utils/configLoader.test.ts +++ b/__tests__/utils/configLoader.test.ts @@ -13,7 +13,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) @@ -66,14 +66,19 @@ describe('loadProwConfig', () => { }) it('fails closed when an org repo answers with something other than 404', async () => { + // the repo tier is probed in parallel with the org tier; answer its first + // probe so none of its requests outlive this test and reach the next one + const repo = new utils.ObserveRequest() + serve('.github/prow.yaml', 'labels:\n kind: [repo]\n', repo) server.use( http.get(utils.contentsUrl(project), utils.mockResponse(500, { message: 'boom' })), - ...utils.noOrgOrRepoConfigExcept(project), + ...utils.noOrgOrRepoConfigExcept(project, '.github/prow.yaml'), ) await expect(loadProwConfig(octokit, context)).rejects.toThrow( 'could not load organization prow config from Codertocat/.project:prow.yaml:', ) + await repo.called() }) }) @@ -279,7 +284,8 @@ describe('loadProwConfig', () => { ) await expect(loadProwConfig(octokit, context)).rejects.toThrow( - 'could not load prow config from https://config.example.com/prow.yaml: TypeError: Failed to fetch', + // msw 2 surfaces HttpResponse.error() as "Failed to fetch", msw 3 as undici's "fetch failed" + /^could not load prow config from https:\/\/config\.example\.com\/prow\.yaml: TypeError: (?:Failed to fetch|fetch failed)$/, ) }) diff --git a/__tests__/utils/labeling.test.ts b/__tests__/utils/labeling.test.ts index 63bb0100..0e13324f 100644 --- a/__tests__/utils/labeling.test.ts +++ b/__tests__/utils/labeling.test.ts @@ -17,9 +17,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => - server.listen({ - onUnhandledRequest: 'error', - }), + server.listen(utils.failOnUnhandledRequest), ) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/utils/mergeQueue.test.ts b/__tests__/utils/mergeQueue.test.ts index 6de06735..4c741fa4 100644 --- a/__tests__/utils/mergeQueue.test.ts +++ b/__tests__/utils/mergeQueue.test.ts @@ -21,7 +21,7 @@ import * as utils from '../testUtils' const server = setupServer() beforeAll(() => { utils.setupActionsEnv() - server.listen({ onUnhandledRequest: 'error' }) + server.listen(utils.failOnUnhandledRequest) }) beforeEach(() => resetMergeQueueWarnings()) afterEach(() => server.resetHandlers()) diff --git a/__tests__/utils/ownersAuth.test.ts b/__tests__/utils/ownersAuth.test.ts index 48fc7478..eac0ff8f 100644 --- a/__tests__/utils/ownersAuth.test.ts +++ b/__tests__/utils/ownersAuth.test.ts @@ -24,9 +24,7 @@ import { const server = setupServer() beforeAll(() => { utils.setupActionsEnv() - server.listen({ - onUnhandledRequest: 'error', - }) + server.listen(utils.failOnUnhandledRequest) }) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/utils/pullRequestOwners.test.ts b/__tests__/utils/pullRequestOwners.test.ts index dccad81a..e3a7f77b 100644 --- a/__tests__/utils/pullRequestOwners.test.ts +++ b/__tests__/utils/pullRequestOwners.test.ts @@ -21,7 +21,7 @@ import { } from './ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) beforeEach(() => utils.setupActionsEnv()) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/utils/repoHasOwners.test.ts b/__tests__/utils/repoHasOwners.test.ts index c4ecf4ea..b4bc482a 100644 --- a/__tests__/utils/repoHasOwners.test.ts +++ b/__tests__/utils/repoHasOwners.test.ts @@ -10,7 +10,7 @@ import * as utils from '../testUtils' import { contentsResponse, repo } from './ownersFixtures' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/utils/utilsErrorPaths.test.ts b/__tests__/utils/utilsErrorPaths.test.ts index b8039909..33316c0a 100644 --- a/__tests__/utils/utilsErrorPaths.test.ts +++ b/__tests__/utils/utilsErrorPaths.test.ts @@ -15,7 +15,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() -beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) @@ -157,7 +157,8 @@ describe('utils error paths', () => { ) await expect(loadProwConfig(octokit, context)).rejects.toThrow( - 'could not load prow config from https://config.example.com/prow.yaml: TypeError: Failed to fetch', + // msw 2 surfaces HttpResponse.error() as "Failed to fetch", msw 3 as undici's "fetch failed" + /^could not load prow config from https:\/\/config\.example\.com\/prow\.yaml: TypeError: (?:Failed to fetch|fetch failed)$/, ) })