Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/common/fixtures.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fixtures from './fixtures.js';

// eslint-disable-next-line no-restricted-syntax
const {
fixturesDir,
path,
Expand Down
4 changes: 4 additions & 0 deletions test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export default [
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"]',
message: 'Use assert.doesNotMatch instead',
},
{
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
message: 'Do not destructure or rename `assert` nor `fixtures`',
},
...((fixturesSpecifier) => [
{
selector: `ImportDeclaration[source.value=${fixturesSpecifier.toString().replace('(\\.js)?', '\\.mjs')}]:not(${[
Expand Down
35 changes: 17 additions & 18 deletions test/parallel/test-assert-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { mustCall, hasCrypto } = require('../common');
const assert = require('assert');
const util = require('util');
const { test } = require('node:test');
const { AssertionError } = assert;
const defaultMsgStart = 'Expected values to be strictly deep-equal:\n';
const defaultMsgStartFull = `${defaultMsgStart}+ actual - expected`;

Expand Down Expand Up @@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
const b = new Array(3);
a[2] = true;
b[1] = true;
assertNotDeepOrStrict(a, b, AssertionError, { partial: 'pass' });
assertNotDeepOrStrict(a, b, assert.AssertionError, { partial: 'pass' });
b[2] = true;
assertNotDeepOrStrict(a, b);
a[0] = true;
assertNotDeepOrStrict(a, b, AssertionError, { partial: 'pass' });
assertNotDeepOrStrict(a, b, assert.AssertionError, { partial: 'pass' });
});

test('Handle sets and maps with mixed keys', () => {
Expand All @@ -715,7 +714,7 @@ test('Handle different error messages', () => {
assertNotDeepOrStrict(err1, new Error('foo2'), assert.AssertionError);
assertNotDeepOrStrict(err1, new TypeError('foo1'), assert.AssertionError);
assertDeepAndStrictEqual(err1, new Error('foo1'));
assertNotDeepOrStrict(err1, {}, AssertionError);
assertNotDeepOrStrict(err1, {}, assert.AssertionError);
});

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

assert.throws(() => { assert.deepEqual(new Date(), new Date(2000, 3, 14)); },
AssertionError,
assert.AssertionError,
'deepEqual(new Date(), new Date(2000, 3, 14))');

assert.throws(
() => { assert.notDeepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14)); },
AssertionError,
assert.AssertionError,
'notDeepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))'
);

assert.throws(
() => { assert.notDeepEqual('a'.repeat(1024), 'a'.repeat(1024)); },
AssertionError,
assert.AssertionError,
'notDeepEqual("a".repeat(1024), "a".repeat(1024))'
);

Expand Down Expand Up @@ -861,7 +860,7 @@ test('Additional tests', () => {
assert.deepEqual(4, '4');
assert.deepEqual(true, 1);
assert.throws(() => assert.deepEqual(4, '5'),
AssertionError,
assert.AssertionError,
'deepEqual( 4, \'5\')');
});

Expand All @@ -870,7 +869,7 @@ test('Having the same number of owned properties && the same set of keys', () =>
assert.deepEqual({ a: 4, b: '2' }, { a: 4, b: '2' });
assert.deepEqual([4], ['4']);
assert.throws(
() => assert.deepEqual({ a: 4 }, { a: 4, b: true }), AssertionError);
() => assert.deepEqual({ a: 4 }, { a: 4, b: true }), assert.AssertionError);
assert.notDeepEqual(['a'], { 0: 'a' });
assert.deepEqual({ a: 4, b: '1' }, { b: '1', a: 4 });
const a1 = [1, 2, 3];
Expand All @@ -880,7 +879,7 @@ test('Having the same number of owned properties && the same set of keys', () =>
a2.b = true;
a2.a = 'test';
assert.throws(() => assert.deepEqual(Object.keys(a1), Object.keys(a2)),
AssertionError);
assert.AssertionError);
assertDeepAndStrictEqual(a1, a2);
});

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

assert.throws(
() => assert.deepStrictEqual(new Date(), new Date(2000, 3, 14)),
AssertionError,
assert.AssertionError,
'deepStrictEqual(new Date(), new Date(2000, 3, 14))'
);

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

assert.throws(
() => assert.deepStrictEqual([0, 1, 2, 'a', 'b'], [0, 1, 2, 'b', 'a']),
AssertionError);
assert.AssertionError);
});

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

assert.throws(() => assert.deepStrictEqual(obj1, obj2), AssertionError);
assert.throws(() => assert.deepStrictEqual(obj1, obj2), assert.AssertionError);

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

test('Check for non-native errors', () => {
Expand All @@ -1281,8 +1280,8 @@ test('Check for non-native errors', () => {
test('Check for Errors with cause property', () => {
const e1 = new Error('err', { cause: new Error('cause e1') });
const e2 = new Error('err', { cause: new Error('cause e2') });
assertNotDeepOrStrict(e1, e2, AssertionError);
assertNotDeepOrStrict(e1, new Error('err'), AssertionError);
assertNotDeepOrStrict(e1, e2, assert.AssertionError);
assertNotDeepOrStrict(e1, new Error('err'), assert.AssertionError);
assertDeepAndStrictEqual(e1, new Error('err', { cause: new Error('cause e1') }));
});

Expand All @@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
const e3 = new AggregateError([e1duplicate, e2], 'Aggregate Error');
const e3duplicate = new AggregateError([e1, e2], 'Aggregate Error');
const e4 = new AggregateError([e1], 'Aggregate Error');
assertNotDeepOrStrict(e1, e3, AssertionError);
assertNotDeepOrStrict(e3, e4, AssertionError);
assertNotDeepOrStrict(e1, e3, assert.AssertionError);
assertNotDeepOrStrict(e3, e4, assert.AssertionError);
assertDeepAndStrictEqual(e3, e3duplicate);
});

Expand Down
13 changes: 5 additions & 8 deletions test/parallel/test-dtls-alpn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
import * as fixtures from '../common/fixtures.mjs';

const { strictEqual } = assert;
const { readKey } = fixtures;

if (!hasCrypto) {
skip('missing crypto');
}
Expand All @@ -19,17 +16,17 @@ if (!process.features.dtls) {

const { listen, connect } = await import('node:dtls');

const serverCert = readKey('agent1-cert.pem');
const serverKey = readKey('agent1-key.pem');
const ca = readKey('ca1-cert.pem');
const serverCert = fixtures.readKey('agent1-cert.pem');
const serverKey = fixtures.readKey('agent1-key.pem');
const ca = fixtures.readKey('ca1-cert.pem');

const serverAlpnChecked = Promise.withResolvers();

const endpoint = listen(mustCall(async (session) => {
session.onmessage = () => {};
await session.opened;
// Server should see the negotiated ALPN protocol.
strictEqual(session.alpnProtocol, 'coap');
assert.strictEqual(session.alpnProtocol, 'coap');
serverAlpnChecked.resolve();
}), {
cert: serverCert.toString(),
Expand All @@ -48,7 +45,7 @@ const session = connect('127.0.0.1', endpoint.address.port, {
await session.opened;

// Client should see the negotiated protocol.
strictEqual(session.alpnProtocol, 'coap');
assert.strictEqual(session.alpnProtocol, 'coap');

await serverAlpnChecked.promise;

Expand Down
13 changes: 5 additions & 8 deletions test/parallel/test-dtls-async-dispose.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall, mustNotCall } from '../common/index.mjs';
import assert from 'node:assert';
import * as fixtures from '../common/fixtures.mjs';

const { strictEqual } = assert;
const { readKey } = fixtures;

if (!hasCrypto) {
skip('missing crypto');
}
Expand All @@ -19,9 +16,9 @@ if (!process.features.dtls) {

const { listen, connect } = await import('node:dtls');

const serverCert = readKey('agent1-cert.pem');
const serverKey = readKey('agent1-key.pem');
const ca = readKey('ca1-cert.pem');
const serverCert = fixtures.readKey('agent1-cert.pem');
const serverKey = fixtures.readKey('agent1-key.pem');
const ca = fixtures.readKey('ca1-cert.pem');

const endpoint = listen(mustCall((session) => {
session.onmessage = mustNotCall();
Expand All @@ -40,8 +37,8 @@ const session = connect('127.0.0.1', endpoint.address.port, {
await session.opened;

// Test that Symbol.asyncDispose exists.
strictEqual(typeof session[Symbol.asyncDispose], 'function');
strictEqual(typeof endpoint[Symbol.asyncDispose], 'function');
assert.strictEqual(typeof session[Symbol.asyncDispose], 'function');
assert.strictEqual(typeof endpoint[Symbol.asyncDispose], 'function');

// Dispose the session.
await session[Symbol.asyncDispose]();
Expand Down
29 changes: 13 additions & 16 deletions test/parallel/test-dtls-basic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
import * as fixtures from '../common/fixtures.mjs';

const { ok, strictEqual, match } = assert;
const { readKey } = fixtures;

if (!hasCrypto) {
skip('missing crypto');
}
Expand All @@ -19,9 +16,9 @@ if (!process.features.dtls) {

const { listen, connect } = await import('node:dtls');

const serverCert = readKey('agent1-cert.pem');
const serverKey = readKey('agent1-key.pem');
const ca = readKey('ca1-cert.pem');
const serverCert = fixtures.readKey('agent1-cert.pem');
const serverKey = fixtures.readKey('agent1-key.pem');
const ca = fixtures.readKey('ca1-cert.pem');

const serverReceivedData = Promise.withResolvers();
const clientReceivedData = Promise.withResolvers();
Expand All @@ -32,16 +29,16 @@ let clientHandshakeDone = false;
// Start server.
const endpoint = listen(mustCall((session) => {
session.onmessage = mustCall((data) => {
strictEqual(data.toString(), 'hello from client');
assert.strictEqual(data.toString(), 'hello from client');
serverReceivedData.resolve();

// Send response back to client.
session.send('hello from server');
});

session.onhandshake = mustCall((protocol) => {
ok(protocol);
match(protocol, /DTLS/i);
assert.ok(protocol);
assert.match(protocol, /DTLS/i);
serverHandshakeDone = true;
});
}), {
Expand All @@ -52,8 +49,8 @@ const endpoint = listen(mustCall((session) => {
});

const serverAddress = endpoint.address;
ok(serverAddress);
ok(serverAddress.port > 0);
assert.ok(serverAddress);
assert.ok(serverAddress.port > 0);

// Connect client.
const clientSession = connect('127.0.0.1', serverAddress.port, {
Expand All @@ -62,18 +59,18 @@ const clientSession = connect('127.0.0.1', serverAddress.port, {
});

clientSession.onmessage = mustCall((data) => {
strictEqual(data.toString(), 'hello from server');
assert.strictEqual(data.toString(), 'hello from server');
clientReceivedData.resolve();
});

clientSession.onhandshake = mustCall((protocol) => {
ok(protocol);
assert.ok(protocol);
clientHandshakeDone = true;
});

// Wait for handshake.
const { protocol } = await clientSession.opened;
match(protocol, /DTLS/i);
assert.match(protocol, /DTLS/i);

// Send data.
clientSession.send('hello from client');
Expand All @@ -82,8 +79,8 @@ clientSession.send('hello from client');
await Promise.all([serverReceivedData.promise, clientReceivedData.promise]);

// Verify handshakes completed.
ok(clientHandshakeDone);
ok(serverHandshakeDone);
assert.ok(clientHandshakeDone);
assert.ok(serverHandshakeDone);

// Clean up.
await clientSession.close();
Expand Down
13 changes: 5 additions & 8 deletions test/parallel/test-dtls-close.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall, mustNotCall } from '../common/index.mjs';
import assert from 'node:assert';
import * as fixtures from '../common/fixtures.mjs';

const { ok, throws } = assert;
const { readKey } = fixtures;

if (!hasCrypto) {
skip('missing crypto');
}
Expand All @@ -19,9 +16,9 @@ if (!process.features.dtls) {

const { listen, connect } = await import('node:dtls');

const serverCert = readKey('agent1-cert.pem');
const serverKey = readKey('agent1-key.pem');
const ca = readKey('ca1-cert.pem');
const serverCert = fixtures.readKey('agent1-cert.pem');
const serverKey = fixtures.readKey('agent1-key.pem');
const ca = fixtures.readKey('ca1-cert.pem');

// Test 1: Graceful close from client side.
{
Expand All @@ -48,7 +45,7 @@ const ca = readKey('ca1-cert.pem');

// Graceful close.
const closedPromise = session.close();
ok(closedPromise instanceof Promise);
assert.ok(closedPromise instanceof Promise);
await closedPromise;

// Wait for server to see the close.
Expand Down Expand Up @@ -80,7 +77,7 @@ const ca = readKey('ca1-cert.pem');
session.destroy();

// After destroy, send should fail.
throws(() => {
assert.throws(() => {
session.send('should fail');
}, /destroyed/i);

Expand Down
11 changes: 4 additions & 7 deletions test/parallel/test-dtls-multiple-clients.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
import * as fixtures from '../common/fixtures.mjs';

const { strictEqual } = assert;
const { readKey } = fixtures;

if (!hasCrypto) {
skip('missing crypto');
}
Expand All @@ -19,9 +16,9 @@ if (!process.features.dtls) {

const { listen, connect } = await import('node:dtls');

const serverCert = readKey('agent1-cert.pem');
const serverKey = readKey('agent1-key.pem');
const ca = readKey('ca1-cert.pem');
const serverCert = fixtures.readKey('agent1-cert.pem');
const serverKey = fixtures.readKey('agent1-key.pem');
const ca = fixtures.readKey('ca1-cert.pem');

const NUM_CLIENTS = 3;
let sessionsAccepted = 0;
Expand Down Expand Up @@ -57,7 +54,7 @@ for (let i = 0; i < NUM_CLIENTS; i++) {
});

session.onmessage = mustCall((data) => {
strictEqual(data.toString(), `echo:client${i}`);
assert.strictEqual(data.toString(), `echo:client${i}`);
received.resolve();
});

Expand Down
Loading
Loading