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
6 changes: 3 additions & 3 deletions test/doctool/test-apilinks.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../common/index.mjs';
import { mustCallAtLeast } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import tmpdir from '../common/tmpdir.js';

Expand All @@ -14,7 +14,7 @@ const apilinks = fixtures.path('apilinks');

tmpdir.refresh();

fs.readdirSync(apilinks).forEach((fixture) => {
fs.readdirSync(apilinks).forEach(mustCallAtLeast((fixture) => {
if (!fixture.endsWith('.js')) return;
const input = path.join(apilinks, fixture);

Expand All @@ -40,4 +40,4 @@ fs.readdirSync(apilinks).forEach((fixture) => {
Object.keys(actualLinks).length, 0,
`unexpected links returned ${JSON.stringify(actualLinks)}`,
);
});
}));
20 changes: 19 additions & 1 deletion test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,31 @@ export default [
'benchmark',
'cctest',
'client-proxy',
'doctool',
'embedding',
'fixtures',
'fuzzers',
'js-native-api',
'known_issues',
'message',
'module-hooks',
'node-api',
'pummel',
'nop',
'overlapped-checker',
'pseudo-tty',
'pummel',
'report',
'sea',
'sqlite',
'system-ca',
'test426',
'testpy',
'tick-processor',
'tools',
'v8-updates',
'wasi',
'wasm-allocation',
'wpt',
].join(',')}}/**/*.{js,mjs,cjs}`,
],
rules: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
const common = require('../../../common');
const { suite, test } = require('node:test');

suite('async suite', async () => {
suite('async suite', common.mustCall(async () => {
await 1;
test('enabled 1', common.mustCall());
await 1;
test('not run', common.mustNotCall());
await 1;
});
}));

suite('sync suite', () => {
suite('sync suite', common.mustCall(() => {
test('enabled 2', common.mustCall());
});
}));
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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
20 changes: 10 additions & 10 deletions test/fixtures/test-runner/output/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { setTimeout } = require('node:timers/promises');
before((t) => t.diagnostic('before 1 called'));
after((t) => t.diagnostic('after 1 called'));

describe('describe hooks', () => {
describe('describe hooks', common.mustCall(() => {
const testArr = [];
before(function() {
testArr.push('before ' + this.name);
Expand Down Expand Up @@ -51,9 +51,9 @@ describe('describe hooks', () => {
it('nested 1', () => testArr.push('nested 1'));
test('nested 2', () => testArr.push('nested 2'));
});
});
}));

describe('describe hooks - no subtests', () => {
describe('describe hooks - no subtests', common.mustCall(() => {
const testArr = [];
before(function() {
testArr.push('before ' + this.name);
Expand All @@ -67,18 +67,18 @@ describe('describe hooks - no subtests', () => {
}));
beforeEach(common.mustNotCall());
afterEach(common.mustNotCall());
});
}));

describe('before throws', () => {
before(() => { throw new Error('before'); });
it('1', () => {});
test('2', () => {});
});

describe('before throws - no subtests', () => {
describe('before throws - no subtests', common.mustCall(() => {
before(() => { throw new Error('before'); });
after(common.mustCall());
});
}));

describe('after throws', () => {
after(() => { throw new Error('after'); });
Expand All @@ -102,11 +102,11 @@ describe('afterEach throws', () => {
test('2', () => {});
});

describe('afterEach when test fails', () => {
describe('afterEach when test fails', common.mustCall(() => {
afterEach(common.mustCall(2));
it('1', () => { throw new Error('test'); });
test('2', () => {});
});
}));

describe('afterEach throws and test fails', () => {
afterEach(() => { throw new Error('afterEach'); });
Expand Down Expand Up @@ -246,13 +246,13 @@ test('t.after() is called if test body throws', (t) => {
throw new Error('bye');
});

describe('run after when before throws', () => {
describe('run after when before throws', common.mustCall(() => {
after(common.mustCall(() => {
console.log('- after() called');
}));
before(() => { throw new Error('before'); });
it('1', () => {});
});
}));


test('test hooks - async', async (t) => {
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/test-runner/output/name_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('top level test enabled', common.mustCall(async (t) => {
);
}));

describe('top level describe enabled', () => {
describe('top level describe enabled', common.mustCall(() => {
before(common.mustCall());
beforeEach(common.mustCall(3));
afterEach(common.mustCall(3));
Expand All @@ -44,7 +44,7 @@ describe('top level describe enabled', () => {
describe('nested describe enabled', common.mustCall(() => {
it('is enabled', common.mustCall());
}));
});
}));

describe('yes', function() {
it('no', () => {});
Expand Down Expand Up @@ -76,13 +76,13 @@ describe('no with todo', { todo: true }, () => {
});
});

describe('DescribeForMatchWithAncestors', () => {
describe('DescribeForMatchWithAncestors', common.mustCall(() => {
it('NestedTest', () => common.mustNotCall());

describe('NestedDescribeForMatchWithAncestors', () => {
describe('NestedDescribeForMatchWithAncestors', common.mustCall(() => {
it('NestedTest', common.mustCall());
});
});
}));
}));

describe('DescribeForMatchWithAncestors', () => {
it('NestedTest', () => common.mustNotCall());
Expand Down
8 changes: 4 additions & 4 deletions test/js-native-api/3_callbacks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const common = require('../../common');
const assert = require('assert');
const addon = require(`./build/${common.buildType}/3_callbacks`);

addon.RunCallback(function(msg) {
addon.RunCallback(common.mustCall((msg) => {
assert.strictEqual(msg, 'hello world');
});
}));

function testRecv(desiredRecv) {
addon.RunCallbackWithRecv(function() {
addon.RunCallbackWithRecv(common.mustCall(function() {
assert.strictEqual(this, desiredRecv);
}, desiredRecv);
}), desiredRecv);
}

testRecv(undefined);
Expand Down
4 changes: 2 additions & 2 deletions test/js-native-api/test_promise/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ test_promise.concludeCurrentPromise(undefined, true);
const rejectPromise = Promise.reject(-1);
const expected_reason = -1;
assert.strictEqual(test_promise.isPromise(rejectPromise), true);
rejectPromise.catch((reason) => {
rejectPromise.catch(common.mustCall((reason) => {
assert.strictEqual(reason, expected_reason);
});
}));

assert.strictEqual(test_promise.isPromise(2.4), false);
assert.strictEqual(test_promise.isPromise('I promise!'), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ if (cluster.isPrimary) {
if (err.code === 'ENOTSUP') throw err;
});

worker1.on('message', (msg) => {
worker1.on('message', common.mustCall((msg) => {
if (typeof msg !== 'object') process.exit(0);
if (msg.message !== 'success') process.exit(0);
if (typeof msg.port1 !== 'number') process.exit(0);

const worker2 = cluster.fork({ PRT1: msg.port1 });
worker2.on('message', () => process.exit(0));
worker2.on('exit', (code, signal) => {
worker2.on('exit', common.mustCall((code, signal) => {
// This is the droid we are looking for
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
}));

// cleanup anyway
process.on('exit', () => {
worker1.send(BYE);
worker2.send(BYE);
});
});
}));
// end primary code
} else {
// worker code
Expand Down
6 changes: 3 additions & 3 deletions test/known_issues/test-fs-cp-non-utf8.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (!common.isLinux) {
common.skip('This test is only applicable to Linux');
}

const { ok, strictEqual } = require('assert');
const assert = require('assert');
const { join } = require('path');
const path = require('path');
const tmpdir = require('../common/tmpdir');
Expand Down Expand Up @@ -42,8 +42,8 @@ const name = Buffer.from([
const testPath = Buffer.concat([tmpdirPath, sepBuf, name]);

writeFileSync(testPath, 'test content');
ok(existsSync(testPath));
strictEqual(readFileSync(testPath, 'utf8'), 'test content');
assert.ok(existsSync(testPath));
assert.strictEqual(readFileSync(testPath, 'utf8'), 'test content');

// The cpSync is expected to fail because the implementation does not
// properly handle non-UTF8 names in the path.
Expand Down
16 changes: 8 additions & 8 deletions test/known_issues/test-http-clientrequest-end-contentlength.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const response = 'content-length: 19\r\n';
const methods = [ 'GET', 'HEAD', 'DELETE', 'POST', 'PATCH', 'PUT', 'OPTIONS' ];

const server = http.createServer(common.mustCall(function(req, res) {
req.on('data', function(chunk) {
req.on('data', common.mustCall((chunk) => {
assert.strictEqual(chunk, Buffer.from(upload));
});
}));
res.setHeader('Content-Type', 'text/plain');
let payload = `${req.method}\r\n`;
for (let i = 0; i < req.rawHeaders.length; i += 2) {
Expand All @@ -30,22 +30,22 @@ const server = http.createServer(common.mustCall(function(req, res) {
res.end(payload);
}), methods.length);

server.listen(0, function tryNextRequest() {
server.listen(0, common.mustCall(function tryNextRequest() {
const method = methods.pop();
if (method === undefined) return;
const port = server.address().port;
const req = http.request({ method, port }, function(res) {
const req = http.request({ method, port }, common.mustCall((res) => {
const chunks = [];
res.on('data', function(chunk) {
chunks.push(chunk);
});
res.on('end', function() {
res.on('end', common.mustCall(() => {
const received = Buffer.concat(chunks).toString();
const expected = method.toLowerCase() + '\r\n' + response;
assert.strictEqual(received.toLowerCase(), expected);
tryNextRequest();
});
});
}));
}));

req.end(upload);
}).unref();
})).unref();
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const response = '';
const methods = [ 'GET', 'HEAD', 'DELETE', 'POST', 'PATCH', 'PUT', 'OPTIONS' ];

const server = http.createServer(common.mustCall(function(req, res) {
req.on('data', function(chunk) {
req.on('data', common.mustCall((chunk) => {
assert.strictEqual(chunk.toString(), upload);
});
}));
res.setHeader('Content-Type', 'text/plain');
res.write(`${req.method}\r\n`);
for (let i = 0; i < req.rawHeaders.length; i += 2) {
Expand All @@ -31,22 +31,22 @@ const server = http.createServer(common.mustCall(function(req, res) {
res.end();
}), methods.length);

server.listen(0, function tryNextRequest() {
server.listen(0, common.mustCall(function tryNextRequest() {
const method = methods.pop();
if (method === undefined) return;
const port = server.address().port;
const req = http.request({ method, port }, function(res) {
const req = http.request({ method, port }, common.mustCall((res) => {
const chunks = [];
res.on('data', function(chunk) {
chunks.push(chunk);
});
res.on('end', function() {
res.on('end', common.mustCall(() => {
const received = Buffer.concat(chunks).toString();
const expected = method.toLowerCase() + '\r\n' + response;
assert.strictEqual(received.toLowerCase(), expected);
tryNextRequest();
});
});
}));
}));

req.end();
}).unref();
})).unref();
16 changes: 8 additions & 8 deletions test/known_issues/test-http-clientrequest-write-chunked.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const response = 'transfer-encoding: chunked\r\n';
const methods = [ 'GET', 'HEAD', 'DELETE', 'POST', 'PATCH', 'PUT', 'OPTIONS' ];

const server = http.createServer(common.mustCall(function(req, res) {
req.on('data', function(chunk) {
req.on('data', common.mustCall((chunk) => {
assert.strictEqual(chunk.toString(), upload);
});
}));
res.setHeader('Content-Type', 'text/plain');
res.write(`${req.method}\r\n`);
for (let i = 0; i < req.rawHeaders.length; i += 2) {
Expand All @@ -30,23 +30,23 @@ const server = http.createServer(common.mustCall(function(req, res) {
res.end();
}), methods.length);

server.listen(0, function tryNextRequest() {
server.listen(0, common.mustCall(function tryNextRequest() {
const method = methods.pop();
if (method === undefined) return;
const port = server.address().port;
const req = http.request({ method, port }, function(res) {
const req = http.request({ method, port }, common.mustCall((res) => {
const chunks = [];
res.on('data', function(chunk) {
chunks.push(chunk);
});
res.on('end', function() {
res.on('end', common.mustCall(() => {
const received = Buffer.concat(chunks).toString();
const expected = method.toLowerCase() + '\r\n' + response;
assert.strictEqual(received.toLowerCase(), expected);
tryNextRequest();
});
});
}));
}));

req.write(upload);
req.end();
}).unref();
})).unref();
Loading
Loading