Skip to content
Merged
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
52 changes: 2 additions & 50 deletions test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default [
],
'node-core/require-common-first': 'error',
'node-core/no-duplicate-requires': 'off',
'node-core/must-call-assert': 'error',
},
},
{
Expand All @@ -154,56 +155,6 @@ export default [
],
},
},
{
files: [
`test/{${[
'abort',
'addons',
'async-hooks',
'benchmark',
'cctest',
'client-proxy',
'doctool',
'embedding',
'es-module',
'fixtures',
'fuzzers',
'internet',
'js-native-api',
'known_issues',
'message',
'module-hooks',
'node-api',
'nop',
'overlapped-checker',
'pseudo-tty',
'pummel',
'report',
'sea',
'sequential',
'sqlite',
'system-ca',
'test426',
'testpy',
'tick-processor',
'tools',
'v8-updates',
'wasi',
'wasm-allocation',
'wpt',
].join(',')}}/**/*.{js,mjs,cjs}`,
`test/parallel/test-{${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
},n*,r*,${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
}}.{js,mjs,cjs}`,
],
rules: {
'node-core/must-call-assert': 'error',
},
},
{
files: [
'test/{common,fixtures,wpt}/**/*.{js,mjs,cjs}',
Expand All @@ -212,6 +163,7 @@ export default [
rules: {
'node-core/required-modules': 'off',
'node-core/require-common-first': 'off',
'node-core/must-call-assert': 'off',
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ before(() => testArr.push('global before'));
after(() => {
testArr.push('global after');

// eslint-disable-next-line node-core/must-call-assert
assert.deepStrictEqual(testArr, [
'global before',
'describe before',
Expand Down
28 changes: 13 additions & 15 deletions test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ const path = require('path');
const { inspect } = require('util');

const is = {
number: (value, key) => {
number: common.mustCallAtLeast((value, key) => {
assert(!Number.isNaN(value), `${key} should not be NaN`);
assert.strictEqual(typeof value, 'number');
},
string: (value) => { assert.strictEqual(typeof value, 'string'); },
array: (value) => { assert.ok(Array.isArray(value)); },
object: (value) => {
}),
string: common.mustCallAtLeast((value) => { assert.strictEqual(typeof value, 'string'); }),
array: common.mustCallAtLeast((value) => { assert.ok(Array.isArray(value)); }),
object: common.mustCallAtLeast((value) => {
assert.strictEqual(typeof value, 'object');
assert.notStrictEqual(value, null);
}
}),
};

process.env.TMPDIR = '/tmpdir';
Expand Down Expand Up @@ -181,15 +181,13 @@ const netmaskToCIDRSuffixMap = new Map(Object.entries({
'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff': 128
}));

Object.values(interfaces)
.flat(Infinity)
.map((v) => ({ v, mask: netmaskToCIDRSuffixMap.get(v.netmask) }))
.forEach(({ v, mask }) => {
assert.ok('cidr' in v, `"cidr" prop not found in ${inspect(v)}`);
if (mask) {
assert.strictEqual(v.cidr, `${v.address}/${mask}`);
}
});
for (const v of Object.values(interfaces).flat(Infinity)) {
assert.ok('cidr' in v, `"cidr" prop not found in ${inspect(v)}`);
const mask = netmaskToCIDRSuffixMap.get(v.netmask);
if (mask) {
assert.strictEqual(v.cidr, `${v.address}/${mask}`);
}
}

const EOL = os.EOL;
if (common.isWindows) {
Expand Down
111 changes: 53 additions & 58 deletions test/parallel/test-perf-hooks-histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

const common = require('../common');

const {
deepStrictEqual,
ok,
strictEqual,
throws,
} = require('assert');
const assert = require('assert');

const {
createHistogram,
Expand All @@ -19,64 +14,64 @@ const { inspect } = require('util');
{
const h = createHistogram();

strictEqual(h.min, 9223372036854776000);
strictEqual(h.minBigInt, 9223372036854775807n);
strictEqual(h.max, 0);
strictEqual(h.maxBigInt, 0n);
strictEqual(h.exceeds, 0);
strictEqual(h.exceedsBigInt, 0n);
ok(Number.isNaN(h.mean));
ok(Number.isNaN(h.stddev));
assert.strictEqual(h.min, 9223372036854776000);
assert.strictEqual(h.minBigInt, 9223372036854775807n);
assert.strictEqual(h.max, 0);
assert.strictEqual(h.maxBigInt, 0n);
assert.strictEqual(h.exceeds, 0);
assert.strictEqual(h.exceedsBigInt, 0n);
assert.ok(Number.isNaN(h.mean));
assert.ok(Number.isNaN(h.stddev));

strictEqual(h.count, 0);
strictEqual(h.countBigInt, 0n);
assert.strictEqual(h.count, 0);
assert.strictEqual(h.countBigInt, 0n);

h.record(1);

strictEqual(h.count, 1);
strictEqual(h.countBigInt, 1n);
assert.strictEqual(h.count, 1);
assert.strictEqual(h.countBigInt, 1n);

[false, '', {}, undefined, null].forEach((i) => {
throws(() => h.record(i), {
assert.throws(() => h.record(i), {
code: 'ERR_INVALID_ARG_TYPE'
});
});
[0, Number.MAX_SAFE_INTEGER + 1].forEach((i) => {
throws(() => h.record(i), {
assert.throws(() => h.record(i), {
code: 'ERR_OUT_OF_RANGE'
});
});

strictEqual(h.min, 1);
strictEqual(h.minBigInt, 1n);
strictEqual(h.max, 1);
strictEqual(h.maxBigInt, 1n);
strictEqual(h.exceeds, 0);
strictEqual(h.mean, 1);
strictEqual(h.stddev, 0);
assert.strictEqual(h.min, 1);
assert.strictEqual(h.minBigInt, 1n);
assert.strictEqual(h.max, 1);
assert.strictEqual(h.maxBigInt, 1n);
assert.strictEqual(h.exceeds, 0);
assert.strictEqual(h.mean, 1);
assert.strictEqual(h.stddev, 0);

strictEqual(h.percentile(1), 1);
strictEqual(h.percentile(100), 1);
assert.strictEqual(h.percentile(1), 1);
assert.strictEqual(h.percentile(100), 1);

strictEqual(h.percentileBigInt(1), 1n);
strictEqual(h.percentileBigInt(100), 1n);
assert.strictEqual(h.percentileBigInt(1), 1n);
assert.strictEqual(h.percentileBigInt(100), 1n);

deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]]));
assert.deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]]));

deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]]));
assert.deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]]));

