Skip to content

Commit 717ea28

Browse files
KimSH39richardlau
authored andcommitted
test: refactor error checks to use assert.ifError/mustSucceed
Replace manual `if (err) assert.fail(err)` and `assert.ok(!err)` with `assert.ifError()` or `common.mustSucceed()` in a few tests to clarify intent and follow project conventions. - test/parallel/test-child-process-send-returns-boolean.js - test/parallel/test-dgram-blocklist.js - test/parallel/test-fs-watchfile.js PR-URL: #59424 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 8c4dcd5 commit 717ea28

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

‎test/parallel/test-child-process-send-returns-boolean.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ const subScript = fixtures.path('child-process-persistent.js');
3333

3434
// Sending a handle and not giving the tickQueue time to acknowledge should
3535
// create the internal backlog, but leave it empty.
36-
constrv1=s.send('one',handle,(err)=>{if(err)assert.fail(err);});
36+
constrv1=s.send('one',handle,assert.ifError);
3737
assert.strictEqual(rv1,true);
3838
// Since the first `send` included a handle (should be unacknowledged),
3939
// we can safely queue up only one more message.
40-
constrv2=s.send('two',(err)=>{if(err)assert.fail(err);});
40+
constrv2=s.send('two',assert.ifError);
4141
assert.strictEqual(rv2,true);
4242
// The backlog should now be indicate to backoff.
43-
constrv3=s.send('three',(err)=>{if(err)assert.fail(err);});
43+
constrv3=s.send('three',assert.ifError);
4444
assert.strictEqual(rv3,false);
4545
constrv4=s.send('four',(err)=>{
46-
if(err)assert.fail(err);
46+
assert.ifError(err);
4747
// `send` queue should have been drained.
48-
constrv5=s.send('5',handle,(err)=>{if(err)assert.fail(err);});
48+
constrv5=s.send('5',handle,assert.ifError);
4949
assert.strictEqual(rv5,true);
5050

5151
// End test and cleanup.

‎test/parallel/test-dgram-blocklist.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ const net = require('net');
4141
receiveSocket.bind(0,common.localhostIPv4,common.mustCall(()=>{
4242
constaddressInfo=receiveSocket.address();
4343
constclient=dgram.createSocket('udp4');
44-
client.send('hello',addressInfo.port,addressInfo.address,common.mustCall((err)=>{
45-
assert.ok(!err);
46-
client.close();
47-
}));
44+
client.send(
45+
'hello',
46+
addressInfo.port,
47+
addressInfo.address,
48+
common.mustSucceed(()=>{
49+
client.close();
50+
})
51+
);
4852
}));
4953
}

‎test/parallel/test-fs-watchfile.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ if (common.isLinux || common.isMacOS || common.isWindows){
9494
}));
9595

9696
constinterval=setInterval(()=>{
97-
fs.writeFile(path.join(dir,'foo.txt'),'foo',common.mustCall((err)=>{
98-
if(err)assert.fail(err);
99-
}));
97+
fs.writeFile(path.join(dir,'foo.txt'),'foo',common.mustSucceed());
10098
},1);
10199
}
102100

0 commit comments

Comments
(0)