GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add common.mustSucceed · nodejs/node@70cb708

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/guides
    • writing-tests.md
  • test
    • .eslintrc.yaml
    • common
      • README.md
      • index.js
    • doctool
      • test-doctool-json.js
    • internet
      • test-dns-any.js
      • test-dns-ipv4.js
      • test-dns-ipv6.js
      • test-http2-issue-32922.js
    • parallel
      • test-c-ares.js
      • test-child-process-exec-any-shells-windows.js
      • test-child-process-exec-cwd.js
      • test-child-process-exec-encoding.js
      • test-child-process-exec-maxbuf.js
      • test-child-process-exec-std-encoding.js
      • test-child-process-exec-timeout.js
      • test-child-process-execfile-maxbuf.js
      • test-child-process-execfile.js
      • test-child-process-fork-getconnections.js
      • test-child-process-send-keep-open.js
      • test-child-process-windows-hide.js
      • test-cli-eval.js
      • test-cli-node-print-help.js
      • test-cluster-http-pipe.js
      • test-cluster-worker-disconnect-on-error.js
      • test-crypto-keygen.js
      • test-crypto-pbkdf2.js
      • test-crypto-random.js
      • test-crypto-scrypt.js
      • test-dgram-connect-send-callback-buffer-length.js
      • test-dgram-connect-send-callback-buffer.js
      • test-dgram-connect-send-empty-buffer.js
      • test-dgram-connect-send-multi-buffer-copy.js
      • test-dgram-send-address-types.js
      • test-dgram-send-callback-buffer-empty-address.js
      • test-dgram-send-callback-buffer-length-empty-address.js
      • test-dgram-send-callback-buffer-length.js
      • test-dgram-send-callback-buffer.js
      • test-dgram-send-callback-multi-buffer-empty-address.js
      • test-dns-lookup.js
      • test-dns-multi-channel.js
      • test-dns-resolveany.js
      • test-dns.js
      • test-domain-crypto.js
      • test-eslint-prefer-common-mustsucceed.js
      • test-fs-append-file.js
      • test-fs-buffer.js
      • test-fs-chmod-mask.js
      • test-fs-chmod.js
      • test-fs-copyfile.js
      • test-fs-empty-readStream.js
      • test-fs-existssync-false.js
      • test-fs-fsync.js
      • test-fs-lchown.js
      • test-fs-long-path.js
      • test-fs-mkdir-mode-mask.js
      • test-fs-mkdir-rmdir.js
      • test-fs-open-flags.js
      • test-fs-open-mode-mask.js
      • test-fs-open.js
      • test-fs-opendir.js
      • test-fs-read.js
      • test-fs-readdir-types.js
      • test-fs-readdir-ucs2.js
      • test-fs-readdir.js
      • test-fs-readfile-fd.js
      • test-fs-readfile-pipe-large.js
      • test-fs-readfile-pipe.js
      • test-fs-readfile-unlink.js
      • test-fs-readfilesync-enoent.js
      • test-fs-readfilesync-pipe-large.js
      • test-fs-readv.js
      • test-fs-realpath-buffer-encoding.js
      • test-fs-realpath-native.js
      • test-fs-realpath-on-substed-drive.js
      • test-fs-realpath.js
      • test-fs-rm.js
      • test-fs-rmdir-recursive.js
      • test-fs-stat.js
      • test-fs-symlink-dir-junction-relative.js
      • test-fs-symlink-dir-junction.js
      • test-fs-symlink-dir.js
      • test-fs-symlink-longpath.js
      • test-fs-symlink.js
      • test-fs-truncate-clear-file-zero.js
      • test-fs-truncate-fd.js
      • test-fs-truncate.js
      • test-fs-whatwg-url.js
      • test-fs-write-buffer.js
      • test-fs-write-file-typedarrays.js
      • test-fs-write-file.js
      • test-fs-write-reuse-callback.js
      • test-fs-write.js
      • test-fs-writefile-with-fd.js
      • test-fs-writev.js
      • test-http-unix-socket-keep-alive.js
      • test-http2-buffersize.js
      • test-http2-client-upload-reject.js
      • test-http2-client-upload.js
      • test-http2-compat-client-upload-reject.js
      • test-http2-compat-serverresponse-createpushresponse.js
      • test-http2-create-client-secure-session.js
      • test-http2-dont-lose-data.js
      • test-http2-options-max-reserved-streams.js
      • test-http2-respond-file-error-pipe-offset.js
      • test-http2-respond-file-with-pipe.js
      • test-http2-server-close-callback.js
      • test-http2-server-push-stream.js
      • test-https-close.js
      • test-inspector-heapdump.js
      • test-intl.js
      • test-net-pingpong.js
      • test-pipe-file-to-http.js
      • test-pipe-head.js
      • test-preload.js
      • test-process-redirect-warnings-env.js
      • test-process-redirect-warnings.js
      • test-repl-history-perm.js
      • test-repl-save-load.js
      • test-repl-tab-complete.js
      • test-repl-use-global.js
      • test-setproctitle.js
      • test-stdout-to-file.js
      • test-stream-finished.js
      • test-stream-pipeline-process.js
      • test-stream-pipeline-uncaught.js
      • test-stream-pipeline.js
      • test-tls-addca.js
      • test-tls-ca-concat.js
      • test-tls-cert-chains-concat.js
      • test-tls-client-getephemeralkeyinfo.js
      • test-tls-disable-renegotiation.js
      • test-tls-ecdh.js
      • test-trace-events-api.js
      • test-util-callbackify.js
      • test-worker-no-stdin-stdout-interaction.js
      • test-zlib-from-concatenated-gzip.js
      • test-zlib-from-gzip-with-trailing-garbage.js
    • sequential
      • test-init.js
  • tools/eslint-rules
    • prefer-common-mustsucceed.js

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/guides/writing-tests.md‎

