Skip to content

Commit

Permalink
test: simplify start and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Oct 22, 2022
1 parent 84a4cea commit d0f5179
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/internal/fs/watch/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,18 @@ function lazyLoadFsSync() {
return internalSync;
}

async function traverse(dir, parent = undefined, files = new SafeMap()) {
const { readdir, stat } = lazyLoadFsPromises();
async function traverse(dir, files = new SafeMap()) {
const { readdir } = lazyLoadFsPromises();

const filenames = await readdir(dir, { withFileTypes: true });

if (parent !== undefined) {
files.set(dir, parent);
} else {
// Optimization: Only call `stat` on the root element.
files.set(dir, await stat(dir));
}

for await (const file of filenames) {
const f = path.join(dir, file.name);

files.set(f, file);

if (file.isDirectory()) {
await traverse(f, file, files);
await traverse(f, files);
}
}

Expand Down Expand Up @@ -168,9 +161,12 @@ class FSWatcher extends EventEmitter {
}

async [kFSWatchStart](filename) {
const { stat } = lazyLoadFsPromises();

this.#rootPath = filename;
this.#closed = false;
this.#files = await traverse(filename);
this.#files.set(filename, await stat(filename));

for (const f of this.#files.keys()) {
this.#watchFile(f);
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-bootstrap-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const expectedModules = new Set([
'NativeModule internal/fs/read_file_context',
'NativeModule internal/fs/rimraf',
'NativeModule internal/fs/utils',
'NativeModule internal/fs/watch/linux',
'NativeModule internal/fs/watchers',
'NativeModule internal/heap_utils',
'NativeModule internal/histogram',
Expand Down

0 comments on commit d0f5179

Please sign in to comment.