Skip to content

Commit 249b062

Browse files
committed
Make flawed integration tests explode by fixing nock expectations
Up until now, a handful of integration tests has been flawed because we didn't actually verify all nock.js expectations (read: nock.js scope) had been fulfilled. That was due to a desire to run several methods as a one-liner instead of one per line; ``` filesScope.done() && existingRepoLabelsScope.done() ``` That could make sense at first glance, but there's a very important catch we didn't think about when writing it; it requires `.done()` to return a truthy value or else what comes after `.done()` will not be executed. The `.done()` method on nock.js' scope either throws an exception if the expectation it represents has not been met, or returns `undefined` when all is good. That `undefined` value stops the subsequent methods on the same line to be executed. In other words, we have always just checked the first expectation, and none of the subsequent ones on the same line. The changes introduced in this commit executes these `.done()`s on their own line which sadly causes all of the related tests to explode at the moment. Why most of these expectations haven't been met is probably due to timing issues, since we don't wait for all the related code to have finished executing before the tests are run. As of now, the code has been written in a fashion that allows incoming HTTPS requests to be get their response ASAP, whilst the code pushing PR statuses to github.com or trigger Jenins builds are still running. That raises some challenges for our integration tests since they don't really know when the code is finished, meaning tests can run. Upcoming changes will fix that by ensuring incoming requests will get their response *after* all relevant code has succeeded or failed. That will introduce quite a big refactor job, but the end result will be a lot more robust tests that can be trusted.
1 parent c829ad5 commit 249b062

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

test/integration/node-labels-webhook.test.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ tap.test('Sends POST request to https://api.github.com/repos/nodejs/node/issues/
4444
.reply(200)
4545

4646
t.plan(1)
47-
t.tearDown(() => filesScope.done() && existingRepoLabelsScope.done() && newLabelsScope.done() && clock.uninstall())
47+
t.tearDown(() => {
48+
filesScope.done()
49+
existingRepoLabelsScope.done()
50+
newLabelsScope.done()
51+
clock.uninstall()
52+
})
4853

4954
supertest(app)
5055
.post('/hooks/github')
@@ -78,7 +83,12 @@ tap.test('Adds v6.x label when PR is targeting the v6.x-staging branch', (t) =>
7883
.reply(200)
7984

8085
t.plan(1)
81-
t.tearDown(() => filesScope.done() && existingRepoLabelsScope.done() && newLabelsScope.done() && clock.uninstall())
86+
t.tearDown(() => {
87+
filesScope.done()
88+
existingRepoLabelsScope.done()
89+
newLabelsScope.done()
90+
clock.uninstall()
91+
})
8292

8393
supertest(app)
8494
.post('/hooks/github')
@@ -107,7 +117,11 @@ tap.test('Does not create labels which does not already exist', (t) => {
107117
.reply(200, readFixture('repo-labels.json'))
108118

109119
t.plan(1)
110-
t.tearDown(() => filesScope.done() && existingRepoLabelsScope.done() && clock.uninstall())
120+
t.tearDown(() => {
121+
filesScope.done()
122+
existingRepoLabelsScope.done()
123+
clock.uninstall()
124+
})
111125

112126
supertest(app)
113127
.post('/hooks/github')
@@ -142,7 +156,12 @@ tap.test('Adds V8 Engine label when PR has deps/v8 file changes', (t) => {
142156
.reply(200)
143157

144158
t.plan(1)
145-
t.tearDown(() => filesScope.done() && existingRepoLabelsScope.done() && newLabelsScope.done() && clock.uninstall())
159+
t.tearDown(() => {
160+
filesScope.done()
161+
existingRepoLabelsScope.done()
162+
newLabelsScope.done()
163+
clock.uninstall()
164+
})
146165

147166
supertest(app)
148167
.post('/hooks/github')

test/integration/trigger-jenkins-build.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ tap.test('Sends POST request to https://ci.nodejs.org', (t) => {
4444
.reply(200)
4545

4646
t.plan(1)
47-
t.tearDown(() => collaboratorsScope.done() && ciJobScope.done() && commentScope.done() && clock.uninstall())
47+
t.tearDown(() => {
48+
collaboratorsScope.done()
49+
ciJobScope.done()
50+
commentScope.done()
51+
clock.uninstall()
52+
})
4853

4954
supertest(app)
5055
.post('/hooks/github')

0 commit comments

Comments
 (0)