Skip to content

Commit a56e051

Browse files
committed
chore: update fetch-mock from 11.1.5 to 12.0.2
The API has changed to this update requires updates to our tests.
1 parent 65307b4 commit a56e051

File tree

7 files changed

+92
-74
lines changed

7 files changed

+92
-74
lines changed

package-lock.json

Lines changed: 25 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"devDependencies": {
3131
"eventsource": "^2.0.2",
32-
"fetch-mock": "^11.1.5",
32+
"fetch-mock": "^12.0.2",
3333
"nock": "^13.5.5",
3434
"nodemon": "^3.1.7",
3535
"standard": "^17.1.2",

test/integration/event-relay-to-github-actions.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ eventRelay(app, events)
1313
tap.test('Sends POST requests to https://api.github.com/repos/nodejs/<repo>/dispatches', (t) => {
1414
const jenkinsPayload = readFixture('success-payload.json')
1515

16-
fetchMock.mock('https://api.github.com/repos/nodejs/node/dispatches', 204)
16+
fetchMock.mockGlobal()
17+
fetchMock.route('https://api.github.com/repos/nodejs/node/dispatches', 204)
1718

1819
t.plan(2)
1920

@@ -23,6 +24,6 @@ tap.test('Sends POST requests to https://api.github.com/repos/nodejs/<repo>/disp
2324
.expect(200)
2425
.end((err, res) => {
2526
t.equal(err, null)
26-
t.equal(fetchMock.done(), true)
27+
t.equal(fetchMock.callHistory.called(), true)
2728
})
2829
})

test/integration/push-jenkins-update.test.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import readFixture from '../read-fixture.js'
99
import jenkinsStatus from '../../scripts/jenkins-status.js'
1010

1111
fetchMock.config.overwriteRoutes = true
12+
fetchMock.mockGlobal()
1213

1314
jenkinsStatus(app, events)
1415

@@ -18,7 +19,7 @@ tap.test('Sends POST requests to https://api.github.com/repos/nodejs/node/status
1819
const listCommitsUrl = setupListCommitsMock('node')
1920

2021
const url = 'https://api.github.com/repos/nodejs/node/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1'
21-
fetchMock.mock({ url, method: 'POST' }, 201)
22+
fetchMock.route({ url, method: 'POST' }, 201)
2223

2324
t.plan(3)
2425

@@ -28,8 +29,8 @@ tap.test('Sends POST requests to https://api.github.com/repos/nodejs/node/status
2829
.expect(200)
2930
.end((err, res) => {
3031
t.equal(err, null)
31-
t.equal(fetchMock.done(url), true)
32-
t.equal(fetchMock.done(listCommitsUrl), true)
32+
t.equal(fetchMock.callHistory.called(url), true)
33+
t.equal(fetchMock.callHistory.called(listCommitsUrl), true)
3334
})
3435
})
3536

@@ -39,7 +40,7 @@ tap.test('Allows repository name to be provided with URL parameter when pushing
3940
const listCommitsUrl = setupListCommitsMock('citgm')
4041

4142
const url = 'https://api.github.com/repos/nodejs/citgm/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1'
42-
fetchMock.mock({ url, method: 'POST' }, 201)
43+
fetchMock.route({ url, method: 'POST' }, 201)
4344

4445
t.plan(3)
4546

@@ -49,8 +50,8 @@ tap.test('Allows repository name to be provided with URL parameter when pushing
4950
.expect(200)
5051
.end((err, res) => {
5152
t.equal(err, null)
52-
t.equal(fetchMock.done(url), true)
53-
t.equal(fetchMock.done(listCommitsUrl), true)
53+
t.equal(fetchMock.callHistory.called(url), true)
54+
t.equal(fetchMock.callHistory.called(listCommitsUrl), true)
5455
})
5556
})
5657

@@ -60,7 +61,7 @@ tap.test('Allows repository name to be provided with URL parameter when pushing
6061
const listCommitsUrl = setupListCommitsMock('citgm')
6162

6263
const url = 'https://api.github.com/repos/nodejs/citgm/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1'
63-
fetchMock.mock({ url, method: 'POST' }, 201)
64+
fetchMock.route({ url, method: 'POST' }, 201)
6465

6566
t.plan(3)
6667

@@ -70,8 +71,8 @@ tap.test('Allows repository name to be provided with URL parameter when pushing
7071
.expect(200)
7172
.end((err, res) => {
7273
t.equal(err, null)
73-
t.equal(fetchMock.done(url), true)
74-
t.equal(fetchMock.done(listCommitsUrl), true)
74+
t.equal(fetchMock.callHistory.called(url), true)
75+
t.equal(fetchMock.callHistory.called(listCommitsUrl), true)
7576
})
7677
})
7778

@@ -87,7 +88,7 @@ tap.test('Forwards payload provided in incoming POST to GitHub status API', (t)
8788
description: 'tests passed',
8889
target_url: 'https://ci.nodejs.org/job/node-test-commit-osx/3157/'
8990
}
90-
fetchMock.mock({ url, method: 'POST', body }, 201)
91+
fetchMock.route({ url, method: 'POST', body }, 201)
9192

9293
t.plan(3)
9394

@@ -97,8 +98,8 @@ tap.test('Forwards payload provided in incoming POST to GitHub status API', (t)
9798
.expect(200)
9899
.end((err, res) => {
99100
t.equal(err, null)
100-
t.equal(fetchMock.done(url), true)
101-
t.equal(fetchMock.done(listCommitsUrl), true)
101+
t.equal(fetchMock.callHistory.called(url), true)
102+
t.equal(fetchMock.callHistory.called(listCommitsUrl), true)
102103
})
103104
})
104105

@@ -107,11 +108,11 @@ tap.test('Posts a CI comment in the related PR when Jenkins build is named node-
107108

108109
const url = 'https://api.github.com/repos/nodejs/node/issues/12345/comments'
109110
const body = { body: 'CI: https://ci.nodejs.org/job/node-test-pull-request/21633/' }
110-
fetchMock.mock({ url, method: 'POST', body }, 200)
111+
fetchMock.route({ url, method: 'POST', body }, 200)
111112

112113
// we don't care about asserting the scopes below, just want to stop the requests from actually being sent
113114
setupListCommitsMock('node')
114-
fetchMock.mock(
115+
fetchMock.route(
115116
{
116117
url: 'https://api.github.com/repos/nodejs/node/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1',
117118
method: 'POST'
@@ -124,7 +125,7 @@ tap.test('Posts a CI comment in the related PR when Jenkins build is named node-
124125
.send(fixture)
125126
.expect(200)
126127
.end((err, res) => {
127-
t.equal(fetchMock.done(url), true)
128+
t.equal(fetchMock.callHistory.called(url), true)
128129
t.equal(err, null)
129130
})
130131
})
@@ -135,11 +136,11 @@ tap.test('Posts a CI comment in the related PR when Jenkins build is named node-
135136

136137
const url = 'https://api.github.com/repos/nodejs/node/issues/12345/comments'
137138
const body = { body: 'Lite-CI: https://ci.nodejs.org/job/node-test-pull-request/21633/' }
138-
fetchMock.mock({ url, body, method: 'POST' }, 200)
139+
fetchMock.route({ url, body, method: 'POST' }, 200)
139140

140141
// we don't care about asserting the scopes below, just want to stop the requests from actually being sent
141142
setupListCommitsMock('node')
142-
fetchMock.mock(
143+
fetchMock.route(
143144
{
144145
url: 'https://api.github.com/repos/nodejs/node/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1',
145146
method: 'POST'
@@ -152,7 +153,7 @@ tap.test('Posts a CI comment in the related PR when Jenkins build is named node-
152153
.send(fixture)
153154
.expect(200)
154155
.end((err, res) => {
155-
t.equal(fetchMock.done(url), true)
156+
t.equal(fetchMock.callHistory.called(url), true)
156157
t.equal(err, null)
157158
})
158159
})
@@ -161,7 +162,7 @@ tap.test('Responds with 400 / "Bad request" when incoming request has invalid pa
161162
const fixture = readFixture('invalid-payload.json')
162163

163164
// don't care about the results, just want to prevent any HTTP request ever being made
164-
fetchMock.mock('https://api.github.com', 200)
165+
fetchMock.route('https://api.github.com', 200)
165166

166167
t.plan(1)
167168

@@ -178,7 +179,7 @@ tap.test('Responds with 400 / "Bad request" when build started status update is
178179
const fixture = readFixture('jenkins-staging-failure-payload.json')
179180

180181
// don't care about the results, just want to prevent any HTTP request ever being made
181-
fetchMock.mock('https://api.github.com', 200)
182+
fetchMock.route('https://api.github.com', 200)
182183

183184
t.plan(1)
184185

@@ -195,7 +196,7 @@ tap.test('Responds with 400 / "Bad request" when build ended status update is no
195196
const fixture = readFixture('jenkins-staging-failure-payload.json')
196197

197198
// don't care about the results, just want to prevent any HTTP request ever being made
198-
fetchMock.mock('https://api.github.com/', 200)
199+
fetchMock.route('https://api.github.com/', 200)
199200

200201
t.plan(1)
201202

@@ -212,7 +213,7 @@ tap.test('Responds with 400 / "Bad request" when incoming providing invalid repo
212213
const fixture = readFixture('pending-payload.json')
213214

214215
// don't care about the results, just want to prevent any HTTP request ever being made
215-
fetchMock.mock('https://api.github.com/', 200)
216+
fetchMock.route('https://api.github.com/', 200)
216217

217218
t.plan(1)
218219

@@ -229,6 +230,6 @@ function setupListCommitsMock (repoName) {
229230
const commitsResponse = readFixture('pr-commits.json')
230231
const url = `https://api.github.com/repos/nodejs/${repoName}/pulls/12345/commits`
231232

232-
fetchMock.mock(url, commitsResponse)
233+
fetchMock.route(url, commitsResponse)
233234
return url
234235
}

0 commit comments

Comments
 (0)