Skip to content

Commit 2856475

Browse files
authored
test: ensure assertions are reached on more tests
PR-URL: #60634 Reviewed-By: Colin Ihrig <[email protected]>
1 parent 597fc3a commit 2856475

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+246
-292
lines changed

test/eslint.config_partial.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export default [
197197
Array.from({ length: 4 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
198198
},${
199199
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
200-
Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
200+
Array.from({ length: 5 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
201201
}}.{js,mjs,cjs}`,
202202
],
203203
rules: {

test/parallel/test-vfs.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const common = require('../common');
66
const Module = require('module');
77
const fs = require('fs');
88
const tmpdir = require('../common/tmpdir');
9-
const { deepStrictEqual, ok, strictEqual, throws } = require('assert');
9+
const assert = require('assert');
1010
const { join } = require('path');
1111

1212
const directory = tmpdir.resolve('directory');
@@ -17,20 +17,20 @@ tmpdir.refresh();
1717
fs.writeFileSync(file, "module.exports = { a: 'b' }");
1818
fs.mkdirSync(directory);
1919

20-
strictEqual(Module._stat(directory), 1);
21-
ok(Module._stat(doesNotExist) < 0);
22-
strictEqual(Module._stat(file), 0);
20+
assert.strictEqual(Module._stat(directory), 1);
21+
assert.ok(Module._stat(doesNotExist) < 0);
22+
assert.strictEqual(Module._stat(file), 0);
2323

2424
const vfsDirectory = join(process.execPath, 'directory');
2525
const vfsDoesNotExist = join(process.execPath, 'does-not-exist');
2626
const vfsFile = join(process.execPath, 'file.js');
2727

28-
ok(Module._stat(vfsDirectory) < 0);
29-
ok(Module._stat(vfsDoesNotExist) < 0);
30-
ok(Module._stat(vfsFile) < 0);
28+
assert.ok(Module._stat(vfsDirectory) < 0);
29+
assert.ok(Module._stat(vfsDoesNotExist) < 0);
30+
assert.ok(Module._stat(vfsFile) < 0);
3131

32-
deepStrictEqual(require(file), { a: 'b' });
33-
throws(() => require(vfsFile), { code: 'MODULE_NOT_FOUND' });
32+
assert.deepStrictEqual(require(file), { a: 'b' });
33+
assert.throws(() => require(vfsFile), { code: 'MODULE_NOT_FOUND' });
3434

3535
common.expectWarning(
3636
'ExperimentalWarning',
@@ -75,15 +75,15 @@ fs.realpathSync = function realpathSync(pathArgument, options) {
7575
return pathArgument;
7676
};
7777

78-
strictEqual(Module._stat(directory), 1);
79-
ok(Module._stat(doesNotExist) < 0);
80-
strictEqual(Module._stat(file), 0);
78+
assert.strictEqual(Module._stat(directory), 1);
79+
assert.ok(Module._stat(doesNotExist) < 0);
80+
assert.strictEqual(Module._stat(file), 0);
8181

82-
strictEqual(Module._stat(vfsDirectory), 1);
83-
ok(Module._stat(vfsDoesNotExist) < 0);
84-
strictEqual(Module._stat(vfsFile), 0);
82+
assert.strictEqual(Module._stat(vfsDirectory), 1);
83+
assert.ok(Module._stat(vfsDoesNotExist) < 0);
84+
assert.strictEqual(Module._stat(vfsFile), 0);
8585

86-
strictEqual(Module._stat(process.execPath), 1);
86+
assert.strictEqual(Module._stat(process.execPath), 1);
8787

88-
deepStrictEqual(require(file), { a: 'b' });
89-
deepStrictEqual(require(vfsFile), { x: 'y' });
88+
assert.deepStrictEqual(require(file), { a: 'b' });
89+
assert.deepStrictEqual(require(vfsFile), { x: 'y' });

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ const util = require('util');
166166
const module = new SyntheticModule([], () => {});
167167
module.link(() => {});
168168
const f = compileFunction('return import("x")', [], {
169-
importModuleDynamically(specifier, referrer) {
169+
importModuleDynamically: common.mustCall((specifier, referrer) => {
170170
assert.strictEqual(specifier, 'x');
171171
assert.strictEqual(referrer, f);
172172
return module;
173-
},
173+
}),
174174
});
175175
f().then((ns) => {
176176
assert.strictEqual(ns, module.namespace);
177-
});
177+
}).then(common.mustCall());
178178
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ async function asserts() {
144144
const m = new SourceTextModule(`
145145
import "foo" with { n1: 'v1', n2: 'v2' };
146146
`, { identifier: 'm' });
147-
await m.link((s, r, p) => {
147+
await m.link(common.mustCall((s, r, p) => {
148148
assert.strictEqual(s, 'foo');
149149
assert.strictEqual(r.identifier, 'm');
150150
assert.strictEqual(p.attributes.n1, 'v1');
151151
assert.strictEqual(p.assert.n1, 'v1');
152152
assert.strictEqual(p.attributes.n2, 'v2');
153153
assert.strictEqual(p.assert.n2, 'v2');
154154
return new SourceTextModule('');
155-
});
155+
}));
156156
}
157157

158158
const finished = common.mustCall();

test/parallel/test-wasm.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '../common/index.mjs';
2-
import { strictEqual } from 'node:assert';
2+
import assert from 'node:assert';
33
import { readSync } from '../common/fixtures.mjs';
44

55
// Test Wasm JSPI
@@ -40,5 +40,5 @@ import { readSync } from '../common/fixtures.mjs';
4040
});
4141

4242
const promisingExport = WebAssembly.promising(instance.exports.test);
43-
strictEqual(await promisingExport(10), 52);
43+
assert.strictEqual(await promisingExport(10), 52);
4444
}

test/parallel/test-watch-file-shared-dependency.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ describe('watch file with shared dependency', () => {
3434
const controller = new AbortController();
3535
const watcher = new FilesWatcher({ signal: controller.signal });
3636

37-
watcher.on('changed', ({ owners }) => {
37+
watcher.on('changed', common.mustCall(({ owners }) => {
3838
if (owners.size !== 2) return;
3939

4040
// If this code is never reached the test times out.
4141
assert.ok(owners.has(fixturePaths['test.js']));
4242
assert.ok(owners.has(fixturePaths['test-2.js']));
4343
controller.abort();
4444
done();
45-
});
45+
}));
4646
watcher.filterFile(fixturePaths['test.js']);
4747
watcher.filterFile(fixturePaths['test-2.js']);
4848
watcher.filterFile(fixturePaths['dependency.js'], fixturePaths['test.js']);

test/parallel/test-weakref.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
// Flags: --expose-gc
44

5-
require('../common');
5+
const common = require('../common');
66
const assert = require('assert');
77

88
const w = new globalThis.WeakRef({});
99

10-
setTimeout(() => {
10+
setTimeout(common.mustCall(() => {
1111
globalThis.gc();
1212
assert.strictEqual(w.deref(), undefined);
13-
}, 200);
13+
}), 200);

test/parallel/test-web-locks-query.js

Lines changed: 5 additions & 5 deletions
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 { describe, it } = require('node:test');
55
const assert = require('node:assert');
66
const { Worker } = require('worker_threads');
@@ -26,7 +26,7 @@ describe('Web Locks - query missing WPT tests', () => {
2626
worker.once('message', resolve);
2727
});
2828

29-
await navigator.locks.request('different-contexts-resource', { mode: 'shared' }, async (lock) => {
29+
await navigator.locks.request('different-contexts-resource', { mode: 'shared' }, common.mustCall(async (lock) => {
3030
const state = await navigator.locks.query();
3131
const heldLocks = state.held.filter((l) => l.name === 'different-contexts-resource');
3232

@@ -35,7 +35,7 @@ describe('Web Locks - query missing WPT tests', () => {
3535
assert.notStrictEqual(mainClientId, workerResult.clientId);
3636

3737
worker.postMessage('release');
38-
});
38+
}));
3939

4040
await worker.terminate();
4141
});
@@ -67,7 +67,7 @@ describe('Web Locks - query missing WPT tests', () => {
6767
});
6868
assert.strictEqual(step1.acquired, 'resource1');
6969

70-
await navigator.locks.request('deadlock-resource-2', async (lock2) => {
70+
await navigator.locks.request('deadlock-resource-2', common.mustCall(async (lock2) => {
7171
worker.postMessage('try-resource2');
7272

7373
const step2 = await new Promise((resolve) => {
@@ -85,7 +85,7 @@ describe('Web Locks - query missing WPT tests', () => {
8585
assert(resource2Lock);
8686

8787
worker.postMessage('release');
88-
});
88+
}));
8989

9090
await worker.terminate();
9191
});

test/parallel/test-web-locks.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ describe('Web Locks with worker threads', () => {
2626
assert.strictEqual(result.success, true);
2727
await worker.terminate();
2828

29-
await navigator.locks.request('exclusive-test', async (lock) => {
29+
await navigator.locks.request('exclusive-test', common.mustCall(async (lock) => {
3030
assert.strictEqual(lock.mode, 'exclusive');
3131
assert.strictEqual(lock.name, 'exclusive-test');
32-
});
32+
}));
3333
});
3434

3535
it('should handle shared locks', async () => {
@@ -48,41 +48,43 @@ describe('Web Locks with worker threads', () => {
4848
});
4949
assert.strictEqual(result.success, true);
5050

51-
await navigator.locks.request('shared-test', { mode: 'shared' }, async (lock1) => {
52-
await navigator.locks.request('shared-test', { mode: 'shared' }, async (lock2) => {
51+
await navigator.locks.request('shared-test', { mode: 'shared' }, common.mustCall(async (lock1) => {
52+
await navigator.locks.request('shared-test', { mode: 'shared' }, common.mustCall(async (lock2) => {
5353
assert.strictEqual(lock1.mode, 'shared');
5454
assert.strictEqual(lock2.mode, 'shared');
55-
});
56-
});
55+
}));
56+
}));
5757

5858
await worker.terminate();
5959
});
6060

6161
it('should handle steal option - no existing lock', async () => {
62-
await navigator.locks.request('steal-simple', { steal: true }, async (lock) => {
62+
await navigator.locks.request('steal-simple', { steal: true }, common.mustCall(async (lock) => {
6363
assert.strictEqual(lock.name, 'steal-simple');
6464
assert.strictEqual(lock.mode, 'exclusive');
65-
});
65+
}));
6666
});
6767

6868
it('should handle steal option - existing lock', async () => {
6969
let originalLockRejected = false;
7070

71-
const originalLockPromise = navigator.locks.request('steal-target', async (lock) => {
71+
const originalLockPromise = navigator.locks.request('steal-target', common.mustCall(async (lock) => {
7272
assert.strictEqual(lock.name, 'steal-target');
7373
return 'original-completed';
74-
}).catch((err) => {
74+
})).catch(common.mustCall((err) => {
7575
originalLockRejected = true;
7676
assert.strictEqual(err.name, 'AbortError');
7777
assert.strictEqual(err.message, 'The operation was aborted');
7878
return 'original-rejected';
79-
});
79+
}));
8080

81-
const stealResult = await navigator.locks.request('steal-target', { steal: true }, async (stolenLock) => {
82-
assert.strictEqual(stolenLock.name, 'steal-target');
83-
assert.strictEqual(stolenLock.mode, 'exclusive');
84-
return 'steal-completed';
85-
});
81+
const stealResult = await navigator.locks.request(
82+
'steal-target', { steal: true },
83+
common.mustCall(async (stolenLock) => {
84+
assert.strictEqual(stolenLock.name, 'steal-target');
85+
assert.strictEqual(stolenLock.mode, 'exclusive');
86+
return 'steal-completed';
87+
}));
8688

8789
assert.strictEqual(stealResult, 'steal-completed');
8890

@@ -92,7 +94,7 @@ describe('Web Locks with worker threads', () => {
9294
});
9395

9496
it('should handle ifAvailable option', async () => {
95-
await navigator.locks.request('ifavailable-test', async () => {
97+
await navigator.locks.request('ifavailable-test', common.mustCall(async () => {
9698
const result = await navigator.locks.request('ifavailable-test', { ifAvailable: true }, (lock) => {
9799
return lock; // should be null
98100
});
@@ -105,7 +107,7 @@ describe('Web Locks with worker threads', () => {
105107
});
106108

107109
assert.strictEqual(availableResult, true);
108-
});
110+
}));
109111
});
110112

111113
it('should handle AbortSignal', async () => {
@@ -179,18 +181,18 @@ describe('Web Locks with worker threads', () => {
179181
const als = new AsyncLocalStorage();
180182
const store = { id: 'lock' };
181183

182-
als.run(store, () => {
184+
als.run(store, common.mustCall(() => {
183185
navigator.locks
184-
.request('als-context-test', async () => {
186+
.request('als-context-test', common.mustCall(async () => {
185187
assert.strictEqual(als.getStore(), store);
186-
})
188+
}))
187189
.then(common.mustCall());
188-
});
190+
}));
189191
});
190192

191193
it('should clean up when worker is terminated with a pending lock', async () => {
192194
// Acquire the lock in the main thread so that the worker's request will be pending
193-
await navigator.locks.request('cleanup-test', async () => {
195+
await navigator.locks.request('cleanup-test', common.mustCall(async () => {
194196
// Launch a worker that requests the same lock
195197
const worker = new Worker(`
196198
const { parentPort } = require('worker_threads');
@@ -212,11 +214,11 @@ describe('Web Locks with worker threads', () => {
212214

213215
await worker.terminate();
214216

215-
});
217+
}));
216218

217219
// Request the lock again to make sure cleanup succeeded
218-
await navigator.locks.request('cleanup-test', async (lock) => {
220+
await navigator.locks.request('cleanup-test', common.mustCall(async (lock) => {
219221
assert.strictEqual(lock.name, 'cleanup-test');
220-
});
222+
}));
221223
});
222224
});

test/parallel/test-webcrypto-cryptokey-workers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ async function doSig(key) {
3030
}
3131

3232
if (process.env.HAS_STARTED_WORKER) {
33-
return parentPort.once('message', (key) => {
33+
return parentPort.once('message', common.mustCall((key) => {
3434
assert.strictEqual(key.algorithm.name, 'HMAC');
3535
doSig(key).then(common.mustCall());
36-
});
36+
}));
3737
}
3838

3939
// Don't use isMainThread to allow running this test inside a worker.

0 commit comments

Comments
 (0)