• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4const assert = require('assert');
5const initHooks = require('./init-hooks');
6const tick = require('../common/tick');
7const { checkInvocations } = require('./hook-checks');
8const fs = require('fs');
9
10if (!common.isMainThread)
11  common.skip('Worker bootstrapping works differently -> different async IDs');
12
13if (common.isIBMi)
14  common.skip('IBMi does not support fs.watch()');
15
16const hooks = initHooks();
17
18hooks.enable();
19const watcher = fs.watch(__filename, onwatcherChanged);
20function onwatcherChanged() { }
21
22watcher.close();
23tick(2);
24
25process.on('exit', onexit);
26
27function onexit() {
28  hooks.disable();
29  hooks.sanityCheck('FSEVENTWRAP');
30
31  const as = hooks.activitiesOfTypes('FSEVENTWRAP');
32  assert.strictEqual(as.length, 1);
33
34  const a = as[0];
35  assert.strictEqual(a.type, 'FSEVENTWRAP');
36  assert.strictEqual(typeof a.uid, 'number');
37  assert.strictEqual(a.triggerAsyncId, 1);
38  checkInvocations(a, { init: 1, destroy: 1 }, 'when process exits');
39}
40