mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

Enable running tests inside workers by passing `--worker` to `tools/test.py`. A number of tests are marked as skipped, or have been slightly altered to fit the different environment. PR-URL: https://github.com/nodejs/node/pull/20876 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
40 lines
910 B
JavaScript
40 lines
910 B
JavaScript
'use strict';
|
|
|
|
// Regression test for https://github.com/nodejs/node/issues/13237
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
if (!common.isMainThread)
|
|
common.skip('Worker bootstrapping works differently -> different timing');
|
|
|
|
const async_hooks = require('async_hooks');
|
|
|
|
const seenEvents = [];
|
|
|
|
common.crashOnUnhandledRejection();
|
|
|
|
const p = new Promise((resolve) => resolve(1));
|
|
p.then(() => seenEvents.push('then'));
|
|
|
|
const hooks = async_hooks.createHook({
|
|
init: common.mustNotCall(),
|
|
|
|
before: common.mustCall((id) => {
|
|
assert.ok(id > 1);
|
|
seenEvents.push('before');
|
|
}),
|
|
|
|
after: common.mustCall((id) => {
|
|
assert.ok(id > 1);
|
|
seenEvents.push('after');
|
|
hooks.disable();
|
|
})
|
|
});
|
|
|
|
setImmediate(() => {
|
|
assert.deepStrictEqual(seenEvents, ['before', 'then', 'after']);
|
|
});
|
|
|
|
hooks.enable(); // After `setImmediate` in order to not catch its init event.
|