mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Split and simplify the tests into individual files. Refs: https://github.com/nodejs/node/pull/61433 PR-URL: https://github.com/nodejs/node/pull/61494 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { skipIfNoWatch } = require('../common/watch.js');
|
|
|
|
skipIfNoWatch();
|
|
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
|
|
const testFileName = 'visible.txt';
|
|
const testFilePath = path.join(tmpdir.path, testFileName);
|
|
const ignoredFileName = '.hidden';
|
|
const ignoredFilePath = path.join(tmpdir.path, ignoredFileName);
|
|
|
|
const watcher = fs.watch(tmpdir.path, {
|
|
ignore: (filename) => filename.startsWith('.'),
|
|
});
|
|
|
|
watcher.on('change', common.mustCallAtLeast((event, filename) => {
|
|
assert.notStrictEqual(filename, ignoredFileName);
|
|
|
|
if (filename === testFileName) {
|
|
watcher.close();
|
|
}
|
|
}, 1));
|
|
|
|
function writeFiles() {
|
|
fs.writeFileSync(ignoredFilePath, 'ignored');
|
|
fs.writeFileSync(testFilePath, 'content');
|
|
}
|
|
|
|
if (common.isMacOS) {
|
|
// Do the write with a delay to ensure that the OS is ready to notify us. See
|
|
// https://github.com/nodejs/node/issues/52601.
|
|
setTimeout(writeFiles, common.platformTimeout(100));
|
|
} else {
|
|
writeFiles();
|
|
}
|