mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
de762b71f2
currentId is renamed to executionAsyncId triggerId is renamed to triggerAsyncId AsyncResource.triggerId is renamed to AsyncResource.triggerAsyncId AsyncHooksGetCurrentId is renamed to AsyncHooksGetExecutionAsyncId AsyncHooksGetTriggerId is renamed to AsyncHooksGetTriggerAsyncId PR-URL: https://github.com/nodejs/node/pull/13490 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
65 lines
2.2 KiB
JavaScript
65 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const commonPath = require.resolve('../common');
|
|
const assert = require('assert');
|
|
const initHooks = require('./init-hooks');
|
|
const { checkInvocations } = require('./hook-checks');
|
|
const fs = require('fs');
|
|
|
|
const hooks = initHooks();
|
|
hooks.enable();
|
|
|
|
function onchange() {}
|
|
// install first file watcher
|
|
fs.watchFile(__filename, onchange);
|
|
|
|
let as = hooks.activitiesOfTypes('STATWATCHER');
|
|
assert.strictEqual(as.length, 1);
|
|
|
|
const statwatcher1 = as[0];
|
|
assert.strictEqual(statwatcher1.type, 'STATWATCHER');
|
|
assert.strictEqual(typeof statwatcher1.uid, 'number');
|
|
assert.strictEqual(statwatcher1.triggerAsyncId, 1);
|
|
checkInvocations(statwatcher1, { init: 1 },
|
|
'watcher1: when started to watch file');
|
|
|
|
// install second file watcher
|
|
fs.watchFile(commonPath, onchange);
|
|
as = hooks.activitiesOfTypes('STATWATCHER');
|
|
assert.strictEqual(as.length, 2);
|
|
|
|
const statwatcher2 = as[1];
|
|
assert.strictEqual(statwatcher2.type, 'STATWATCHER');
|
|
assert.strictEqual(typeof statwatcher2.uid, 'number');
|
|
assert.strictEqual(statwatcher2.triggerAsyncId, 1);
|
|
checkInvocations(statwatcher1, { init: 1 },
|
|
'watcher1: when started to watch second file');
|
|
checkInvocations(statwatcher2, { init: 1 },
|
|
'watcher2: when started to watch second file');
|
|
|
|
// remove first file watcher
|
|
fs.unwatchFile(__filename);
|
|
checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
|
|
'watcher1: when unwatched first file');
|
|
checkInvocations(statwatcher2, { init: 1 },
|
|
'watcher2: when unwatched first file');
|
|
|
|
// remove second file watcher
|
|
fs.unwatchFile(commonPath);
|
|
checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
|
|
'watcher1: when unwatched second file');
|
|
checkInvocations(statwatcher2, { init: 1, before: 1, after: 1 },
|
|
'watcher2: when unwatched second file');
|
|
|
|
process.on('exit', onexit);
|
|
|
|
function onexit() {
|
|
hooks.disable();
|
|
hooks.sanityCheck('STATWATCHER');
|
|
checkInvocations(statwatcher1, { init: 1, before: 1, after: 1 },
|
|
'watcher1: when process exits');
|
|
checkInvocations(statwatcher2, { init: 1, before: 1, after: 1 },
|
|
'watcher2: when process exits');
|
|
}
|