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
6 changes: 1 addition & 5 deletions test/addons/callback-scope/test-resolve-async.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
'use strict';

const common = require('../../common');
const assert = require('assert');
const { testResolveAsync } = require(`./build/${common.buildType}/binding`);

// Checks that resolving promises from C++ works.

let called = false;
testResolveAsync().then(() => { called = true; });

process.on('beforeExit', common.mustCall(() => { assert(called); }));
testResolveAsync().then(common.mustCall());
1 change: 1 addition & 0 deletions test/async-hooks/test-async-local-storage-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function fireErr5() {
const makeOrphan = vm.compileFunction(`(${String(() => {
async function main() {
await null;
// eslint-disable-next-line node-core/must-call-assert
Promise.resolve().then(() => {
throw new Error('err5');
});
Expand Down
4 changes: 2 additions & 2 deletions test/async-hooks/test-async-local-storage-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ async function main() {
assert.strictEqual(asyncLocalStorage.getStore().get('a'), 1);
throw err;
});
await assert.rejects(new Promise((resolve, reject) => {
await assert.rejects(new Promise((resolve) => {
asyncLocalStorage.run(new Map(), () => {
const store = asyncLocalStorage.getStore();
store.set('a', 1);
next().then(resolve, reject);
resolve(next());
});
}), err);
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
Expand Down
2 changes: 1 addition & 1 deletion test/async-hooks/test-async-local-storage-thenable.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ store.run(data, common.mustCall(() => {
// Returning a thenable in a then handler
store.run(data, common.mustCall(() => {
assert.strictEqual(store.getStore(), data);
Promise.resolve().then(() => thenable());
Promise.resolve().then(() => thenable()).then(common.mustCall());
assert.strictEqual(store.getStore(), data);
}));
6 changes: 3 additions & 3 deletions test/async-hooks/test-destroy-not-blocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ function testPromise() {
assert.strictEqual(activeId, res.asyncId());
res.emitDestroy();
// Promise has higher prio than emit destroy
Promise.resolve().then(common.mustCall(() =>
assert.strictEqual(activeId, res.asyncId())),
);
Promise.resolve().then(common.mustCall(() => {
assert.strictEqual(activeId, res.asyncId());
}));
}

async function testAwait() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const p = new Promise(common.mustCall(function executor(resolve) {
p.then(function afterResolution(val) {
assert.strictEqual(val, 5);
return val;
});
}).then(common.mustCall());

// Init hooks after chained promise is created
const hooks = initHooks();
Expand All @@ -34,7 +34,7 @@ process.on('exit', function onexit() {
const as = hooks.activitiesOfTypes('PROMISE');
const unknown = hooks.activitiesOfTypes('Unknown');
assert.strictEqual(as.length, 0);
assert.strictEqual(unknown.length, 1);
assert.strictEqual(unknown.length, 2);

const a0 = unknown[0];
assert.strictEqual(a0.type, 'Unknown');
Expand Down
4 changes: 2 additions & 2 deletions test/async-hooks/test-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const hooks = initHooks();
hooks.enable();

const p = new Promise(common.mustCall(executor));
p.then(function afterResolution(val) {
p.then(common.mustCall(function afterResolution(val) {
assert.strictEqual(val, 5);
const as = hooks.activitiesOfTypes('PROMISE');
assert.strictEqual(as.length, 2);
checkInvocations(as[0], { init: 1 }, 'after resolution parent promise');
checkInvocations(as[1], { init: 1, before: 1 },
'after resolution child promise');
});
}));

function executor(resolve) {
const as = hooks.activitiesOfTypes('PROMISE');
Expand Down
6 changes: 3 additions & 3 deletions test/async-hooks/test-promise.promise-before-init-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ hooks.enable();
p.then(function afterResolution(val) {
assert.strictEqual(val, 5);
const as = hooks.activitiesOfTypes('PROMISE');
assert.strictEqual(as.length, 1);
assert.strictEqual(as.length, 2);
checkInvocations(as[0], { init: 1, before: 1 },
'after resolution child promise');
return val;
});
}).then(common.mustCall());

process.on('exit', function onexit() {
hooks.disable();
hooks.sanityCheck('PROMISE');

const as = hooks.activitiesOfTypes('PROMISE');
assert.strictEqual(as.length, 1);
assert.strictEqual(as.length, 2);

const a0 = as[0];
assert.strictEqual(a0.type, 'PROMISE');
Expand Down
2 changes: 1 addition & 1 deletion test/client-proxy/test-http-proxy-request-max-sockets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const server = http.createServer(common.mustCall((req, res) => {
console.log('Responding to /first');
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Response for /first');
});
}).then(common.mustCall());
} else if (req.url === '/second') {
// Respond immediately for the second request
res.writeHead(200, { 'Content-Type': 'text/plain' });
Expand Down
2 changes: 1 addition & 1 deletion test/client-proxy/test-https-proxy-request-max-sockets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const server = https.createServer({
console.log('Responding to /first');
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Response for /first');
});
}).then(common.mustCall());
} else if (req.url === '/second') {
// Respond immediately for the second request
res.writeHead(200, { 'Content-Type': 'text/plain' });
Expand Down
66 changes: 21 additions & 45 deletions test/es-module/test-esm-loader-stringify-text.mjs
Original file line number Diff line number Diff line change
@@ -1,90 +1,66 @@
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/string-sources.mjs
import { mustCall, mustNotCall } from '../common/index.mjs';
import { mustCall } from '../common/index.mjs';
import assert from 'assert';

import('test:Array').then(
mustNotCall('Should not accept Arrays'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);
assert.rejects(
import('test:Array'),
{ code: 'ERR_INVALID_RETURN_PROPERTY_VALUE' },
).then(mustCall());
import('test:ArrayBuffer').then(
mustCall(),
mustNotCall('Should accept ArrayBuffers'),
);
import('test:BigInt64Array').then(
mustCall(),
mustNotCall('Should accept BigInt64Array'),
);
import('test:BigUint64Array').then(
mustCall(),
mustNotCall('Should accept BigUint64Array'),
);
import('test:Float32Array').then(
mustCall(),
mustNotCall('Should accept Float32Array'),
);
import('test:Float64Array').then(
mustCall(),
mustNotCall('Should accept Float64Array'),
);
import('test:Int8Array').then(
mustCall(),
mustNotCall('Should accept Int8Array'),
);
import('test:Int16Array').then(
mustCall(),
mustNotCall('Should accept Int16Array'),
);
import('test:Int32Array').then(
mustCall(),
mustNotCall('Should accept Int32Array'),
);
import('test:null').then(
mustNotCall('Should not accept null'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);
import('test:Object').then(
mustNotCall('Should not stringify or valueOf Objects'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);
assert.rejects(
import('test:null'),
{ code: 'ERR_INVALID_RETURN_PROPERTY_VALUE' },
).then(mustCall());
assert.rejects(
import('test:Object'),
{ code: 'ERR_INVALID_RETURN_PROPERTY_VALUE' },
).then(mustCall());
import('test:SharedArrayBuffer').then(
mustCall(),
mustNotCall('Should accept SharedArrayBuffers'),
);
import('test:string').then(
mustCall(),
mustNotCall('Should accept strings'),
);
import('test:String').then(
mustNotCall('Should not accept wrapper Strings'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);
assert.rejects(
import('test:String'),
{ code: 'ERR_INVALID_RETURN_PROPERTY_VALUE' },
).then(mustCall());
import('test:Uint8ClampedArray').then(
mustCall(),
mustNotCall('Should accept Uint8ClampedArray'),
);
import('test:Uint16Array').then(
mustCall(),
mustNotCall('Should accept Uint16Array'),
);
import('test:Uint32Array').then(
mustCall(),
mustNotCall('Should accept Uint32Array'),
);
import('test:Uint8Array').then(
mustCall(),
mustNotCall('Should accept Uint8Arrays'),
);
import('test:undefined').then(
mustNotCall('Should not accept undefined'),
mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
})
);
assert.rejects(
import('test:undefined'),
{ code: 'ERR_INVALID_RETURN_PROPERTY_VALUE' },
).then(mustCall());
5 changes: 3 additions & 2 deletions test/es-module/test-esm-tla.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import '../common/index.mjs';
import { mustCall } from '../common/index.mjs';
import fixtures from '../common/fixtures.js';
import assert from 'assert';
import { pathToFileURL } from 'url';

import(pathToFileURL(fixtures.path('/es-modules/tla/parent.mjs')))
.then(({ default: order }) => {
assert.deepStrictEqual(order, ['order', 'b', 'c', 'd', 'a', 'parent']);
});
})
.then(mustCall());
2 changes: 1 addition & 1 deletion test/es-module/test-require-module-tla-retry-import-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ async function test() {
}

// Run the test twice to check consistency after caching.
test().then(common.mustCall(test));
test().then(test).then(common.mustCall());
2 changes: 1 addition & 1 deletion test/es-module/test-require-module-tla-retry-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ async function test() {
}

// Run the test twice to check consistency after caching.
test().then(common.mustCall(test));
test().then(test).then(common.mustCall());
4 changes: 2 additions & 2 deletions test/es-module/test-wasm-simple.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

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

Expand All @@ -14,4 +14,4 @@ WebAssembly.instantiate(buffer, {}).then((results) => {
results.instance.exports.add(10, 20),
30
);
});
}).then(common.mustCall());
3 changes: 2 additions & 1 deletion test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ test(function test_lookup_ip_promise(done) {
assert.strictEqual(family, 4);

done();
});
})
.then(common.mustCall());
});


Expand Down
13 changes: 6 additions & 7 deletions test/js-native-api/test_promise/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ const test_promise = require(`./build/${common.buildType}/test_promise`);
const expected_result = 42;
const promise = test_promise.createPromise();
promise.then(
common.mustCall(function(result) {
common.mustCall((result) => {
assert.strictEqual(result, expected_result);
}),
common.mustNotCall());
}));
test_promise.concludeCurrentPromise(expected_result, true);
}

Expand All @@ -27,7 +26,8 @@ const test_promise = require(`./build/${common.buildType}/test_promise`);
common.mustNotCall(),
common.mustCall(function(result) {
assert.strictEqual(result, expected_result);
}));
}))
.then(common.mustCall());
test_promise.concludeCurrentPromise(expected_result, false);
}

Expand All @@ -36,10 +36,9 @@ const test_promise = require(`./build/${common.buildType}/test_promise`);
const expected_result = 'chained answer';
const promise = test_promise.createPromise();
promise.then(
common.mustCall(function(result) {
common.mustCall((result) => {
assert.strictEqual(result, expected_result);
}),
common.mustNotCall());
}));
test_promise.concludeCurrentPromise(Promise.resolve('chained answer'), true);
}

Expand Down
3 changes: 2 additions & 1 deletion test/node-api/test_instance_data/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ if (module !== require.main) {
// Test that the thread-safe function can access the instance data.
.then(() => new Promise((resolve) =>
test_instance_data.testThreadsafeFunction(common.mustCall(),
common.mustCall(resolve))));
common.mustCall(resolve))))
.then(common.mustCall());
} else {
// When launched as a script, run tests in either a child process or in a
// worker thread.
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-abortsignal-drop-settled-signals.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Flags: --expose_gc
//
import '../common/index.mjs';
import { mustCall } from '../common/index.mjs';
import { gcUntil } from '../common/gc.js';
import { describe, it } from 'node:test';

Expand Down Expand Up @@ -146,7 +146,7 @@ it('drops settled dependant signals when signal is composite', (t, done) => {
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 2);
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1);

setImmediate(() => {
setImmediate(mustCall(() => {
globalThis.gc({ execution: 'async' }).then(async () => {
await gcUntil('all signals are GCed', () => {
const totalDependantSignals = Math.max(
Expand All @@ -158,8 +158,8 @@ it('drops settled dependant signals when signal is composite', (t, done) => {
});

done();
});
});
}).then(mustCall());
}));
});

it('drops settled signals even when there are listeners', (t, done) => {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-async-hooks-async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// asyncIds & triggerAsyncId for async-await
'use strict';

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

Expand All @@ -23,4 +23,4 @@ main().then(() => {
assert.strictEqual(asyncIds[0][1], asyncIds[1][0]);
assert.strictEqual(asyncIds[0][1], asyncIds[3][0]);
assert.strictEqual(asyncIds[1][1], asyncIds[2][0]);
});
}).then(common.mustCall());
5 changes: 2 additions & 3 deletions test/parallel/test-async-hooks-fatal-error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const childProcess = require('child_process');
const os = require('os');
Expand Down Expand Up @@ -28,8 +28,7 @@ function child(type, valueType) {
new Promise((resolve) => resolve())
// Trigger `after`/`destroy`.
.then(() => fs.promises.readFile(__filename, 'utf8'))
// Make process exit with code 0 if no error caught.
.then(() => process.exit(0));
.then(common.mustCall());
}

function main() {
Expand Down
Loading
Loading