Skip to content

Commit 2c4ebe0

Browse files
committed
test: use .then(common.mustCall()) for all async IIFEs
This makes sure that all async functions finish as expected. PR-URL: #34363 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent da95dd7 commit 2c4ebe0

35 files changed

+55
-61
lines changed

test/es-module/test-esm-error-cache.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55

66
const file = '../fixtures/syntax/bad_syntax.mjs';
@@ -23,4 +23,4 @@ let error;
2323
return true;
2424
}
2525
);
26-
})();
26+
})().then(common.mustCall());

test/es-module/test-esm-import-meta-resolve.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Flags: --experimental-import-meta-resolve
2-
import '../common/index.mjs';
2+
import { mustCall } from '../common/index.mjs';
33
import assert from 'assert';
44

55
const dirname = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1);
@@ -21,4 +21,4 @@ const fixtures = dirname.slice(0, dirname.lastIndexOf('/', dirname.length - 2) +
2121
assert.strictEqual(await import.meta.resolve('../fixtures/'), fixtures);
2222
assert.strictEqual(await import.meta.resolve('baz/', fixtures),
2323
fixtures + 'node_modules/baz/');
24-
})();
24+
})().then(mustCall());

test/internet/test-dns-promises-resolve.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44

55
const dnsPromises = require('dns').promises;
@@ -38,5 +38,5 @@ const dnsPromises = require('dns').promises;
3838
const result = await dnsPromises.resolve('example.org', rrtype);
3939
assert.ok(result !== undefined);
4040
assert.ok(result.length > 0);
41-
})();
41+
})().then(common.mustCall());
4242
}

test/internet/test-dns-txt-sigsegv.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const dns = require('dns');
55
const dnsPromises = dns.promises;
66

77
(async function() {
88
const result = await dnsPromises.resolveTxt('www.microsoft.com');
99
assert.strictEqual(result.length, 0);
10-
})();
10+
})().then(common.mustCall());
1111

1212
dns.resolveTxt('www.microsoft.com', function(err, records) {
1313
assert.strictEqual(err, null);

test/internet/test-dns.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,4 +708,4 @@ dns.lookupService('0.0.0.0', 0, common.mustCall());
708708
(async function() {
709709
await dnsPromises.lookup(addresses.INET6_HOST, 6);
710710
await dnsPromises.lookup(addresses.INET_HOST, {});
711-
})();
711+
})().then(common.mustCall());

test/parallel/test-c-ares.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const dnsPromises = dns.promises;
4040
res = await dnsPromises.lookup('::1');
4141
assert.strictEqual(res.address, '::1');
4242
assert.strictEqual(res.family, 6);
43-
})();
43+
})().then(common.mustCall());
4444

4545
// Try resolution without callback
4646

@@ -94,5 +94,5 @@ if (!common.isWindows && !common.isIBMi) {
9494

9595
(async function() {
9696
assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1')));
97-
})();
97+
})().then(common.mustCall());
9898
}

test/parallel/test-child-process-spawn-args.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ const expectedResult = tmpdir.path.trim().toLowerCase();
5252
);
5353

5454
assert.deepStrictEqual([...new Set(results)], [expectedResult]);
55-
})();
55+
})().then(common.mustCall());

test/parallel/test-dns-lookup-promises.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,5 @@ async function lookupallNegative() {
135135
lookupNegative(),
136136
lookupallPositive(),
137137
lookupallNegative()
138-
]).then(common.mustCall());
139-
})();
138+
]);
139+
})().then(common.mustCall());

test/parallel/test-dns-lookup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ assert.throws(() => {
109109
all: false
110110
});
111111
assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 });
112-
})();
112+
})().then(common.mustCall());
113113

114114
dns.lookup(false, {
115115
hints: 0,

test/parallel/test-dns-setservers-type-check.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const promiseResolver = new dns.promises.Resolver();
9595
// This should not throw any error.
9696
(async () => {
9797
setServers([ '127.0.0.1' ]);
98-
})();
98+
})().then(common.mustCall());
9999

100100
[
101101
[null],

test/parallel/test-dns.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ dns.lookup('', {
276276
await dnsPromises.lookup('', {
277277
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
278278
});
279-
})();
279+
})().then(common.mustCall());
280280

281281
{
282282
const err = {
@@ -450,7 +450,7 @@ assert.throws(() => {
450450
cases.shift();
451451
nextCase();
452452
}));
453-
})();
453+
})().then(common.mustCall());
454454

455455
}));
456456
}

test/parallel/test-fs-copyfile-respect-permissions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function beforeEach() {
4949
const { source, dest, check } = beforeEach();
5050
(async () => {
5151
await assert.rejects(fs.promises.copyFile(source, dest), check);
52-
})();
52+
})().then(common.mustCall());
5353
}
5454

