Commit e59346b

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 8cefc6e commit e59346b

234 files changed

Lines changed: 1711 additions & 2258 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
importfixturesfrom'./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
@@ -116,6 +116,10 @@ export default [
116116
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"]',
117117
message: 'Use assert.doesNotMatch instead',
118118
},
119+
{
120+
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
121+
message: 'Do not destructure or rename `assert` nor `fixtures`',
122+
},
119123
...((fixturesSpecifier)=>[
120124
{
121125
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
constassert=require('assert');
55
constutil=require('util');
66
const{ test }=require('node:test');
7-
const{ AssertionError }=assert;
87
constdefaultMsgStart='Expected values to be strictly deep-equal:\n';
98
constdefaultMsgStartFull=`${defaultMsgStart}+ actual - expected`;
109

@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
688687
constb=newArray(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,newError('foo2'),assert.AssertionError);
716715
assertNotDeepOrStrict(err1,newTypeError('foo1'),assert.AssertionError);
717716
assertDeepAndStrictEqual(err1,newError('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(newDate(2000,3,14),newDate(2000,3,14));
812811

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

817816
assert.throws(
818817
()=>{assert.notDeepEqual(newDate(2000,3,14),newDate(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
consta1=[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(newDate(),newDate(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
constobj1=newConstructor1('Ryan','Dahl');
11061105
letobj2=newConstructor2('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=newConstructor2('Ryan','Dahl');
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
12621261
err[Symbol.toStringTag]='Foobar';
12631262
consterr2=newError('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
conste1=newError('err',{cause: newError('cause e1')});
12831282
conste2=newError('err',{cause: newError('cause e2')});
1284-
assertNotDeepOrStrict(e1,e2,AssertionError);
1285-
assertNotDeepOrStrict(e1,newError('err'),AssertionError);
1283+
assertNotDeepOrStrict(e1,e2,assert.AssertionError);
1284+
assertNotDeepOrStrict(e1,newError('err'),assert.AssertionError);
12861285
assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')}));
12871286
});
12881287

@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
12941293
conste3=newAggregateError([e1duplicate,e2],'Aggregate Error');
12951294
conste3duplicate=newAggregateError([e1,e2],'Aggregate Error');
12961295
conste4=newAggregateError([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
importassertfrom'node:assert';
1010
import*asfixturesfrom'../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 }=awaitimport('node:quic');
2017
const{ createPrivateKey }=awaitimport('node:crypto');
2118

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

2522
constendpoint=newQuicEndpoint({validateAddress: true});
2623

2724
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2825
constinfo=awaitserverSession.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
constinfo=awaitclientSession.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
awaitclientSession.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2623
constinfo=awaitserverSession.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
constclientSession=awaitconnect(serverEndpoint.address,{
3734
servername: 'localhost',
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
4037

4138
asyncfunctioncheckClient(){
4239
constinfo=awaitclientSession.opened;
43-
strictEqual(info.protocol,'h3');
40+
assert.strictEqual(info.protocol,'h3');
4441
}
4542

4643
awaitPromise.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
importassertfrom'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: /noapplicationprotocol/
2624
};
2725

28-
constonerror=mustCall((err)=>{
29-
strictEqual(err.code,'ERR_QUIC_TRANSPORT_ERROR');
30-
strictEqual(err.errorCode,376n);
31-
match(err.message,/noapplicationprotocol/);
32-
});
3326
consttransportParams={maxIdleTimeout: 1};
3427

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

49-
awaitrejects(clientSession.opened,expected);
42+
awaitassert.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-
awaitrejects(clientSession.closed,expected);
46+
awaitassert.rejects(clientSession.closed,expected);
5447
awaitserverEndpoint.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
asyncfunctioncheckSession(session){
2623
constinfo=awaitsession.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
constserverEndpoint=awaitlisten(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
constclientSession=awaitconnect(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
importassertfrom'node:assert';
99
importnetfrom'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-
awaitrejects(clientSession.opened,{
40+
awaitassert.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
awaitserverEndpoint.close();
5149
}
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
7270
awaitclientSession.opened;
7371
awaitclientSession.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
awaitserverEndpoint.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
importassertfrom'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(newUint8Array(4096));
4341

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

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit e59346b

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 8cefc6e commit e59346b

234 files changed

Lines changed: 1711 additions & 2258 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
importfixturesfrom'./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
@@ -116,6 +116,10 @@ export default [
116116
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"]',
117117
message: 'Use assert.doesNotMatch instead',
118118
},
119+
{
120+
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
121+
message: 'Do not destructure or rename `assert` nor `fixtures`',
122+
},
119123
...((fixturesSpecifier)=>[
120124
{
121125
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
constassert=require('assert');
55
constutil=require('util');
66
const{ test }=require('node:test');
7-
const{ AssertionError }=assert;
87
constdefaultMsgStart='Expected values to be strictly deep-equal:\n';
98
constdefaultMsgStartFull=`${defaultMsgStart}+ actual - expected`;
109

@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
688687
constb=newArray(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,newError('foo2'),assert.AssertionError);
716715
assertNotDeepOrStrict(err1,newTypeError('foo1'),assert.AssertionError);
717716
assertDeepAndStrictEqual(err1,newError('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(newDate(2000,3,14),newDate(2000,3,14));
812811

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

817816
assert.throws(
818817
()=>{assert.notDeepEqual(newDate(2000,3,14),newDate(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
consta1=[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(newDate(),newDate(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
constobj1=newConstructor1('Ryan','Dahl');
11061105
letobj2=newConstructor2('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=newConstructor2('Ryan','Dahl');
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
12621261
err[Symbol.toStringTag]='Foobar';
12631262
consterr2=newError('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
conste1=newError('err',{cause: newError('cause e1')});
12831282
conste2=newError('err',{cause: newError('cause e2')});
1284-
assertNotDeepOrStrict(e1,e2,AssertionError);
1285-
assertNotDeepOrStrict(e1,newError('err'),AssertionError);
1283+
assertNotDeepOrStrict(e1,e2,assert.AssertionError);
1284+
assertNotDeepOrStrict(e1,newError('err'),assert.AssertionError);
12861285
assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')}));
12871286
});
12881287

@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
12941293
conste3=newAggregateError([e1duplicate,e2],'Aggregate Error');
12951294
conste3duplicate=newAggregateError([e1,e2],'Aggregate Error');
12961295
conste4=newAggregateError([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
importassertfrom'node:assert';
1010
import*asfixturesfrom'../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 }=awaitimport('node:quic');
2017
const{ createPrivateKey }=awaitimport('node:crypto');
2118

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

2522
constendpoint=newQuicEndpoint({validateAddress: true});
2623

2724
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2825
constinfo=awaitserverSession.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
constinfo=awaitclientSession.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
awaitclientSession.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2623
constinfo=awaitserverSession.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
constclientSession=awaitconnect(serverEndpoint.address,{
3734
servername: 'localhost',
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
4037

4138
asyncfunctioncheckClient(){
4239
constinfo=awaitclientSession.opened;
43-
strictEqual(info.protocol,'h3');
40+
assert.strictEqual(info.protocol,'h3');
4441
}
4542

4643
awaitPromise.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
importassertfrom'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: /noapplicationprotocol/
2624
};
2725

28-
constonerror=mustCall((err)=>{
29-
strictEqual(err.code,'ERR_QUIC_TRANSPORT_ERROR');
30-
strictEqual(err.errorCode,376n);
31-
match(err.message,/noapplicationprotocol/);
32-
});
3326
consttransportParams={maxIdleTimeout: 1};
3427

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

49-
awaitrejects(clientSession.opened,expected);
42+
awaitassert.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-
awaitrejects(clientSession.closed,expected);
46+
awaitassert.rejects(clientSession.closed,expected);
5447
awaitserverEndpoint.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
asyncfunctioncheckSession(session){
2623
constinfo=awaitsession.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
constserverEndpoint=awaitlisten(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
constclientSession=awaitconnect(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
importassertfrom'node:assert';
99
importnetfrom'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-
awaitrejects(clientSession.opened,{
40+
awaitassert.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
awaitserverEndpoint.close();
5149
}
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
7270
awaitclientSession.opened;
7371
awaitclientSession.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
awaitserverEndpoint.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
importassertfrom'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(newUint8Array(4096));
4341

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

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit e59346b

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 8cefc6e commit e59346b

234 files changed

Lines changed: 1711 additions & 2258 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
importfixturesfrom'./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
@@ -116,6 +116,10 @@ export default [
116116
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"]',
117117
message: 'Use assert.doesNotMatch instead',
118118
},
119+
{
120+
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
121+
message: 'Do not destructure or rename `assert` nor `fixtures`',
122+
},
119123
...((fixturesSpecifier)=>[
120124
{
121125
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
constassert=require('assert');
55
constutil=require('util');
66
const{ test }=require('node:test');
7-
const{ AssertionError }=assert;
87
constdefaultMsgStart='Expected values to be strictly deep-equal:\n';
98
constdefaultMsgStartFull=`${defaultMsgStart}+ actual - expected`;
109

@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
688687
constb=newArray(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,newError('foo2'),assert.AssertionError);
716715
assertNotDeepOrStrict(err1,newTypeError('foo1'),assert.AssertionError);
717716
assertDeepAndStrictEqual(err1,newError('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(newDate(2000,3,14),newDate(2000,3,14));
812811

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

817816
assert.throws(
818817
()=>{assert.notDeepEqual(newDate(2000,3,14),newDate(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
consta1=[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(newDate(),newDate(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
constobj1=newConstructor1('Ryan','Dahl');
11061105
letobj2=newConstructor2('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=newConstructor2('Ryan','Dahl');
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
12621261
err[Symbol.toStringTag]='Foobar';
12631262
consterr2=newError('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
conste1=newError('err',{cause: newError('cause e1')});
12831282
conste2=newError('err',{cause: newError('cause e2')});
1284-
assertNotDeepOrStrict(e1,e2,AssertionError);
1285-
assertNotDeepOrStrict(e1,newError('err'),AssertionError);
1283+
assertNotDeepOrStrict(e1,e2,assert.AssertionError);
1284+
assertNotDeepOrStrict(e1,newError('err'),assert.AssertionError);
12861285
assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')}));
12871286
});
12881287

@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
12941293
conste3=newAggregateError([e1duplicate,e2],'Aggregate Error');
12951294
conste3duplicate=newAggregateError([e1,e2],'Aggregate Error');
12961295
conste4=newAggregateError([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
importassertfrom'node:assert';
1010
import*asfixturesfrom'../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 }=awaitimport('node:quic');
2017
const{ createPrivateKey }=awaitimport('node:crypto');
2118

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

2522
constendpoint=newQuicEndpoint({validateAddress: true});
2623

2724
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2825
constinfo=awaitserverSession.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
constinfo=awaitclientSession.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
awaitclientSession.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2623
constinfo=awaitserverSession.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
constclientSession=awaitconnect(serverEndpoint.address,{
3734
servername: 'localhost',
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
4037

4138
asyncfunctioncheckClient(){
4239
constinfo=awaitclientSession.opened;
43-
strictEqual(info.protocol,'h3');
40+
assert.strictEqual(info.protocol,'h3');
4441
}
4542

4643
awaitPromise.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
importassertfrom'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: /noapplicationprotocol/
2624
};
2725

28-
constonerror=mustCall((err)=>{
29-
strictEqual(err.code,'ERR_QUIC_TRANSPORT_ERROR');
30-
strictEqual(err.errorCode,376n);
31-
match(err.message,/noapplicationprotocol/);
32-
});
3326
consttransportParams={maxIdleTimeout: 1};
3427

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

49-
awaitrejects(clientSession.opened,expected);
42+
awaitassert.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-
awaitrejects(clientSession.closed,expected);
46+
awaitassert.rejects(clientSession.closed,expected);
5447
awaitserverEndpoint.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
asyncfunctioncheckSession(session){
2623
constinfo=awaitsession.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
constserverEndpoint=awaitlisten(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
constclientSession=awaitconnect(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
importassertfrom'node:assert';
99
importnetfrom'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-
awaitrejects(clientSession.opened,{
40+
awaitassert.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
awaitserverEndpoint.close();
5149
}
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
7270
awaitclientSession.opened;
7371
awaitclientSession.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
awaitserverEndpoint.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
importassertfrom'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(newUint8Array(4096));
4341

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

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit e59346b

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 8cefc6e commit e59346b

234 files changed

Lines changed: 1711 additions & 2258 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
importfixturesfrom'./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
@@ -116,6 +116,10 @@ export default [
116116
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"]',
117117
message: 'Use assert.doesNotMatch instead',
118118
},
119+
{
120+
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
121+
message: 'Do not destructure or rename `assert` nor `fixtures`',
122+
},
119123
...((fixturesSpecifier)=>[
120124
{
121125
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
constassert=require('assert');
55
constutil=require('util');
66
const{ test }=require('node:test');
7-
const{ AssertionError }=assert;
87
constdefaultMsgStart='Expected values to be strictly deep-equal:\n';
98
constdefaultMsgStartFull=`${defaultMsgStart}+ actual - expected`;
109

@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
688687
constb=newArray(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,newError('foo2'),assert.AssertionError);
716715
assertNotDeepOrStrict(err1,newTypeError('foo1'),assert.AssertionError);
717716
assertDeepAndStrictEqual(err1,newError('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(newDate(2000,3,14),newDate(2000,3,14));
812811

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

817816
assert.throws(
818817
()=>{assert.notDeepEqual(newDate(2000,3,14),newDate(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
consta1=[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(newDate(),newDate(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
constobj1=newConstructor1('Ryan','Dahl');
11061105
letobj2=newConstructor2('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=newConstructor2('Ryan','Dahl');
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
12621261
err[Symbol.toStringTag]='Foobar';
12631262
consterr2=newError('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
conste1=newError('err',{cause: newError('cause e1')});
12831282
conste2=newError('err',{cause: newError('cause e2')});
1284-
assertNotDeepOrStrict(e1,e2,AssertionError);
1285-
assertNotDeepOrStrict(e1,newError('err'),AssertionError);
1283+
assertNotDeepOrStrict(e1,e2,assert.AssertionError);
1284+
assertNotDeepOrStrict(e1,newError('err'),assert.AssertionError);
12861285
assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')}));
12871286
});
12881287

@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
12941293
conste3=newAggregateError([e1duplicate,e2],'Aggregate Error');
12951294
conste3duplicate=newAggregateError([e1,e2],'Aggregate Error');
12961295
conste4=newAggregateError([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
importassertfrom'node:assert';
1010
import*asfixturesfrom'../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 }=awaitimport('node:quic');
2017
const{ createPrivateKey }=awaitimport('node:crypto');
2118

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

2522
constendpoint=newQuicEndpoint({validateAddress: true});
2623

2724
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2825
constinfo=awaitserverSession.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
constinfo=awaitclientSession.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
awaitclientSession.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2623
constinfo=awaitserverSession.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
constclientSession=awaitconnect(serverEndpoint.address,{
3734
servername: 'localhost',
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
4037

4138
asyncfunctioncheckClient(){
4239
constinfo=awaitclientSession.opened;
43-
strictEqual(info.protocol,'h3');
40+
assert.strictEqual(info.protocol,'h3');
4441
}
4542

4643
awaitPromise.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
importassertfrom'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: /noapplicationprotocol/
2624
};
2725

28-
constonerror=mustCall((err)=>{
29-
strictEqual(err.code,'ERR_QUIC_TRANSPORT_ERROR');
30-
strictEqual(err.errorCode,376n);
31-
match(err.message,/noapplicationprotocol/);
32-
});
3326
consttransportParams={maxIdleTimeout: 1};
3427

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

49-
awaitrejects(clientSession.opened,expected);
42+
awaitassert.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-
awaitrejects(clientSession.closed,expected);
46+
awaitassert.rejects(clientSession.closed,expected);
5447
awaitserverEndpoint.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
asyncfunctioncheckSession(session){
2623
constinfo=awaitsession.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
constserverEndpoint=awaitlisten(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
constclientSession=awaitconnect(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
importassertfrom'node:assert';
99
importnetfrom'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-
awaitrejects(clientSession.opened,{
40+
awaitassert.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
awaitserverEndpoint.close();
5149
}
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
7270
awaitclientSession.opened;
7371
awaitclientSession.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
awaitserverEndpoint.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
importassertfrom'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(newUint8Array(4096));
4341

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

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit e59346b

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 8cefc6e commit e59346b

234 files changed

Lines changed: 1711 additions & 2258 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
importfixturesfrom'./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
@@ -116,6 +116,10 @@ export default [
116116
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"]',
117117
message: 'Use assert.doesNotMatch instead',
118118
},
119+
{
120+
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
121+
message: 'Do not destructure or rename `assert` nor `fixtures`',
122+
},
119123
...((fixturesSpecifier)=>[
120124
{
121125
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
constassert=require('assert');
55
constutil=require('util');
66
const{ test }=require('node:test');
7-
const{ AssertionError }=assert;
87
constdefaultMsgStart='Expected values to be strictly deep-equal:\n';
98
constdefaultMsgStartFull=`${defaultMsgStart}+ actual - expected`;
109

@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
688687
constb=newArray(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,newError('foo2'),assert.AssertionError);
716715
assertNotDeepOrStrict(err1,newTypeError('foo1'),assert.AssertionError);
717716
assertDeepAndStrictEqual(err1,newError('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(newDate(2000,3,14),newDate(2000,3,14));
812811

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

817816
assert.throws(
818817
()=>{assert.notDeepEqual(newDate(2000,3,14),newDate(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
consta1=[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(newDate(),newDate(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
constobj1=newConstructor1('Ryan','Dahl');
11061105
letobj2=newConstructor2('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=newConstructor2('Ryan','Dahl');
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
12621261
err[Symbol.toStringTag]='Foobar';
12631262
consterr2=newError('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
conste1=newError('err',{cause: newError('cause e1')});
12831282
conste2=newError('err',{cause: newError('cause e2')});
1284-
assertNotDeepOrStrict(e1,e2,AssertionError);
1285-
assertNotDeepOrStrict(e1,newError('err'),AssertionError);
1283+
assertNotDeepOrStrict(e1,e2,assert.AssertionError);
1284+
assertNotDeepOrStrict(e1,newError('err'),assert.AssertionError);
12861285
assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')}));
12871286
});
12881287

@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
12941293
conste3=newAggregateError([e1duplicate,e2],'Aggregate Error');
12951294
conste3duplicate=newAggregateError([e1,e2],'Aggregate Error');
12961295
conste4=newAggregateError([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
importassertfrom'node:assert';
1010
import*asfixturesfrom'../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 }=awaitimport('node:quic');
2017
const{ createPrivateKey }=awaitimport('node:crypto');
2118

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

2522
constendpoint=newQuicEndpoint({validateAddress: true});
2623

2724
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2825
constinfo=awaitserverSession.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
constinfo=awaitclientSession.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
awaitclientSession.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2623
constinfo=awaitserverSession.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
constclientSession=awaitconnect(serverEndpoint.address,{
3734
servername: 'localhost',
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
4037

4138
asyncfunctioncheckClient(){
4239
constinfo=awaitclientSession.opened;
43-
strictEqual(info.protocol,'h3');
40+
assert.strictEqual(info.protocol,'h3');
4441
}
4542

4643
awaitPromise.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
importassertfrom'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: /noapplicationprotocol/
2624
};
2725

28-
constonerror=mustCall((err)=>{
29-
strictEqual(err.code,'ERR_QUIC_TRANSPORT_ERROR');
30-
strictEqual(err.errorCode,376n);
31-
match(err.message,/noapplicationprotocol/);
32-
});
3326
consttransportParams={maxIdleTimeout: 1};
3427

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

49-
awaitrejects(clientSession.opened,expected);
42+
awaitassert.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-
awaitrejects(clientSession.closed,expected);
46+
awaitassert.rejects(clientSession.closed,expected);
5447
awaitserverEndpoint.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
asyncfunctioncheckSession(session){
2623
constinfo=awaitsession.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
constserverEndpoint=awaitlisten(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
constclientSession=awaitconnect(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
importassertfrom'node:assert';
99
importnetfrom'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-
awaitrejects(clientSession.opened,{
40+
awaitassert.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
awaitserverEndpoint.close();
5149
}
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
7270
awaitclientSession.opened;
7371
awaitclientSession.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
awaitserverEndpoint.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
importassertfrom'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(newUint8Array(4096));
4341

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

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit e59346b

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 8cefc6e commit e59346b

234 files changed

Lines changed: 1711 additions & 2258 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
importfixturesfrom'./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
@@ -116,6 +116,10 @@ export default [
116116
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"]',
117117
message: 'Use assert.doesNotMatch instead',
118118
},
119+
{
120+
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
121+
message: 'Do not destructure or rename `assert` nor `fixtures`',
122+
},
119123
...((fixturesSpecifier)=>[
120124
{
121125
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
constassert=require('assert');
55
constutil=require('util');
66
const{ test }=require('node:test');
7-
const{ AssertionError }=assert;
87
constdefaultMsgStart='Expected values to be strictly deep-equal:\n';
98
constdefaultMsgStartFull=`${defaultMsgStart}+ actual - expected`;
109

@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
688687
constb=newArray(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,newError('foo2'),assert.AssertionError);
716715
assertNotDeepOrStrict(err1,newTypeError('foo1'),assert.AssertionError);
717716
assertDeepAndStrictEqual(err1,newError('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(newDate(2000,3,14),newDate(2000,3,14));
812811

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

817816
assert.throws(
818817
()=>{assert.notDeepEqual(newDate(2000,3,14),newDate(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
consta1=[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(newDate(),newDate(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
constobj1=newConstructor1('Ryan','Dahl');
11061105
letobj2=newConstructor2('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=newConstructor2('Ryan','Dahl');
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
12621261
err[Symbol.toStringTag]='Foobar';
12631262
consterr2=newError('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
conste1=newError('err',{cause: newError('cause e1')});
12831282
conste2=newError('err',{cause: newError('cause e2')});
1284-
assertNotDeepOrStrict(e1,e2,AssertionError);
1285-
assertNotDeepOrStrict(e1,newError('err'),AssertionError);
1283+
assertNotDeepOrStrict(e1,e2,assert.AssertionError);
1284+
assertNotDeepOrStrict(e1,newError('err'),assert.AssertionError);
12861285
assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')}));
12871286
});
12881287

@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
12941293
conste3=newAggregateError([e1duplicate,e2],'Aggregate Error');
12951294
conste3duplicate=newAggregateError([e1,e2],'Aggregate Error');
12961295
conste4=newAggregateError([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
importassertfrom'node:assert';
1010
import*asfixturesfrom'../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 }=awaitimport('node:quic');
2017
const{ createPrivateKey }=awaitimport('node:crypto');
2118

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

2522
constendpoint=newQuicEndpoint({validateAddress: true});
2623

2724
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2825
constinfo=awaitserverSession.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
constinfo=awaitclientSession.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
awaitclientSession.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2623
constinfo=awaitserverSession.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
constclientSession=awaitconnect(serverEndpoint.address,{
3734
servername: 'localhost',
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
4037

4138
asyncfunctioncheckClient(){
4239
constinfo=awaitclientSession.opened;
43-
strictEqual(info.protocol,'h3');
40+
assert.strictEqual(info.protocol,'h3');
4441
}
4542

4643
awaitPromise.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
importassertfrom'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: /noapplicationprotocol/
2624
};
2725

28-
constonerror=mustCall((err)=>{
29-
strictEqual(err.code,'ERR_QUIC_TRANSPORT_ERROR');
30-
strictEqual(err.errorCode,376n);
31-
match(err.message,/noapplicationprotocol/);
32-
});
3326
consttransportParams={maxIdleTimeout: 1};
3427

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

49-
awaitrejects(clientSession.opened,expected);
42+
awaitassert.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-
awaitrejects(clientSession.closed,expected);
46+
awaitassert.rejects(clientSession.closed,expected);
5447
awaitserverEndpoint.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
asyncfunctioncheckSession(session){
2623
constinfo=awaitsession.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
constserverEndpoint=awaitlisten(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
constclientSession=awaitconnect(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
importassertfrom'node:assert';
99
importnetfrom'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-
awaitrejects(clientSession.opened,{
40+
awaitassert.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
awaitserverEndpoint.close();
5149
}
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
7270
awaitclientSession.opened;
7371
awaitclientSession.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
awaitserverEndpoint.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
importassertfrom'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(newUint8Array(4096));
4341

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

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit e59346b

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 8cefc6e commit e59346b

234 files changed

Lines changed: 1711 additions & 2258 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
importfixturesfrom'./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
@@ -116,6 +116,10 @@ export default [
116116
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"]',
117117
message: 'Use assert.doesNotMatch instead',
118118
},
119+
{
120+
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
121+
message: 'Do not destructure or rename `assert` nor `fixtures`',
122+
},
119123
...((fixturesSpecifier)=>[
120124
{
121125
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
constassert=require('assert');
55
constutil=require('util');
66
const{ test }=require('node:test');
7-
const{ AssertionError }=assert;
87
constdefaultMsgStart='Expected values to be strictly deep-equal:\n';
98
constdefaultMsgStartFull=`${defaultMsgStart}+ actual - expected`;
109

@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
688687
constb=newArray(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,newError('foo2'),assert.AssertionError);
716715
assertNotDeepOrStrict(err1,newTypeError('foo1'),assert.AssertionError);
717716
assertDeepAndStrictEqual(err1,newError('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(newDate(2000,3,14),newDate(2000,3,14));
812811

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

817816
assert.throws(
818817
()=>{assert.notDeepEqual(newDate(2000,3,14),newDate(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
consta1=[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(newDate(),newDate(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
constobj1=newConstructor1('Ryan','Dahl');
11061105
letobj2=newConstructor2('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=newConstructor2('Ryan','Dahl');
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
12621261
err[Symbol.toStringTag]='Foobar';
12631262
consterr2=newError('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
conste1=newError('err',{cause: newError('cause e1')});
12831282
conste2=newError('err',{cause: newError('cause e2')});
1284-
assertNotDeepOrStrict(e1,e2,AssertionError);
1285-
assertNotDeepOrStrict(e1,newError('err'),AssertionError);
1283+
assertNotDeepOrStrict(e1,e2,assert.AssertionError);
1284+
assertNotDeepOrStrict(e1,newError('err'),assert.AssertionError);
12861285
assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')}));
12871286
});
12881287

@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
12941293
conste3=newAggregateError([e1duplicate,e2],'Aggregate Error');
12951294
conste3duplicate=newAggregateError([e1,e2],'Aggregate Error');
12961295
conste4=newAggregateError([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
importassertfrom'node:assert';
1010
import*asfixturesfrom'../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 }=awaitimport('node:quic');
2017
const{ createPrivateKey }=awaitimport('node:crypto');
2118

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

2522
constendpoint=newQuicEndpoint({validateAddress: true});
2623

2724
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2825
constinfo=awaitserverSession.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
constinfo=awaitclientSession.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
awaitclientSession.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2623
constinfo=awaitserverSession.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
constclientSession=awaitconnect(serverEndpoint.address,{
3734
servername: 'localhost',
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
4037

4138
asyncfunctioncheckClient(){
4239
constinfo=awaitclientSession.opened;
43-
strictEqual(info.protocol,'h3');
40+
assert.strictEqual(info.protocol,'h3');
4441
}
4542

4643
awaitPromise.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
importassertfrom'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: /noapplicationprotocol/
2624
};
2725

28-
constonerror=mustCall((err)=>{
29-
strictEqual(err.code,'ERR_QUIC_TRANSPORT_ERROR');
30-
strictEqual(err.errorCode,376n);
31-
match(err.message,/noapplicationprotocol/);
32-
});
3326
consttransportParams={maxIdleTimeout: 1};
3427

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

49-
awaitrejects(clientSession.opened,expected);
42+
awaitassert.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-
awaitrejects(clientSession.closed,expected);
46+
awaitassert.rejects(clientSession.closed,expected);
5447
awaitserverEndpoint.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
asyncfunctioncheckSession(session){
2623
constinfo=awaitsession.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
constserverEndpoint=awaitlisten(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
constclientSession=awaitconnect(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
importassertfrom'node:assert';
99
importnetfrom'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-
awaitrejects(clientSession.opened,{
40+
awaitassert.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
awaitserverEndpoint.close();
5149
}
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
7270
awaitclientSession.opened;
7371
awaitclientSession.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
awaitserverEndpoint.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
importassertfrom'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(newUint8Array(4096));
4341

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

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit e59346b

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 8cefc6e commit e59346b

234 files changed

Lines changed: 1711 additions & 2258 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
importfixturesfrom'./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
@@ -116,6 +116,10 @@ export default [
116116
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"]',
117117
message: 'Use assert.doesNotMatch instead',
118118
},
119+
{
120+
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
121+
message: 'Do not destructure or rename `assert` nor `fixtures`',
122+
},
119123
...((fixturesSpecifier)=>[
120124
{
121125
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
constassert=require('assert');
55
constutil=require('util');
66
const{ test }=require('node:test');
7-
const{ AssertionError }=assert;
87
constdefaultMsgStart='Expected values to be strictly deep-equal:\n';
98
constdefaultMsgStartFull=`${defaultMsgStart}+ actual - expected`;
109

@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
688687
constb=newArray(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,newError('foo2'),assert.AssertionError);
716715
assertNotDeepOrStrict(err1,newTypeError('foo1'),assert.AssertionError);
717716
assertDeepAndStrictEqual(err1,newError('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(newDate(2000,3,14),newDate(2000,3,14));
812811

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

817816
assert.throws(
818817
()=>{assert.notDeepEqual(newDate(2000,3,14),newDate(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
consta1=[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(newDate(),newDate(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
constobj1=newConstructor1('Ryan','Dahl');
11061105
letobj2=newConstructor2('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=newConstructor2('Ryan','Dahl');
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
12621261
err[Symbol.toStringTag]='Foobar';
12631262
consterr2=newError('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
conste1=newError('err',{cause: newError('cause e1')});
12831282
conste2=newError('err',{cause: newError('cause e2')});
1284-
assertNotDeepOrStrict(e1,e2,AssertionError);
1285-
assertNotDeepOrStrict(e1,newError('err'),AssertionError);
1283+
assertNotDeepOrStrict(e1,e2,assert.AssertionError);
1284+
assertNotDeepOrStrict(e1,newError('err'),assert.AssertionError);
12861285
assertDeepAndStrictEqual(e1,newError('err',{cause: newError('cause e1')}));
12871286
});
12881287

@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
12941293
conste3=newAggregateError([e1duplicate,e2],'Aggregate Error');
12951294
conste3duplicate=newAggregateError([e1,e2],'Aggregate Error');
12961295
conste4=newAggregateError([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
importassertfrom'node:assert';
1010
import*asfixturesfrom'../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 }=awaitimport('node:quic');
2017
const{ createPrivateKey }=awaitimport('node:crypto');
2118

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

2522
constendpoint=newQuicEndpoint({validateAddress: true});
2623

2724
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2825
constinfo=awaitserverSession.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
constinfo=awaitclientSession.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
awaitclientSession.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
constserverEndpoint=awaitlisten(mustCall(async(serverSession)=>{
2623
constinfo=awaitserverSession.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
constclientSession=awaitconnect(serverEndpoint.address,{
3734
servername: 'localhost',
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
4037

4138
asyncfunctioncheckClient(){
4239
constinfo=awaitclientSession.opened;
43-
strictEqual(info.protocol,'h3');
40+
assert.strictEqual(info.protocol,'h3');
4441
}
4542

4643
awaitPromise.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
importassertfrom'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: /noapplicationprotocol/
2624
};
2725

28-
constonerror=mustCall((err)=>{
29-
strictEqual(err.code,'ERR_QUIC_TRANSPORT_ERROR');
30-
strictEqual(err.errorCode,376n);
31-
match(err.message,/noapplicationprotocol/);
32-
});
3326
consttransportParams={maxIdleTimeout: 1};
3427

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

49-
awaitrejects(clientSession.opened,expected);
42+
awaitassert.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-
awaitrejects(clientSession.closed,expected);
46+
awaitassert.rejects(clientSession.closed,expected);
5447
awaitserverEndpoint.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
importassertfrom'node:assert';
55
import*asfixturesfrom'../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 }=awaitimport('node:quic');
1512
const{ createPrivateKey }=awaitimport('node:crypto');
1613

17-
constkey=createPrivateKey(readKey('agent1-key.pem'));
18-
constcert=readKey('agent1-cert.pem');
14+
constkey=createPrivateKey(fixtures.readKey('agent1-key.pem'));
15+
constcert=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
asyncfunctioncheckSession(session){
2623
constinfo=awaitsession.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
constserverEndpoint=awaitlisten(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
constclientSession=awaitconnect(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
importassertfrom'node:assert';
99
importnetfrom'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-
awaitrejects(clientSession.opened,{
40+
awaitassert.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
awaitserverEndpoint.close();
5149
}
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
7270
awaitclientSession.opened;
7371
awaitclientSession.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
awaitserverEndpoint.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
importassertfrom'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(newUint8Array(4096));
4341

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

0 commit comments

Comments
 (0)