Skip to content

Commit 582e88a

Browse files
committed
test: ensure assertions are reached on all tests
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #64716 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent abce850 commit 582e88a

234 files changed

Lines changed: 1711 additions & 2260 deletions

File tree

Some content is hidden

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

test/common/fixtures.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fixtures from './fixtures.js';
22

3+
// eslint-disable-next-line no-restricted-syntax
34
const {
45
fixturesDir,
56
path,

test/eslint.config_partial.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ export default [
117117
selector: 'CallExpression:matches([callee.type="Identifier"][callee.name="assert"], [callee.type="MemberExpression"][callee.object.type="Identifier"][callee.object.name="assert"][callee.property.type="Identifier"][callee.property.name="ok"])[arguments.0.type="UnaryExpression"][arguments.0.operator="!"][arguments.0.argument.type="CallExpression"][arguments.0.argument.callee.type="MemberExpression"][arguments.0.argument.callee.object.regex][arguments.0.argument.callee.property.name="test"]',
118118
message: 'Use assert.doesNotMatch instead',
119119
},
120+
{
121+
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
122+
message: 'Do not destructure or rename `assert` nor `fixtures`',
123+
},
120124
...((fixturesSpecifier) => [
121125
{
122126
selector: `ImportDeclaration[source.value=${fixturesSpecifier.toString().replace('(\\.js)?', '\\.mjs')}]:not(${[

test/parallel/test-assert-deep.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const { mustCall, hasCrypto } = require('../common');
44
const assert = require('assert');
55
const util = require('util');
66
const { test } = require('node:test');
7-
const { AssertionError } = assert;
87
const defaultMsgStart = 'Expected values to be strictly deep-equal:\n';
98
const defaultMsgStartFull = `${defaultMsgStart}+ actual - expected`;
109

@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
688687
const b = new Array(3);
689688
a[2] = true;
690689
b[1] = true;
691-
assertNotDeepOrStrict(a, b, AssertionError, { partial: 'pass' });
690+
assertNotDeepOrStrict(a, b, assert.AssertionError, { partial: 'pass' });
692691
b[2] = true;
693692
assertNotDeepOrStrict(a, b);
694693
a[0] = true;
695-
assertNotDeepOrStrict(a, b, AssertionError, { partial: 'pass' });
694+
assertNotDeepOrStrict(a, b, assert.AssertionError, { partial: 'pass' });
696695
});
697696

698697
test('Handle sets and maps with mixed keys', () => {
@@ -715,7 +714,7 @@ test('Handle different error messages', () => {
715714
assertNotDeepOrStrict(err1, new Error('foo2'), assert.AssertionError);
716715
assertNotDeepOrStrict(err1, new TypeError('foo1'), assert.AssertionError);
717716
assertDeepAndStrictEqual(err1, new Error('foo1'));
718-
assertNotDeepOrStrict(err1, {}, AssertionError);
717+
assertNotDeepOrStrict(err1, {}, assert.AssertionError);
719718
});
720719

721720
test('Handle NaN', () => {
@@ -811,18 +810,18 @@ test('Additional tests', () => {
811810
assertDeepAndStrictEqual(new Date(2000, 3, 14), new Date(2000, 3, 14));
812811

813812
assert.throws(() => { assert.deepEqual(new Date(), new Date(2000, 3, 14)); },
814-
AssertionError,
813+
assert.AssertionError,
815814
'deepEqual(new Date(), new Date(2000, 3, 14))');
816815

817816
assert.throws(
818817
() => { assert.notDeepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14)); },
819-
AssertionError,
818+
assert.AssertionError,
820819
'notDeepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))'
821820
);
822821

823822
assert.throws(
824823
() => { assert.notDeepEqual('a'.repeat(1024), 'a'.repeat(1024)); },
825-
AssertionError,
824+
assert.AssertionError,
826825
'notDeepEqual("a".repeat(1024), "a".repeat(1024))'
827826
);
828827

@@ -861,7 +860,7 @@ test('Additional tests', () => {
861860
assert.deepEqual(4, '4');
862861
assert.deepEqual(true, 1);
863862
assert.throws(() => assert.deepEqual(4, '5'),
864-
AssertionError,
863+
assert.AssertionError,
865864
'deepEqual( 4, \'5\')');
866865
});
867866

@@ -870,7 +869,7 @@ test('Having the same number of owned properties && the same set of keys', () =>
870869
assert.deepEqual({ a: 4, b: '2' }, { a: 4, b: '2' });
871870
assert.deepEqual([4], ['4']);
872871
assert.throws(
873-
() => assert.deepEqual({ a: 4 }, { a: 4, b: true }), AssertionError);
872+
() => assert.deepEqual({ a: 4 }, { a: 4, b: true }), assert.AssertionError);
874873
assert.notDeepEqual(['a'], { 0: 'a' });
875874
assert.deepEqual({ a: 4, b: '1' }, { b: '1', a: 4 });
876875
const a1 = [1, 2, 3];
@@ -880,7 +879,7 @@ test('Having the same number of owned properties && the same set of keys', () =>
880879
a2.b = true;
881880
a2.a = 'test';
882881
assert.throws(() => assert.deepEqual(Object.keys(a1), Object.keys(a2)),
883-
AssertionError);
882+
assert.AssertionError);
884883
assertDeepAndStrictEqual(a1, a2);
885884
});
886885

@@ -946,7 +945,7 @@ test('Additional tests', () => {
946945

947946
assert.throws(
948947
() => assert.deepStrictEqual(new Date(), new Date(2000, 3, 14)),
949-
AssertionError,
948+
assert.AssertionError,
950949
'deepStrictEqual(new Date(), new Date(2000, 3, 14))'
951950
);
952951

@@ -1059,7 +1058,7 @@ test('Additional tests', () => {
10591058

10601059
assert.throws(
10611060
() => assert.deepStrictEqual([0, 1, 2, 'a', 'b'], [0, 1, 2, 'b', 'a']),
1062-
AssertionError);
1061+
assert.AssertionError);
10631062
});
10641063

10651064
test('Having the same number of owned properties && the same set of keys', () => {
@@ -1105,7 +1104,7 @@ test('Prototype check', () => {
11051104
const obj1 = new Constructor1('Ryan', 'Dahl');
11061105
let obj2 = new Constructor2('Ryan', 'Dahl');
11071106

1108-
assert.throws(() => assert.deepStrictEqual(obj1, obj2), AssertionError);
1107+
assert.throws(() => assert.deepStrictEqual(obj1, obj2), assert.AssertionError);
11091108

11101109
Constructor2.prototype = Constructor1.prototype;
11111110
obj2 = new Constructor2('Ryan', 'Dahl');
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
12621261
err[Symbol.toStringTag] = 'Foobar';
12631262
const err2 = new Error('bar');
12641263
err2[Symbol.toStringTag] = 'Foobar';
1265-
assertNotDeepOrStrict(err, err2, AssertionError);
1264+
assertNotDeepOrStrict(err, err2, assert.AssertionError);
12661265
});
12671266

12681267
test('Check for non-native errors', () => {
@@ -1281,8 +1280,8 @@ test('Check for non-native errors', () => {
12811280
test('Check for Errors with cause property', () => {
12821281
const e1 = new Error('err', { cause: new Error('cause e1') });
12831282
const e2 = new Error('err', { cause: new Error('cause e2') });
1284-
assertNotDeepOrStrict(e1, e2, AssertionError);
1285-
assertNotDeepOrStrict(e1, new Error('err'), AssertionError);
1283+
assertNotDeepOrStrict(e1, e2, assert.AssertionError);
1284+
assertNotDeepOrStrict(e1, new Error('err'), assert.AssertionError);
12861285
assertDeepAndStrictEqual(e1, new Error('err', { cause: new Error('cause e1') }));
12871286
});
12881287

@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
12941293
const e3 = new AggregateError([e1duplicate, e2], 'Aggregate Error');
12951294
const e3duplicate = new AggregateError([e1, e2], 'Aggregate Error');
12961295
const e4 = new AggregateError([e1], 'Aggregate Error');
1297-
assertNotDeepOrStrict(e1, e3, AssertionError);
1298-
assertNotDeepOrStrict(e3, e4, AssertionError);
1296+
assertNotDeepOrStrict(e1, e3, assert.AssertionError);
1297+
assertNotDeepOrStrict(e3, e4, assert.AssertionError);
12991298
assertDeepAndStrictEqual(e3, e3duplicate);
13001299
});
13011300

test/parallel/test-quic-address-validation.mjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,22 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
99
import assert from 'node:assert';
1010
import * as fixtures from '../common/fixtures.mjs';
1111

12-
const { strictEqual } = assert;
13-
const { readKey } = fixtures;
14-
1512
if (!hasQuic) {
1613
skip('QUIC is not enabled');
1714
}
1815

1916
const { listen, connect, QuicEndpoint } = await import('node:quic');
2017
const { createPrivateKey } = await import('node:crypto');
2118

22-
const key = createPrivateKey(readKey('agent1-key.pem'));
23-
const cert = readKey('agent1-cert.pem');
19+
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
20+
const cert = fixtures.readKey('agent1-cert.pem');
2421

2522
const endpoint = new QuicEndpoint({ validateAddress: true });
2623

2724
const serverEndpoint = await listen(mustCall(async (serverSession) => {
2825
const info = await serverSession.opened;
2926
// The handshake should complete despite the Retry flow.
30-
strictEqual(info.protocol, 'quic-test');
27+
assert.strictEqual(info.protocol, 'quic-test');
3128
serverSession.close();
3229
}), {
3330
endpoint,
@@ -42,7 +39,7 @@ const clientSession = await connect(serverEndpoint.address, {
4239
});
4340

4441
const info = await clientSession.opened;
45-
strictEqual(info.protocol, 'quic-test');
42+
assert.strictEqual(info.protocol, 'quic-test');
4643

4744
// The serverEndpoint must be closed after we wait for the clientSession to close.
4845
await clientSession.closed;

test/parallel/test-quic-alpn-h3.mjs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
44
import assert from 'node:assert';
55
import * as fixtures from '../common/fixtures.mjs';
66

7-
const { strictEqual, notStrictEqual } = assert;
8-
const { readKey } = fixtures;
9-
107
if (!hasQuic) {
118
skip('QUIC is not enabled');
129
}
1310

1411
const { listen, connect } = await import('node:quic');
1512
const { createPrivateKey } = await import('node:crypto');
1613

17-
const key = createPrivateKey(readKey('agent1-key.pem'));
18-
const cert = readKey('agent1-cert.pem');
14+
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
const cert = fixtures.readKey('agent1-cert.pem');
1916

2017
// Test h3 ALPN negotiation with Http3ApplicationImpl.
2118
// Both server and client use the default ALPN (h3).
@@ -24,14 +21,14 @@ const serverOpened = Promise.withResolvers();
2421

2522
const serverEndpoint = await listen(mustCall(async (serverSession) => {
2623
const info = await serverSession.opened;
27-
strictEqual(info.protocol, 'h3');
24+
assert.strictEqual(info.protocol, 'h3');
2825
serverOpened.resolve();
2926
serverSession.close();
3027
}), {
3128
sni: { '*': { keys: [key], certs: [cert] } },
3229
});
3330

34-
notStrictEqual(serverEndpoint.address, undefined);
31+
assert.notStrictEqual(serverEndpoint.address, undefined);
3532

3633
const clientSession = await connect(serverEndpoint.address, {
3734
servername: 'localhost',
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
4037

4138
async function checkClient() {
4239
const info = await clientSession.opened;
43-
strictEqual(info.protocol, 'h3');
40+
assert.strictEqual(info.protocol, 'h3');
4441
}
4542

4643
await Promise.all([serverOpened.promise, checkClient()]);

test/parallel/test-quic-alpn-mismatch.mjs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
// 0x100 | <tls_alert>. For `no_application_protocol` (alert 120 / 0x78) this
99
// is 0x178 == 376.
1010

11-
import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
11+
import { hasQuic, skip, mustNotCall, expectsError } from '../common/index.mjs';
1212
import assert from 'node:assert';
1313

14-
const { rejects, strictEqual, match } = assert;
15-
1614
if (!hasQuic) {
1715
skip('QUIC is not enabled');
1816
}
@@ -25,11 +23,6 @@ const expected = {
2523
message: /no application protocol/
2624
};
2725

28-
const onerror = mustCall((err) => {
29-
strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
30-
strictEqual(err.errorCode, 376n);
31-
match(err.message, /no application protocol/);
32-
});
3326
const transportParams = { maxIdleTimeout: 1 };
3427

3528
// The handshake fails so the session is never surfaced to JS
@@ -43,12 +36,12 @@ const serverEndpoint = await listen(
4336
const clientSession = await connect(serverEndpoint.address, {
4437
alpn: 'nonexistent-protocol',
4538
transportParams,
46-
onerror,
39+
onerror: expectsError(expected),
4740
});
4841

49-
await rejects(clientSession.opened, expected);
42+
await assert.rejects(clientSession.opened, expected);
5043

5144
// The handshake should fail — opened may reject or never resolve.
5245
// The session should close with an error.
53-
await rejects(clientSession.closed, expected);
46+
await assert.rejects(clientSession.closed, expected);
5447
await serverEndpoint.close();

test/parallel/test-quic-alpn.mjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
44
import assert from 'node:assert';
55
import * as fixtures from '../common/fixtures.mjs';
66

7-
const { notStrictEqual, strictEqual } = assert;
8-
const { readKey } = fixtures;
9-
107
if (!hasQuic) {
118
skip('QUIC is not enabled');
129
}
1310

1411
const { listen, connect } = await import('node:quic');
1512
const { createPrivateKey } = await import('node:crypto');
1613

17-
const key = createPrivateKey(readKey('agent1-key.pem'));
18-
const cert = readKey('agent1-cert.pem');
14+
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
const cert = fixtures.readKey('agent1-cert.pem');
1916

2017
// Server offers multiple ALPNs. Client requests one that the server supports.
2118
// Verify the negotiated protocol matches on both sides.
@@ -25,7 +22,7 @@ const serverOpened = Promise.withResolvers();
2522
async function checkSession(session) {
2623
const info = await session.opened;
2724
// The client should negotiate proto-b (the only protocol it requested)
28-
strictEqual(info.protocol, 'proto-b');
25+
assert.strictEqual(info.protocol, 'proto-b');
2926
}
3027

3128
const serverEndpoint = await listen(mustCall(async (serverSession) => {
@@ -36,7 +33,7 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
3633
alpn: ['proto-a', 'proto-b', 'proto-c'],
3734
});
3835

39-
notStrictEqual(serverEndpoint.address, undefined);
36+
assert.notStrictEqual(serverEndpoint.address, undefined);
4037

4138
const clientSession = await connect(serverEndpoint.address, {
4239
alpn: 'proto-b',

test/parallel/test-quic-blocklist.mjs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
88
import assert from 'node:assert';
99
import net from 'node:net';
1010

11-
const { ok, rejects, strictEqual } = assert;
12-
1311
if (!hasQuic) {
1412
skip('QUIC is not enabled');
1513
}
@@ -34,18 +32,18 @@ const { listen, connect } = await import('../common/quic.mjs');
3432
handshakeTimeout: 500,
3533
verifyPeer: 'manual',
3634
onerror: mustCall((err) => {
37-
strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
35+
assert.strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
3836
}),
3937
});
4038

4139
// The session should fail — the server never sees the packet.
42-
await rejects(clientSession.opened, {
40+
await assert.rejects(clientSession.opened, {
4341
code: 'ERR_QUIC_TRANSPORT_ERROR',
4442
});
4543

4644
// Verify the stat counter.
47-
ok(serverEndpoint.stats.packetsBlocked > 0n,
48-
'packetsBlocked should be non-zero');
45+
assert.ok(serverEndpoint.stats.packetsBlocked > 0n,
46+
'packetsBlocked should be non-zero');
4947

5048
await serverEndpoint.close();
5149
}
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
7270
await clientSession.opened;
7371
await clientSession.close();
7472

75-
strictEqual(serverEndpoint.stats.packetsBlocked, 0n,
76-
'No packets should be blocked for allowed address');
73+
assert.strictEqual(serverEndpoint.stats.packetsBlocked, 0n); // No packets should be blocked for allowed address
7774

7875
await serverEndpoint.close();
7976
}

test/parallel/test-quic-callback-error-onblocked.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import { hasQuic, skip, mustCall } from '../common/index.mjs';
88
import assert from 'node:assert';
99

10-
const { rejects } = assert;
11-
1210
if (!hasQuic) {
1311
skip('QUIC is not enabled');
1412
}
@@ -42,5 +40,5 @@ stream.onblocked = mustCall(() => {
4240
stream.setBody(new Uint8Array(4096));
4341

4442
// The stream's closed promise should reject with the error from the throw.
45-
await rejects(stream.closed, testError);
43+
await assert.rejects(stream.closed, testError);
4644
await serverEndpoint.close();

0 commit comments

Comments
 (0)