5555
// Test callback API.

test/parallel/test-fs-read-empty-buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ assert.throws(
3838
'Received Uint8Array(0) []'
3939
}
4040
);
41-
})();
41+
})().then(common.mustCall());

test/parallel/test-fs-readdir-types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fs.readdir(readdirDir, {
7777
withFileTypes: true
7878
});
7979
assertDirents(dirents);
80-
})();
80+
})().then(common.mustCall());
8181

8282
// Check for correct types when the binding returns unknowns
8383
const UNKNOWN = constants.UV_DIRENT_UNKNOWN;

test/parallel/test-fs-readv-promises.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
2-
3-
require('../common');
2+
const common = require('../common');
43
const assert = require('assert');
54
const path = require('path');
65
const fs = require('fs').promises;
@@ -64,4 +63,4 @@ const allocateEmptyBuffers = (combinedLength) => {
6463
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
6564
handle.close();
6665
}
67-
})();
66+
})().then(common.mustCall());

test/parallel/test-fs-rmdir-recursive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function removeAsync(dir) {
149149

150150
// Attempted removal should fail now because the directory is gone.
151151
assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
152-
})();
152+
})().then(common.mustCall());
153153

154154
// Test input validation.
155155
{

test/parallel/test-fs-stat-bigint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,4 @@ if (!common.isWindows) {
185185
const allowableDelta = Math.ceil(Number(endTime - startTime) / 1e6);
186186
verifyStats(bigintStats, numStats, allowableDelta);
187187
await handle.close();
188-
})();
188+
})().then(common.mustCall());

test/parallel/test-fs-writev-promises.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
2-
3-
require('../common');
2+
const common = require('../common');
43
const assert = require('assert');
54
const path = require('path');
65
const fs = require('fs').promises;
@@ -48,4 +47,4 @@ tmpdir.refresh();
4847
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
4948
handle.close();
5049
}
51-
})();
50+
})().then(common.mustCall());

test/parallel/test-inspect-publish-uid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { spawnSync } = require('child_process');
1010
await testArg('stderr');
1111
await testArg('http');
1212
await testArg('http,stderr');
13-
})();
13+
})().then(common.mustCall());
1414

1515
async function testArg(argValue) {
1616
console.log('Checks ' + argValue + '..');

test/parallel/test-internal-module-wrap.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
2-
31
// Flags: --expose-internals
4-
5-
require('../common');
2+
'use strict';
3+
const common = require('../common');
64
const assert = require('assert');
75

86
const { internalBinding } = require('internal/test/binding');
@@ -26,4 +24,4 @@ const bar = new ModuleWrap('bar', undefined, 'export const five = 5', 0, 0);
2624

2725
assert.strictEqual(await foo.evaluate(-1, false), undefined);
2826
assert.strictEqual(foo.getNamespace().five, 5);
29-
})();
27+
})().then(common.mustCall());

test/parallel/test-repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ const tcpTests = [
827827
socket.end();
828828
}
829829
common.allowGlobals(...Object.values(global));
830-
})();
830+
})().then(common.mustCall());
831831

832832
function startTCPRepl() {
833833
let resolveSocket, resolveReplServer;

test/parallel/test-util-inspect-namespace.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
2-
31
// Flags: --experimental-vm-modules
4-
5-
require('../common');
2+
'use strict';
3+
const common = require('../common');
64
const assert = require('assert');
75

86
const { SourceTextModule } = require('vm');
@@ -16,4 +14,4 @@ const { inspect } = require('util');
1614
'[Module] { a: <uninitialized>, b: undefined }');
1715
await m.evaluate();
1816
assert.strictEqual(inspect(m.namespace), '[Module] { a: 1, b: 2 }');
19-
})();
17+
})().then(common.mustCall());

test/parallel/test-util-promisify.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const stat = promisify(fs.stat);
131131
(async () => {
132132
const value = await promisify(fn)(null, 42);
133133
assert.strictEqual(value, 42);
134-
})();
134+
})().then(common.mustCall());
135135
}
136136

137137
{
@@ -159,7 +159,7 @@ const stat = promisify(fs.stat);
159159
await fn();
160160
await Promise.resolve();
161161
return assert.strictEqual(stack, err.stack);
162-
})();
162+
})().then(common.mustCall());
163163
}
164164

165165
{

test/parallel/test-util-types.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Flags: --experimental-vm-modules --expose-internals
22
'use strict';
3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55
const { types, inspect } = require('util');
66
const vm = require('vm');
@@ -280,4 +280,4 @@ for (const [ value, _method ] of [
280280
await m.link(() => 0);
281281
await m.evaluate();
282282
assert.ok(types.isModuleNamespaceObject(m.namespace));
283-
})();
283+
})().then(common.mustCall());