const mc = new MessageChannel();
mc.port1.onmessage = common.mustCall(({ data }) => {
strictEqual(h.min, 1);
strictEqual(h.max, 1);
strictEqual(h.exceeds, 0);
strictEqual(h.mean, 1);
strictEqual(h.stddev, 0);
assert.strictEqual(h.min, 1);
assert.strictEqual(h.max, 1);
assert.strictEqual(h.exceeds, 0);
assert.strictEqual(h.mean, 1);
assert.strictEqual(h.stddev, 0);

data.record(2n);
data.recordDelta();

strictEqual(h.max, 2);
assert.strictEqual(h.max, 2);

mc.port1.close();
});
Expand All @@ -85,15 +80,15 @@ const { inspect } = require('util');

{
const e = monitorEventLoopDelay();
strictEqual(e.count, 0);
assert.strictEqual(e.count, 0);
e.enable();
const mc = new MessageChannel();
mc.port1.onmessage = common.mustCall(({ data }) => {
strictEqual(typeof data.min, 'number');
ok(data.min > 0);
ok(data.count > 0);
strictEqual(data.disable, undefined);
strictEqual(data.enable, undefined);
assert.strictEqual(typeof data.min, 'number');
assert.ok(data.min > 0);
assert.ok(data.count > 0);
assert.strictEqual(data.disable, undefined);
assert.strictEqual(data.enable, undefined);
mc.port1.close();
});
const interval = setInterval(() => {
Expand All @@ -112,19 +107,19 @@ const { inspect } = require('util');
histogram = hi;
}
// The histogram should already be disabled.
strictEqual(histogram.disable(), false);
assert.strictEqual(histogram.disable(), false);
}

{
const h = createHistogram();
ok(inspect(h, { depth: null }).startsWith('Histogram'));
strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]');
assert.ok(inspect(h, { depth: null }).startsWith('Histogram'));
assert.strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]');
}

