Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion test/parallel/test-fs-utils-get-dirents.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ const common = require('../common');
const { getDirents, getDirent } = require('internal/fs/utils');
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
const { UV_DIRENT_UNKNOWN } = internalBinding('constants').fs;
const { UV_DIRENT_UNKNOWN, UV_DIRENT_FILE } = internalBinding('constants').fs;
const fs = require('fs');
const { resolve } = require('path');

const tmpdir = require('../common/tmpdir');
const filename = 'foo';
const nonExistentPath = resolve(tmpdir.path, 'does-not-exist');

{
// setup
Expand Down Expand Up @@ -65,6 +67,18 @@ const filename = 'foo';
},
));
}
{
// Intentional error in lstat
getDirents(
Buffer.from(nonExistentPath),
[[Buffer.from(filename)], [UV_DIRENT_UNKNOWN]],
common.mustCall((err) => {
assert.match(
err.code, /ENOTDIR|ENOENT/
);
},
));
}
// getDirent
{
// string + string
Expand Down Expand Up @@ -125,3 +139,28 @@ const filename = 'foo';
},
));
}
{
// When type != UV_DIRENT_UNKNOWN
getDirent(
tmpdir.path,
filename,
UV_DIRENT_FILE,
common.mustCall((err, dirent) => {
assert.strictEqual(err, null);
assert.strictEqual(dirent.name, filename);
},
));
}
{
// Intentional error in lstat
getDirent(
nonExistentPath,
filename,
UV_DIRENT_UNKNOWN,
common.mustCall((err) => {
assert.match(
err.code, /ENOTDIR|ENOENT/
);
},
));
}