test/parallel/test-vm-module-basic.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const util = require('util');
3232
baz: 'bar',
3333
typeofProcess: 'undefined'
3434
});
35-
}());
35+
}().then(common.mustCall()));
3636

3737
(async () => {
3838
const m = new SourceTextModule(`
@@ -45,14 +45,14 @@ const util = require('util');
4545
assert.strictEqual(global.vmResultTypeofProcess, '[object process]');
4646
delete global.vmResultFoo;
4747
delete global.vmResultTypeofProcess;
48-
})();
48+
})().then(common.mustCall());
4949

5050
(async () => {
5151
const m = new SourceTextModule('while (true) {}');
5252
await m.link(common.mustNotCall());
5353
await m.evaluate({ timeout: 500 })
5454
.then(() => assert(false), () => {});
55-
})();
55+
})().then(common.mustCall());
5656

5757
// Check the generated identifier for each module
5858
(async () => {
@@ -65,7 +65,7 @@ const util = require('util');
6565
assert.strictEqual(m2.identifier, 'vm:module(1)');
6666
const m3 = new SourceTextModule('3', { context: context2 });
6767
assert.strictEqual(m3.identifier, 'vm:module(0)');
68-
})();
68+
})().then(common.mustCall());
6969

7070
// Check inspection of the instance
7171
{

test/parallel/test-vm-module-errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,4 @@ const finished = common.mustCall();
233233
await checkInvalidOptionForEvaluate();
234234
checkInvalidCachedData();
235235
finished();
236-
})();
236+
})().then(common.mustCall());

test/parallel/test-vm-module-import-meta.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ async function testInvalid() {
4141
(async () => {
4242
await testBasic();
4343
await testInvalid();
44-
})();
44+
})().then(common.mustCall());

test/parallel/test-vm-module-link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,4 @@ const finished = common.mustCall();
133133
await circular();
134134
await circular2();
135135
finished();
136-
})();
136+
})().then(common.mustCall());

test/parallel/test-vm-module-reevaluate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ const finished = common.mustCall();
4848
}
4949

5050
finished();
51-
})();
51+
})().then(common.mustCall());

test/parallel/test-vm-module-synthetic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ const assert = require('assert');
6565
code: 'ERR_VM_MODULE_STATUS',
6666
});
6767
}
68-
})();
68+
})().then(common.mustCall());

test/parallel/test-zlib-empty-buffer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const zlib = require('zlib');
44
const { inspect, promisify } = require('util');
55
const assert = require('assert');
@@ -23,4 +23,4 @@ const emptyBuffer = Buffer.alloc(0);
2323
`Expected ${inspect(compressed)} to match ${inspect(decompressed)} ` +
2424
`to match for ${method}`);
2525
}
26-
})();
26+
})().then(common.mustCall());

test/sequential/test-inspector-async-call-stack-abort.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (process.argv[2] === 'child') {
2525
await session.post('Debugger.setAsyncCallStackDepth', { maxDepth: 42 });
2626
strictEqual(enabled, 1);
2727
throw new Error(eyecatcher);
28-
})();
28+
})().finally(common.mustCall());
2929
} else {
3030
const { spawnSync } = require('child_process');
3131
const options = { encoding: 'utf8' };

test/wasi/test-wasi-stdio.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Flags: --experimental-wasi-unstable-preview1 --experimental-wasm-bigint
22
'use strict';
3-
require('../common');
3+
const common = require('../common');
44
const tmpdir = require('../common/tmpdir');
55
const { strictEqual } = require('assert');
66
const { closeSync, openSync, readFileSync, writeFileSync } = require('fs');
@@ -31,4 +31,4 @@ const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
3131
closeSync(stderr);
3232
strictEqual(readFileSync(stdoutFile, 'utf8').trim(), 'x'.repeat(31));
3333
strictEqual(readFileSync(stderrFile, 'utf8').trim(), '');
34-
})();
34+
})().then(common.mustCall());

test/wasi/test-wasi-symlinks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (process.argv[2] === 'wasi-child') {
2525
const { instance } = await WebAssembly.instantiate(buffer, importObject);
2626

2727
wasi.start(instance);
28-
})();
28+
})().then(common.mustCall());
2929
} else {
3030
if (!common.canCreateSymLink()) {
3131
common.skip('insufficient privileges');

test/wasi/test-wasi.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if (process.argv[2] === 'wasi-child') {
3030
const { instance } = await WebAssembly.instantiate(buffer, importObject);
3131

3232
wasi.start(instance);
33-
})();
33+
})().then(common.mustCall());
3434
} else {
3535
const assert = require('assert');
3636
const cp = require('child_process');

0 commit comments

Comments
 (0)