diff --git a/__tests__/cronJobTest/handleCronJob.test.ts b/__tests__/cronJobTest/handleCronJob.test.ts index 41e7c4d..ac0c1b2 100644 --- a/__tests__/cronJobTest/handleCronJob.test.ts +++ b/__tests__/cronJobTest/handleCronJob.test.ts @@ -9,7 +9,8 @@ import pullReqOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json' import * as utils from '../testUtils' -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/cronJobTest/labelSync.test.ts b/__tests__/cronJobTest/labelSync.test.ts index 8d4ade7..5508e64 100644 --- a/__tests__/cronJobTest/labelSync.test.ts +++ b/__tests__/cronJobTest/labelSync.test.ts @@ -16,7 +16,8 @@ import * as utils from '../testUtils' // non-Error fallback of a refused write is only reachable through a stub vi.mock('../../src/utils/octokit', { spy: true }) -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/cronJobTest/lgtm.test.ts b/__tests__/cronJobTest/lgtm.test.ts index 4af2b8c..aafa346 100644 --- a/__tests__/cronJobTest/lgtm.test.ts +++ b/__tests__/cronJobTest/lgtm.test.ts @@ -29,6 +29,7 @@ function servePullsByNumber(prs: typeof listPullReqs) { } const server = setupServer( + utils.noMergeQueue, ...utils.noOrgOrRepoConfigExcept(), // the gate's default depends on whether the default branch has OWNERS files; none here unless a test serves a tree utils.defaultBranchTree(), @@ -61,6 +62,7 @@ const server = setupServer( }, ), ) +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/approve.test.ts b/__tests__/issueCommentTest/approve.test.ts index 890be7a..25f5231 100644 --- a/__tests__/issueCommentTest/approve.test.ts +++ b/__tests__/issueCommentTest/approve.test.ts @@ -14,7 +14,8 @@ import pullReqListReviews from '../fixtures/pullReq/pullReqListReviews.json' import * as utils from '../testUtils' import { baseBranch, blobSha, changedFiles, filesHandler, prCommentEvent, prHandlers, pullHandler, repo, treeHandlers } from '../utils/ownersFixtures' -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/approveMilestoneErrorPaths.test.ts b/__tests__/issueCommentTest/approveMilestoneErrorPaths.test.ts index 482405e..fbc1b23 100644 --- a/__tests__/issueCommentTest/approveMilestoneErrorPaths.test.ts +++ b/__tests__/issueCommentTest/approveMilestoneErrorPaths.test.ts @@ -16,6 +16,7 @@ import * as utils from '../testUtils' vi.mock('../../src/utils/auth', { spy: true }) const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/assign.test.ts b/__tests__/issueCommentTest/assign.test.ts index 0e2272e..9d1b7e2 100644 --- a/__tests__/issueCommentTest/assign.test.ts +++ b/__tests__/issueCommentTest/assign.test.ts @@ -11,6 +11,7 @@ import issueListComments from '../fixtures/issues/assign/issueListComments.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/cc.test.ts b/__tests__/issueCommentTest/cc.test.ts index a1cdd97..56c2e17 100644 --- a/__tests__/issueCommentTest/cc.test.ts +++ b/__tests__/issueCommentTest/cc.test.ts @@ -11,6 +11,7 @@ import pullReviewRequested from '../fixtures/pullReq/pullReviewRequested.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/close.test.ts b/__tests__/issueCommentTest/close.test.ts index 2016998..da96866 100644 --- a/__tests__/issueCommentTest/close.test.ts +++ b/__tests__/issueCommentTest/close.test.ts @@ -12,6 +12,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/commentWithoutBody.test.ts b/__tests__/issueCommentTest/commentWithoutBody.test.ts index 90f6fb8..0f480a3 100644 --- a/__tests__/issueCommentTest/commentWithoutBody.test.ts +++ b/__tests__/issueCommentTest/commentWithoutBody.test.ts @@ -7,6 +7,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) let calls: string[] beforeAll(() => server.listen(utils.failOnUnhandledRequest)) beforeEach(() => { diff --git a/__tests__/issueCommentTest/errorPaths.test.ts b/__tests__/issueCommentTest/errorPaths.test.ts index 48bf2ab..b37182c 100644 --- a/__tests__/issueCommentTest/errorPaths.test.ts +++ b/__tests__/issueCommentTest/errorPaths.test.ts @@ -20,6 +20,7 @@ import * as utils from '../testUtils' vi.mock('../../src/utils/auth', { spy: true }) const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/handleIssueComment.test.ts b/__tests__/issueCommentTest/handleIssueComment.test.ts index db0f198..371c39f 100644 --- a/__tests__/issueCommentTest/handleIssueComment.test.ts +++ b/__tests__/issueCommentTest/handleIssueComment.test.ts @@ -22,6 +22,7 @@ import * as utils from '../testUtils' import { prCommentEvent, prHandlers, pullHandler, repo } from '../utils/ownersFixtures' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest)) // the dispatch tests below mock every command; the sweep that follows a command is stubbed the same way diff --git a/__tests__/issueCommentTest/lock.test.ts b/__tests__/issueCommentTest/lock.test.ts index 52d2929..f0cfc3c 100644 --- a/__tests__/issueCommentTest/lock.test.ts +++ b/__tests__/issueCommentTest/lock.test.ts @@ -10,6 +10,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/meow.test.ts b/__tests__/issueCommentTest/meow.test.ts index 0f6c194..5f3af2d 100644 --- a/__tests__/issueCommentTest/meow.test.ts +++ b/__tests__/issueCommentTest/meow.test.ts @@ -14,6 +14,7 @@ import * as utils from '../testUtils' const catApi = 'https://api.thecatapi.com/v1/images/search' const server = setupServer() +utils.failTestOnUnhandledRequests(server) // msw answers every mocked request without resolving its host, so the only // way a unit test reaches dns is a socket the interceptor passed through diff --git a/__tests__/issueCommentTest/milestone.test.ts b/__tests__/issueCommentTest/milestone.test.ts index 640f969..3c610f1 100644 --- a/__tests__/issueCommentTest/milestone.test.ts +++ b/__tests__/issueCommentTest/milestone.test.ts @@ -11,6 +11,7 @@ import repoMilestones from '../fixtures/milestones/repoListMilestones.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/reopen.test.ts b/__tests__/issueCommentTest/reopen.test.ts index 9842875..d6b28db 100644 --- a/__tests__/issueCommentTest/reopen.test.ts +++ b/__tests__/issueCommentTest/reopen.test.ts @@ -12,6 +12,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/retitle.test.ts b/__tests__/issueCommentTest/retitle.test.ts index b2264ea..10b2c14 100644 --- a/__tests__/issueCommentTest/retitle.test.ts +++ b/__tests__/issueCommentTest/retitle.test.ts @@ -10,6 +10,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/reviewAuthorization.test.ts b/__tests__/issueCommentTest/reviewAuthorization.test.ts index fc9faf5..8fee46d 100644 --- a/__tests__/issueCommentTest/reviewAuthorization.test.ts +++ b/__tests__/issueCommentTest/reviewAuthorization.test.ts @@ -13,6 +13,7 @@ import * as utils from '../testUtils' import { prCommentEvent, prHandlers } from '../utils/ownersFixtures' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => 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 18dd3ea..731cc7a 100644 --- a/__tests__/issueCommentTest/trigger.test.ts +++ b/__tests__/issueCommentTest/trigger.test.ts @@ -13,7 +13,8 @@ import prOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json' import * as utils from '../testUtils' import { prCommentEvent, prHandlers, repo } from '../utils/ownersFixtures' -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => { server.resetHandlers() @@ -670,7 +671,7 @@ describe('/test', () => { it('refuses an outsider', async () => { const reply = new utils.ObserveRequest() - server.use(...outsiderAuth(), http.post(`${repo}/issues/1/comments`, utils.mockResponse(201, {}, reply))) + server.use(...outsiderAuth(), http.post(`${repo}/issues/1/comments`, utils.mockResponse(201, {}, reply)), ...utils.noOrgOrRepoConfigExcept()) const setFailed = vi.spyOn(core, 'setFailed').mockImplementation(() => {}) vi.spyOn(core, 'error').mockImplementation(() => {}) diff --git a/__tests__/issueCommentTest/unassign.test.ts b/__tests__/issueCommentTest/unassign.test.ts index 52d4cf4..545ff1b 100644 --- a/__tests__/issueCommentTest/unassign.test.ts +++ b/__tests__/issueCommentTest/unassign.test.ts @@ -11,6 +11,7 @@ import issueUnassignedResp from '../fixtures/issues/unassign/issueUnassignedResp import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issueCommentTest/uncc.test.ts b/__tests__/issueCommentTest/uncc.test.ts index 42d9356..bb3ee48 100644 --- a/__tests__/issueCommentTest/uncc.test.ts +++ b/__tests__/issueCommentTest/uncc.test.ts @@ -10,6 +10,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/issuesTest/handleIssues.test.ts b/__tests__/issuesTest/handleIssues.test.ts index db21330..195d28d 100644 --- a/__tests__/issuesTest/handleIssues.test.ts +++ b/__tests__/issuesTest/handleIssues.test.ts @@ -8,6 +8,7 @@ import issuesLabeledEvent from '../fixtures/issues/issuesLabeledEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/area.test.ts b/__tests__/label/area.test.ts index ed734a4..d3dafd8 100644 --- a/__tests__/label/area.test.ts +++ b/__tests__/label/area.test.ts @@ -11,6 +11,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/authorization.test.ts b/__tests__/label/authorization.test.ts index 1cd6674..9078f6d 100644 --- a/__tests__/label/authorization.test.ts +++ b/__tests__/label/authorization.test.ts @@ -11,6 +11,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => 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 a705260..03aec1d 100644 --- a/__tests__/label/dynamic.test.ts +++ b/__tests__/label/dynamic.test.ts @@ -11,6 +11,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/errorPaths.test.ts b/__tests__/label/errorPaths.test.ts index 8627874..855fa8b 100644 --- a/__tests__/label/errorPaths.test.ts +++ b/__tests__/label/errorPaths.test.ts @@ -19,6 +19,7 @@ import * as utils from '../testUtils' vi.mock('../../src/utils/auth', { spy: true }) const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/help.test.ts b/__tests__/label/help.test.ts index cb571e8..a0355b0 100644 --- a/__tests__/label/help.test.ts +++ b/__tests__/label/help.test.ts @@ -10,6 +10,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/hold.test.ts b/__tests__/label/hold.test.ts index ac29bfc..13fe635 100644 --- a/__tests__/label/hold.test.ts +++ b/__tests__/label/hold.test.ts @@ -12,6 +12,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer(...utils.noOrgOrRepoConfigExcept()) +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/kind.test.ts b/__tests__/label/kind.test.ts index 06b5b2c..44f6de2 100644 --- a/__tests__/label/kind.test.ts +++ b/__tests__/label/kind.test.ts @@ -11,6 +11,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/label.test.ts b/__tests__/label/label.test.ts index 32383b7..0e440e6 100644 --- a/__tests__/label/label.test.ts +++ b/__tests__/label/label.test.ts @@ -13,6 +13,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/lgtm.test.ts b/__tests__/label/lgtm.test.ts index 80a460a..02f5ef1 100644 --- a/__tests__/label/lgtm.test.ts +++ b/__tests__/label/lgtm.test.ts @@ -20,7 +20,8 @@ import { prCommentEvent, prHandlers } from '../utils/ownersFixtures' // /lgtm is only reachable when the binding itself rejects with a bare value vi.mock('../../src/plugins/lgtmBinding', { spy: true }) -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/lifecycle.test.ts b/__tests__/label/lifecycle.test.ts index 685aa64..21f54bc 100644 --- a/__tests__/label/lifecycle.test.ts +++ b/__tests__/label/lifecycle.test.ts @@ -12,6 +12,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/prefixed.test.ts b/__tests__/label/prefixed.test.ts index 4d3b504..cbe6ac5 100644 --- a/__tests__/label/prefixed.test.ts +++ b/__tests__/label/prefixed.test.ts @@ -8,6 +8,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) 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 a3329af..750638f 100644 --- a/__tests__/label/priority.test.ts +++ b/__tests__/label/priority.test.ts @@ -11,6 +11,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/label/remove.test.ts b/__tests__/label/remove.test.ts index da17195..2419677 100644 --- a/__tests__/label/remove.test.ts +++ b/__tests__/label/remove.test.ts @@ -10,6 +10,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/missingNumberMessage.test.ts b/__tests__/missingNumberMessage.test.ts index 7bd8820..7ac8dbc 100644 --- a/__tests__/missingNumberMessage.test.ts +++ b/__tests__/missingNumberMessage.test.ts @@ -27,6 +27,7 @@ import * as utils from './testUtils' // every request is unexpected: the handlers must refuse before calling the API const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/plugins/approveErrorPaths.test.ts b/__tests__/plugins/approveErrorPaths.test.ts index 4cfbb69..a6caf75 100644 --- a/__tests__/plugins/approveErrorPaths.test.ts +++ b/__tests__/plugins/approveErrorPaths.test.ts @@ -13,6 +13,7 @@ import * as utils from '../testUtils' import { prHandlers, repo } from '../utils/ownersFixtures' const server = setupServer() +utils.failTestOnUnhandledRequests(server) 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 d909fe7..c67d48c 100644 --- a/__tests__/plugins/approveEvents.test.ts +++ b/__tests__/plugins/approveEvents.test.ts @@ -13,7 +13,8 @@ import reviewSubmittedEvent from '../fixtures/pullReq/pullReqReviewSubmittedEven import * as utils from '../testUtils' import { prHandlers, repo } from '../utils/ownersFixtures' -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/plugins/approveReview.test.ts b/__tests__/plugins/approveReview.test.ts index 82eca82..24824ad 100644 --- a/__tests__/plugins/approveReview.test.ts +++ b/__tests__/plugins/approveReview.test.ts @@ -17,7 +17,8 @@ import reviewSubmittedEvent from '../fixtures/pullReq/pullReqReviewSubmittedEven import * as utils from '../testUtils' import { prHandlers, pullBody, repo } from '../utils/ownersFixtures' -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) 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 2483bff..5f9b4dc 100644 --- a/__tests__/plugins/blunderbuss.test.ts +++ b/__tests__/plugins/blunderbuss.test.ts @@ -15,6 +15,7 @@ import * as utils from '../testUtils' import { baseSha, changedFiles, filesHandler, prCommentEvent, repo, treeHandlers } from '../utils/ownersFixtures' const server = setupServer() +utils.failTestOnUnhandledRequests(server) 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 bef3732..19549b9 100644 --- a/__tests__/plugins/lgtmBinding.test.ts +++ b/__tests__/plugins/lgtmBinding.test.ts @@ -12,6 +12,7 @@ import pullReqOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) 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 cf83d6c..525a939 100644 --- a/__tests__/plugins/ownersLabel.test.ts +++ b/__tests__/plugins/ownersLabel.test.ts @@ -10,6 +10,7 @@ import * as utils from '../testUtils' import { baseSha, changedFiles, filesHandler, prHandlers, pullHandler, repo, treeHandlers } from '../utils/ownersFixtures' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) @@ -216,6 +217,8 @@ describe('ownersLabel', () => { const setFailed = vi.spyOn(core, 'setFailed').mockImplementation(() => {}) server.use( ...utils.noOrgOrRepoConfigExcept(), + // the approve handler runs on opened too; an OWNERS-less default branch keeps it out of this test + utils.defaultBranchTree(), http.get(`${repo}/pulls/1`, utils.mockResponse(500, { message: 'boom' })), ) diff --git a/__tests__/plugins/pluginErrorPaths.test.ts b/__tests__/plugins/pluginErrorPaths.test.ts index 5b395c5..833eb36 100644 --- a/__tests__/plugins/pluginErrorPaths.test.ts +++ b/__tests__/plugins/pluginErrorPaths.test.ts @@ -13,6 +13,7 @@ import * as utils from '../testUtils' import { prHandlers } from '../utils/ownersFixtures' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest)) beforeEach(() => utils.setupActionsEnv()) afterEach(() => server.resetHandlers()) diff --git a/__tests__/plugins/requireMatchingLabel.test.ts b/__tests__/plugins/requireMatchingLabel.test.ts index 243527c..8616b35 100644 --- a/__tests__/plugins/requireMatchingLabel.test.ts +++ b/__tests__/plugins/requireMatchingLabel.test.ts @@ -19,7 +19,8 @@ import pullReqOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json' import * as utils from '../testUtils' import { pullHandler } from '../utils/ownersFixtures' -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) beforeAll(() => 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 b1d1870..e499aef 100644 --- a/__tests__/plugins/tideMergeQueue.test.ts +++ b/__tests__/plugins/tideMergeQueue.test.ts @@ -11,6 +11,7 @@ import pullReqOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) 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 ed8a7d6..25884ac 100644 --- a/__tests__/pullReqTest/handleCheckSuite.test.ts +++ b/__tests__/pullReqTest/handleCheckSuite.test.ts @@ -10,6 +10,7 @@ import checkSuiteCompletedEvent from '../fixtures/pullReq/checkSuiteCompletedEve import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/pullReqTest/handlePullReq.test.ts b/__tests__/pullReqTest/handlePullReq.test.ts index bd05b35..1686faf 100644 --- a/__tests__/pullReqTest/handlePullReq.test.ts +++ b/__tests__/pullReqTest/handlePullReq.test.ts @@ -17,6 +17,7 @@ import prOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/pullReqTest/handlePullReqReview.test.ts b/__tests__/pullReqTest/handlePullReqReview.test.ts index 977425a..46cc1ea 100644 --- a/__tests__/pullReqTest/handlePullReqReview.test.ts +++ b/__tests__/pullReqTest/handlePullReqReview.test.ts @@ -9,6 +9,7 @@ import reviewSubmittedEvent from '../fixtures/pullReq/pullReqReviewSubmittedEven import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/pullReqTest/onPrLgtm.test.ts b/__tests__/pullReqTest/onPrLgtm.test.ts index 6bdb08e..c39699d 100644 --- a/__tests__/pullReqTest/onPrLgtm.test.ts +++ b/__tests__/pullReqTest/onPrLgtm.test.ts @@ -13,7 +13,8 @@ import { prHandlers } from '../utils/ownersFixtures' // removal is tied to new commits, so the cases below run on `synchronize` const pullReqEvent = { ...pullReqOpenedEvent, action: 'synchronize' } -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/pullReqTest/readOnlyFork.test.ts b/__tests__/pullReqTest/readOnlyFork.test.ts index b1a8c84..4635810 100644 --- a/__tests__/pullReqTest/readOnlyFork.test.ts +++ b/__tests__/pullReqTest/readOnlyFork.test.ts @@ -11,6 +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() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest)) const fork = 'octocat/Hello-World' diff --git a/__tests__/testUtils.ts b/__tests__/testUtils.ts index 7b808ff..8ad2ad9 100644 --- a/__tests__/testUtils.ts +++ b/__tests__/testUtils.ts @@ -1,6 +1,8 @@ +import type { SetupServerApi } from 'msw/node' import type { Context } from '../src/utils/context' import * as github from '@actions/github' import { http } from 'msw' +import { afterEach, beforeEach, expect } from 'vitest' import { resetTideWarnings } from '../src/plugins/tide' import { resetProwConfigCache } from '../src/utils/config' @@ -21,6 +23,55 @@ export const api = 'https://api.github.com' */ export const failOnUnhandledRequest = { onUnhandledRequest: 'error', onUnhandledFrame: 'error' } as const +/** + * failTestOnUnhandledRequests makes a request that `failOnUnhandledRequest` + * rejected fail the test it happened in. The rejection alone does not: the + * code under test receives it as a network error, and a fallback that catches + * it (fail-open authorization, a warning, a skipped step) lets the test pass + * while the request it meant to assert on was never served. + * + * Call it once at file level, right after `setupServer()`. The listener is + * re-attached before every test, so an `afterEach` that calls + * `server.events.removeAllListeners()` does not disarm it. A test that leaves a + * request deliberately unserved opts out with `.allow()`; the allowance lasts + * for that test only. + * + * @param server - the file's msw server + */ +export function failTestOnUnhandledRequests(server: SetupServerApi) { + const unhandled: string[] = [] + let allowed = false + const record = ({ request }: { request: Request }) => { + unhandled.push(`${request.method} ${request.url}`) + } + const check = () => { + if (!allowed && unhandled.length > 0) { + expect.fail(`${unhandled.length} request(s) no handler served (a test that leaves one unserved on purpose calls .allow() on the object failTestOnUnhandledRequests returned):\n ${unhandled.join('\n ')}`) + } + } + beforeEach(() => { + unhandled.length = 0 + allowed = false + server.events.on('request:unhandled', record) + }) + afterEach(() => { + server.events.removeListener('request:unhandled', record) + check() + }) + return { + /** lets the current test leave requests unserved */ + allow() { + allowed = true + }, + /** the requests no handler served so far in the current test, as `METHOD url` */ + seen() { + return [...unhandled] + }, + /** what the afterEach runs: fails unless nothing is unserved or the test called allow() */ + check, + } +} + /** every file the prow configuration loader probes for Codertocat/Hello-World, as `owner/repo:path` */ export const configProbes = [ 'Codertocat/.project:prow.yaml', @@ -302,6 +353,15 @@ export function mergeQueueGraphql(queue: MergeQueueFixture = {}, calls: GraphqlC return { handler, calls } } +/** + * noMergeQueue answers the merge queue state query for any pull request with + * `isMergeQueueEnabled: false`, what GitHub reports for a base branch without a + * merge queue, so tide merges directly. Without it an unserved `POST /graphql` + * reaches the same direct merge through readQueueState's "could not read the + * merge queue state" fallback, which failTestOnUnhandledRequests rejects. + */ +export const noMergeQueue = mergeQueueGraphql({ enabled: false }).handler + export function graphqlMutations(calls: GraphqlCall[], name: string) { return calls.filter(call => call.query.includes(name)) } diff --git a/__tests__/unhandledRequests.test.ts b/__tests__/unhandledRequests.test.ts new file mode 100644 index 0000000..f95c72d --- /dev/null +++ b/__tests__/unhandledRequests.test.ts @@ -0,0 +1,70 @@ +import { http } from 'msw' +import { setupServer } from 'msw/node' +import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest' + +import * as utils from './testUtils' + +const server = setupServer() +const unhandled = utils.failTestOnUnhandledRequests(server) +beforeAll(() => server.listen(utils.failOnUnhandledRequest)) +afterEach(() => server.resetHandlers()) +afterAll(() => server.close()) + +const url = `${utils.api}/repos/Codertocat/Hello-World/pulls/1` + +// what the code under test does with a request failOnUnhandledRequest rejected +async function swallow(target: string) { + await fetch(target).catch(() => undefined) +} + +describe('failTestOnUnhandledRequests', () => { + it('records a request no handler served even though the caller swallowed the rejection', async () => { + await swallow(url) + + expect(unhandled.seen()).toEqual([`GET ${url}`]) + expect(() => unhandled.check()).toThrow(`1 request(s) no handler served (a test that leaves one unserved on purpose calls .allow() on the object failTestOnUnhandledRequests returned):\n GET ${url}`) + unhandled.allow() + }) + + it('does not count a served request, nor one answered with a network error on purpose', async () => { + server.use( + http.get(url, utils.mockResponse(200, { number: 1 })), + http.get(`${url}/files`, () => Response.error()), + ) + + await fetch(url) + await swallow(`${url}/files`) + + expect(unhandled.seen()).toEqual([]) + expect(() => unhandled.check()).not.toThrow() + }) + + it('allow() exempts the current test only', async () => { + unhandled.allow() + await swallow(url) + + expect(unhandled.seen()).toEqual([`GET ${url}`]) + expect(() => unhandled.check()).not.toThrow() + }) + + it('starts the next test with nothing recorded and no allowance', () => { + expect(unhandled.seen()).toEqual([]) + expect(() => unhandled.check()).not.toThrow() + }) + + it('a test that calls server.events.removeAllListeners() disarms only itself', async () => { + server.events.removeAllListeners() + await swallow(url) + + // the listener is re-attached before every test, so the removal only reaches this one + expect(unhandled.seen()).toEqual([]) + unhandled.allow() + }) + + it('is listening again after the test that removed every listener', async () => { + await swallow(url) + + expect(unhandled.seen()).toEqual([`GET ${url}`]) + unhandled.allow() + }) +}) diff --git a/__tests__/utils/auth.test.ts b/__tests__/utils/auth.test.ts index 3f5dfc1..ebdc7ce 100644 --- a/__tests__/utils/auth.test.ts +++ b/__tests__/utils/auth.test.ts @@ -24,6 +24,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => { utils.setupActionsEnv() server.listen(utils.failOnUnhandledRequest) diff --git a/__tests__/utils/comments.test.ts b/__tests__/utils/comments.test.ts index d17f670..0d14962 100644 --- a/__tests__/utils/comments.test.ts +++ b/__tests__/utils/comments.test.ts @@ -8,6 +8,7 @@ import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) 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 66128da..26649bd 100644 --- a/__tests__/utils/configLoader.test.ts +++ b/__tests__/utils/configLoader.test.ts @@ -13,6 +13,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) diff --git a/__tests__/utils/labeling.test.ts b/__tests__/utils/labeling.test.ts index f321e76..ed10027 100644 --- a/__tests__/utils/labeling.test.ts +++ b/__tests__/utils/labeling.test.ts @@ -16,6 +16,7 @@ import malformedFileContents from '../fixtures/labels/labelFileMalformedResponse import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest), ) diff --git a/__tests__/utils/mergeQueue.test.ts b/__tests__/utils/mergeQueue.test.ts index c06236c..6e5e114 100644 --- a/__tests__/utils/mergeQueue.test.ts +++ b/__tests__/utils/mergeQueue.test.ts @@ -19,6 +19,7 @@ import pullReqOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => { utils.setupActionsEnv() server.listen(utils.failOnUnhandledRequest) diff --git a/__tests__/utils/ownersAuth.test.ts b/__tests__/utils/ownersAuth.test.ts index dbbe2b3..d978852 100644 --- a/__tests__/utils/ownersAuth.test.ts +++ b/__tests__/utils/ownersAuth.test.ts @@ -23,7 +23,8 @@ import { treeHandlers, } from './ownersFixtures' -const server = setupServer() +const server = setupServer(utils.noMergeQueue) +utils.failTestOnUnhandledRequests(server) beforeAll(() => { utils.setupActionsEnv() server.listen(utils.failOnUnhandledRequest) @@ -336,6 +337,7 @@ describe('assertAuthorizedByOwnersOrMembership on a pull request', () => { server.use( pullHandler(), filesHandler(changedFiles('src/file1.txt')), + branchHandler(), http.get(`${repo}/git/trees/${baseSha}`, utils.mockResponse(500)), ) diff --git a/__tests__/utils/pullRequestOwners.test.ts b/__tests__/utils/pullRequestOwners.test.ts index c82bc17..0ee7b35 100644 --- a/__tests__/utils/pullRequestOwners.test.ts +++ b/__tests__/utils/pullRequestOwners.test.ts @@ -21,6 +21,7 @@ import { } from './ownersFixtures' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest)) beforeEach(() => utils.setupActionsEnv()) afterEach(() => server.resetHandlers()) @@ -238,6 +239,7 @@ describe('loadPullRequestOwners', () => { server.use( pullHandler(), filesHandler(changedFiles('src/file1.txt')), + branchHandler(), http.get(`${repo}/git/trees/${baseSha}`, utils.mockResponse(500, null, observeTree)), http.get(`${repo}/git/blobs/${blobSha('OWNERS')}`, utils.mockResponse(500)), ) diff --git a/__tests__/utils/repoHasOwners.test.ts b/__tests__/utils/repoHasOwners.test.ts index 0f94483..a518c1b 100644 --- a/__tests__/utils/repoHasOwners.test.ts +++ b/__tests__/utils/repoHasOwners.test.ts @@ -10,6 +10,7 @@ import * as utils from '../testUtils' import { contentsResponse, repo } from './ownersFixtures' const server = setupServer() +utils.failTestOnUnhandledRequests(server) 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 33316c0..d612830 100644 --- a/__tests__/utils/utilsErrorPaths.test.ts +++ b/__tests__/utils/utilsErrorPaths.test.ts @@ -15,6 +15,7 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json' import * as utils from '../testUtils' const server = setupServer() +utils.failTestOnUnhandledRequests(server) beforeAll(() => server.listen(utils.failOnUnhandledRequest)) afterEach(() => server.resetHandlers()) afterAll(() => server.close())