Skip to content

Commit 89ee6ab

Browse files
addaleaxtargos
authored andcommitted
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 <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 55fc206 commit 89ee6ab

34 files changed

+54
-60
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
@@ -748,4 +748,4 @@ dns.lookupService('0.0.0.0', 0, common.mustCall());
748748
(async function() {
749749
await dnsPromises.lookup(addresses.INET6_HOST, 6);
750750
await dnsPromises.lookup(addresses.INET_HOST, {});
751-
})();
751+
})().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 hostname.
4646
dns.lookup(null, common.mustSucceed((result, addressType) => {
@@ -89,5 +89,5 @@ if (!common.isWindows && !common.isIBMi) {
8989

9090
(async function() {
9191
assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1')));
92-
})();
92+
})().then(common.mustCall());
9393
}

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
@@ -110,7 +110,7 @@ assert.throws(() => {
110110
all: false
111111
});
112112
assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 });
113-
})();
113+
})().then(common.mustCall());
114114

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

test/parallel/test-dns.js

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

279279
{
280280
const err = {
@@ -447,7 +447,7 @@ assert.throws(() => {
447447
cases.shift();
448448
nextCase();
449449
}));
450-
})();
450+
})().then(common.mustCall());
451451

452452
}));
453453
}

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
@@ -76,7 +76,7 @@ fs.readdir(readdirDir, {
7676
withFileTypes: true
7777
});
7878
assertDirents(dirents);
79-
})();
79+
})().then(common.mustCall());
8080

8181
// Check for correct types when the binding returns unknowns
8282
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
@@ -145,7 +145,7 @@ function removeAsync(dir) {
145145

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

150150
// Test input validation.
151151
{

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,4 @@ if (!common.isWindows) {
212212
const allowableDelta = Math.ceil(Number(endTime - startTime) / 1e6);
213213
verifyStats(bigintStats, numStats, allowableDelta);
214214
await handle.close();
215-
})();
215+
})().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
@@ -837,7 +837,7 @@ const tcpTests = [
837837
socket.end();
838838
}
839839
common.allowGlobals(...Object.values(global));
840-
})();
840+
})().then(common.mustCall());
841841

842842
function startTCPRepl() {
843843
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');
@@ -20,4 +18,4 @@ const { inspect } = require('util');
2018
inspect(m.namespace),
2119
'[Module: null prototype] { a: 1, b: 2 }'
2220
);
23-
})();
21+
})().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
@@ -132,4 +132,4 @@ const finished = common.mustCall();
132132
await circular();
133133
await circular2();
134134
finished();
135-
})();
135+
})().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)