{
// Tests that RecordableHistogram is impossible to construct manually
const h = createHistogram();
throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
assert.throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
}

{
Expand All @@ -133,7 +128,7 @@ const { inspect } = require('util');
1,
null,
].forEach((i) => {
throws(() => createHistogram(i), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => createHistogram(i), { code: 'ERR_INVALID_ARG_TYPE' });
});

[
Expand All @@ -142,20 +137,20 @@ const { inspect } = require('util');
null,
{},
].forEach((i) => {
throws(() => createHistogram({ lowest: i }), {
assert.throws(() => createHistogram({ lowest: i }), {
code: 'ERR_INVALID_ARG_TYPE',
});
throws(() => createHistogram({ highest: i }), {
assert.throws(() => createHistogram({ highest: i }), {
code: 'ERR_INVALID_ARG_TYPE',
});
throws(() => createHistogram({ figures: i }), {
assert.throws(() => createHistogram({ figures: i }), {
code: 'ERR_INVALID_ARG_TYPE',
});
});

// Number greater than 5 is not allowed
for (const i of [6, 10]) {
throws(() => createHistogram({ figures: i }), {
assert.throws(() => createHistogram({ figures: i }), {
code: 'ERR_OUT_OF_RANGE',
});
}
Expand All @@ -169,20 +164,20 @@ const { inspect } = require('util');

h1.record(1);

strictEqual(h2.count, 0);
strictEqual(h1.count, 1);
assert.strictEqual(h2.count, 0);
assert.strictEqual(h1.count, 1);

h2.add(h1);

strictEqual(h2.count, 1);
assert.strictEqual(h2.count, 1);

[
'hello',
1,
false,
{},
].forEach((i) => {
throws(() => h1.add(i), {
assert.throws(() => h1.add(i), {
code: 'ERR_INVALID_ARG_TYPE',
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-performance-gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const kinds = [
// GC should not keep the event loop alive
{
let didCall = false;
process.on('beforeExit', () => {
process.on('beforeExit', common.mustCall(() => {
assert(!didCall);
didCall = true;
globalThis.gc();
});
}));
}
10 changes: 4 additions & 6 deletions test/parallel/test-performance-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
require('../common');

const perf_hooks = require('perf_hooks');
const {
strictEqual
} = require('assert');
const assert = require('assert');

const perf = performance;
strictEqual(globalThis.performance, perf_hooks.performance);
assert.strictEqual(globalThis.performance, perf_hooks.performance);
performance = undefined;
strictEqual(globalThis.performance, undefined);
strictEqual(typeof perf_hooks.performance.now, 'function');
assert.strictEqual(globalThis.performance, undefined);
assert.strictEqual(typeof perf_hooks.performance.now, 'function');

// Restore the value of performance for the known globals check
performance = perf;
4 changes: 2 additions & 2 deletions test/parallel/test-performance-measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const ALLOWED_MARGIN = 10;

const expected = ['Start to Now', 'A to Now', 'A to B'];
const obs = new PerformanceObserver(common.mustCall((items) => {
items.getEntries().forEach(({ name, duration }) => {
for (const { name, duration } of items.getEntries()) {
assert.ok(duration > (DELAY - ALLOWED_MARGIN));
assert.strictEqual(expected.shift(), name);
});
}
}));
obs.observe({ entryTypes: ['measure'] });

Expand Down
Loading
Loading