0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-fs-watch-abort-signal.js
Wassim Chegham eaadc4bd30 test: refactor code to use AbortSignal.abort()
PR-URL: https://github.com/nodejs/node/pull/37798
Refs: https://github.com/whatwg/dom/pull/960
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2021-03-20 19:21:13 +01:00

31 lines
790 B
JavaScript

// Flags: --expose-internals
'use strict';
// Verify that AbortSignal integration works for fs.watch
const common = require('../common');
if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');
const fs = require('fs');
const fixtures = require('../common/fixtures');
{
// Signal aborted after creating the watcher
const file = fixtures.path('empty.js');
const ac = new AbortController();
const { signal } = ac;
const watcher = fs.watch(file, { signal });
watcher.once('close', common.mustCall());
setImmediate(() => ac.abort());
}
{
// Signal aborted before creating the watcher
const file = fixtures.path('empty.js');
const signal = AbortSignal.abort();
const watcher = fs.watch(file, { signal });
watcher.once('close', common.mustCall());
}