Copy file name to clipboardExpand all lines: doc/guides/writing-tests.md
+5Lines changed: 5 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ const server = http.createServer(common.mustCall((req, res) => {
209209

210210
```
211211

212+
**Note:** Many functions invoke their callback with an `err` value as the first
213+
argument. It is not a good idea to simply pass `common.mustCall()` to those
214+
because `common.mustCall()` will ignore the error. Use `common.mustSucceed()`
215+
instead.
216+
212217
#### Countdown Module
213218

214219
The common [Countdown module](https://github.com/nodejs/node/tree/master/test/common#countdown-module)
Collapse file

‎test/.eslintrc.yaml‎

Copy file name to clipboardExpand all lines: test/.eslintrc.yaml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ rules:
5050
node-core/prefer-assert-iferror: error
5151
node-core/prefer-assert-methods: error
5252
node-core/prefer-common-mustnotcall: error
53+
node-core/prefer-common-mustsucceed: error
5354
node-core/crypto-check: error
5455
node-core/eslint-check: error
5556
node-core/inspector-check: error
Collapse file

‎test/common/README.md‎

Copy file name to clipboardExpand all lines: test/common/README.md
+9Lines changed: 9 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,15 @@ If `fn` is not provided, an empty function will be used.
313313
Returns a function that triggers an `AssertionError` if it is invoked. `msg` is
314314
used as the error message for the `AssertionError`.
315315

316+
### `mustSucceed([fn])`
317+
318+
* `fn` [<Function>][] default = () => {}
319+
* return [<Function>][]
320+
321+
Returns a function that accepts arguments `(err, ...args)`. If `err` is not
322+
`undefined` or `null`, it triggers an `AssertionError`. Otherwise, it calls
323+
`fn(...args)`.
324+
316325
### `nodeProcessAborted(exitCode, signal)`
317326

318327
* `exitCode` [<number>][]
Collapse file

‎test/common/index.js‎

Copy file name to clipboardExpand all lines: test/common/index.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@ function mustCall(fn, exact) {
334334
return _mustCallInner(fn, exact, 'exact');
335335
}
336336

337+
function mustSucceed(fn, exact) {
338+
return mustCall(function(err, ...args) {
339+
assert.ifError(err);
340+
if (typeof fn === 'function')
341+
return fn.apply(this, args);
342+
}, exact);
343+
}
344+
337345
function mustCallAtLeast(fn, minimum) {
338346
return _mustCallInner(fn, minimum, 'minimum');
339347
}
@@ -723,6 +731,7 @@ const common = {
723731
mustCall,
724732
mustCallAtLeast,
725733
mustNotCall,
734+
mustSucceed,
726735
nodeProcessAborted,
727736
PIPE,
728737
platformTimeout,
Collapse file

‎test/doctool/test-doctool-json.js‎

Copy file name to clipboardExpand all lines: test/doctool/test-doctool-json.js
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,8 @@ const testData = [
229229
];
230230

231231
testData.forEach((item) => {
232-
fs.readFile(item.file, 'utf8', common.mustCall((err, input) => {
233-
assert.ifError(err);
234-
toJSON(input, 'foo', common.mustCall((err, output) => {
235-
assert.ifError(err);
232+
fs.readFile(item.file, 'utf8', common.mustSucceed((input) => {
233+
toJSON(input, 'foo', common.mustSucceed((output) => {
236234
assert.deepStrictEqual(output.json, item.json);
237235
}));
238236
}));
Collapse file

‎test/internet/test-dns-any.js‎

Copy file name to clipboardExpand all lines: test/internet/test-dns-any.js
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ TEST(async function test_sip2sip_for_naptr(done) {
127127
const req = dns.resolve(
128128
'sip2sip.info',
129129
'ANY',
130-
common.mustCall(function(err, ret) {
131-
assert.ifError(err);
130+
common.mustSucceed((ret) => {
132131
validateResult(ret);
133132
done();
134133
}));
@@ -147,8 +146,7 @@ TEST(async function test_google_for_cname_and_srv(done) {
147146
const req = dns.resolve(
148147
'_jabber._tcp.google.com',
149148
'ANY',
150-
common.mustCall(function(err, ret) {
151-
assert.ifError(err);
149+
common.mustSucceed((ret) => {
152150
validateResult(ret);
153151
done();
154152
}));
@@ -167,8 +165,7 @@ TEST(async function test_ptr(done) {
167165
const req = dns.resolve(
168166
'8.8.8.8.in-addr.arpa',
169167
'ANY',
170-
common.mustCall(function(err, ret) {
171-
assert.ifError(err);
168+
common.mustSucceed((ret) => {
172169
validateResult(ret);
173170
done();
174171
}));
Collapse file

‎test/internet/test-dns-ipv4.js‎

Copy file name to clipboardExpand all lines: test/internet/test-dns-ipv4.js
+10-20Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ TEST(async function test_resolve4(done) {
5050

5151
const req = dns.resolve4(
5252
addresses.INET4_HOST,
53-
common.mustCall((err, ips) => {
54-
assert.ifError(err);
53+
common.mustSucceed((ips) => {
5554
validateResult(ips);
5655
done();
5756
}));
@@ -73,8 +72,7 @@ TEST(async function test_reverse_ipv4(done) {
7372

7473
const req = dns.reverse(
7574
addresses.INET4_IP,
76-
common.mustCall((err, domains) => {
77-
assert.ifError(err);
75+
common.mustSucceed((domains) => {
7876
validateResult(domains);
7977
done();
8078
}));
@@ -92,8 +90,7 @@ TEST(async function test_lookup_ipv4_explicit(done) {
9290

9391
const req = dns.lookup(
9492
addresses.INET4_HOST, 4,
95-
common.mustCall((err, ip, family) => {
96-
assert.ifError(err);
93+
common.mustSucceed((ip, family) => {
9794
validateResult({ address: ip, family });
9895
done();
9996
}));
@@ -111,8 +108,7 @@ TEST(async function test_lookup_ipv4_implicit(done) {
111108

112109
const req = dns.lookup(
113110
addresses.INET4_HOST,
114-
common.mustCall((err, ip, family) => {
115-
assert.ifError(err);
111+
common.mustSucceed((ip, family) => {
116112
validateResult({ address: ip, family });
117113
done();
118114
}));
@@ -130,8 +126,7 @@ TEST(async function test_lookup_ipv4_explicit_object(done) {
130126

131127
const req = dns.lookup(addresses.INET4_HOST, {
132128
family: 4
133-
}, common.mustCall((err, ip, family) => {
134-
assert.ifError(err);
129+
}, common.mustSucceed((ip, family) => {
135130
validateResult({ address: ip, family });
136131
done();
137132
}));
@@ -151,8 +146,7 @@ TEST(async function test_lookup_ipv4_hint_addrconfig(done) {
151146

152147
const req = dns.lookup(addresses.INET4_HOST, {
153148
hints: dns.ADDRCONFIG
154-
}, common.mustCall((err, ip, family) => {
155-
assert.ifError(err);
149+
}, common.mustSucceed((ip, family) => {
156150
validateResult({ address: ip, family });
157151
done();
158152
}));
@@ -169,8 +163,7 @@ TEST(async function test_lookup_ip_ipv4(done) {
169163
validateResult(await dnsPromises.lookup('127.0.0.1'));
170164

171165
const req = dns.lookup('127.0.0.1',
172-
common.mustCall((err, ip, family) => {
173-
assert.ifError(err);
166+
common.mustSucceed((ip, family) => {
174167
validateResult({ address: ip, family });
175168
done();
176169
}));
@@ -187,8 +180,7 @@ TEST(async function test_lookup_localhost_ipv4(done) {
187180
validateResult(await dnsPromises.lookup('localhost', 4));
188181

189182
const req = dns.lookup('localhost', 4,
190-
common.mustCall((err, ip, family) => {
191-
assert.ifError(err);
183+
common.mustSucceed((ip, family) => {
192184
validateResult({ address: ip, family });
193185
done();
194186
}));
@@ -215,8 +207,7 @@ TEST(async function test_lookup_all_ipv4(done) {
215207
const req = dns.lookup(
216208
addresses.INET4_HOST,
217209
{ all: true, family: 4 },
218-
common.mustCall((err, ips) => {
219-
assert.ifError(err);
210+
common.mustSucceed((ips) => {
220211
validateResult(ips);
221212
done();
222213
})
@@ -236,8 +227,7 @@ TEST(async function test_lookupservice_ip_ipv4(done) {
236227

237228
const req = dns.lookupService(
238229
'127.0.0.1', 80,
239-
common.mustCall((err, hostname, service) => {
240-
assert.ifError(err);
230+
common.mustSucceed((hostname, service) => {
241231
validateResult({ hostname, service });
242232
done();
243233
})
Collapse file

‎test/internet/test-dns-ipv6.js‎

Copy file name to clipboardExpand all lines: test/internet/test-dns-ipv6.js
+6-12Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ TEST(async function test_resolve6(done) {
5252

5353
const req = dns.resolve6(
5454
addresses.INET6_HOST,
55-
common.mustCall((err, ips) => {
56-
assert.ifError(err);
55+
common.mustSucceed((ips) => {
5756
validateResult(ips);
5857
done();
5958
}));
@@ -74,8 +73,7 @@ TEST(async function test_reverse_ipv6(done) {
7473

7574
const req = dns.reverse(
7675
addresses.INET6_IP,
77-
common.mustCall((err, domains) => {
78-
assert.ifError(err);
76+
common.mustSucceed((domains) => {
7977
validateResult(domains);
8078
done();
8179
}));
@@ -94,8 +92,7 @@ TEST(async function test_lookup_ipv6_explicit(done) {
9492
const req = dns.lookup(
9593
addresses.INET6_HOST,
9694
6,
97-
common.mustCall((err, ip, family) => {
98-
assert.ifError(err);
95+
common.mustSucceed((ip, family) => {
9996
validateResult({ address: ip, family });
10097
done();
10198
}));
@@ -126,8 +123,7 @@ TEST(async function test_lookup_ipv6_explicit_object(done) {
126123

127124
const req = dns.lookup(addresses.INET6_HOST, {
128125
family: 6
129-
}, common.mustCall((err, ip, family) => {
130-
assert.ifError(err);
126+
}, common.mustSucceed((ip, family) => {
131127
validateResult({ address: ip, family });
132128
done();
133129
}));
@@ -173,8 +169,7 @@ TEST(async function test_lookup_ip_ipv6(done) {
173169

174170
const req = dns.lookup(
175171
'::1',
176-
common.mustCall((err, ip, family) => {
177-
assert.ifError(err);
172+
common.mustSucceed((ip, family) => {
178173
validateResult({ address: ip, family });
179174
done();
180175
}));
@@ -202,8 +197,7 @@ TEST(async function test_lookup_all_ipv6(done) {
202197
const req = dns.lookup(
203198
addresses.INET6_HOST,
204199
{ all: true, family: 6 },
205-
common.mustCall((err, ips) => {
206-
assert.ifError(err);
200+
common.mustSucceed((ips) => {
207201
validateResult(ips);
208202
done();
209203
})
Collapse file

‎test/internet/test-http2-issue-32922.js‎

Copy file name to clipboardExpand all lines: test/internet/test-http2-issue-32922.js
+3-10Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
43

54
if (!common.hasCrypto)
65
common.skip('missing crypto');
@@ -29,9 +28,7 @@ function normalSession(cb) {
2928
});
3029
});
3130
}
32-
normalSession(common.mustCall(function(err) {
33-
assert.ifError(err);
34-
}));
31+
normalSession(common.mustSucceed());
3532

3633
// Create a session using a socket that has not yet finished connecting
3734
function socketNotFinished(done) {
@@ -52,9 +49,7 @@ function socketNotFinished(done) {
5249
});
5350
});
5451
}
55-
socketNotFinished(common.mustCall(function(err) {
56-
assert.ifError(err);
57-
}));
52+
socketNotFinished(common.mustSucceed());
5853

5954
// Create a session using a socket that has finished connecting
6055
function socketFinished(done) {
@@ -75,6 +70,4 @@ function socketFinished(done) {
7570
});
7671
});
7772
}
78-
socketFinished(common.mustCall(function(err) {
79-
assert.ifError(err);
80-
}));
73+
socketFinished(common.mustSucceed());
Collapse file

‎test/parallel/test-c-ares.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-c-ares.js
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,17 @@ const dnsPromises = dns.promises;
4343
})();
4444

4545
// Try resolution without hostname.
46-
dns.lookup(null, common.mustCall((error, result, addressType) => {
47-
assert.ifError(error);
46+
dns.lookup(null, common.mustSucceed((result, addressType) => {
4847
assert.strictEqual(result, null);
4948
assert.strictEqual(addressType, 4);
5049
}));
5150

52-
dns.lookup('127.0.0.1', common.mustCall((error, result, addressType) => {
53-
assert.ifError(error);
51+
dns.lookup('127.0.0.1', common.mustSucceed((result, addressType) => {
5452
assert.strictEqual(result, '127.0.0.1');
5553
assert.strictEqual(addressType, 4);
5654
}));
5755

58-
dns.lookup('::1', common.mustCall((error, result, addressType) => {
59-
assert.ifError(error);
56+
dns.lookup('::1', common.mustSucceed((result, addressType) => {
6057
assert.strictEqual(result, '::1');
6158
assert.strictEqual(addressType, 6);
6259
}));
@@ -86,8 +83,7 @@ dns.lookup('::1', common.mustCall((error, result, addressType) => {
8683
// so we disable this test on Windows.
8784
// IBMi reports `ENOTFOUND` when get hostname by address 127.0.0.1
8885
if (!common.isWindows && !common.isIBMi) {
89-
dns.reverse('127.0.0.1', common.mustCall(function(error, domains) {
90-
assert.ifError(error);
86+
dns.reverse('127.0.0.1', common.mustSucceed((domains) => {
9187
assert.ok(Array.isArray(domains));
9288
}));
9389

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.