Skip to content

Commit

Permalink
test: Add several test cases
Browse files Browse the repository at this point in the history
- Added a test to check whether the `options` argument of APIs allows explicit `null` value
- Added a test to check whether the `ls` function accepts a string value of `lsTypes` property names as value of `type` argument
- Added a test to check the `ls` function correctly throws a `TypeError` if the given `type` argument is an unexpected value
  • Loading branch information
mitsuki31 committed Apr 20, 2024
1 parent 084a48c commit 87d9c54
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
26 changes: 21 additions & 5 deletions test/lsfnd.spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ it('test `lsFiles` function by listing this file directory', async () => {
deepEq(results, expected);
}, false);

it('test `lsDirs` function by listing this file directory', async () => {
const results = await lsDirs(__dirname);
const expected = [ 'lib' ].map((e) => path.join(__dirname, e));
deepEq(results, expected);
}, false);

it('list root directory using URL object', async () => {
await doesNotReject(ls(pathToFileURL(rootDirPosix)), URIError);
}, false);
Expand All @@ -35,17 +41,27 @@ it('list root directory using file URL path', async () => {
await doesNotReject(ls('file:'.concat(rootDirPosix)), URIError);
}, false);

it('test `lsDirs` function by listing this file directory', async () => {
const results = await lsDirs(__dirname);
const expected = [ 'lib' ].map((e) => path.join(__dirname, e));
deepEq(results, expected);
it('test if the options argument allows explicit null value', async () => {
await doesNotReject(lsFiles(__dirname, null), TypeError);
}, false);

it('test if the type argument accepts a string value', async () => {
await doesNotReject(ls(__dirname, {}, 'LS_D'), TypeError);
}, false);

it('throws an error if the given directory path not exist', async () => {
await rejects(ls('./this/is/not/exist/directory/path'), Error);
}, false);

it('throws an URIError if the given file URL path using unsupported protocol',
it('throws a `URIError` if the given file URL path using unsupported protocol',
async () => await rejects(ls('http:'.concat(rootDirPosix)), URIError),
false
);

it('throws a `TypeError` if the given type is an unexpected value',
async () => {
await rejects(ls(__dirname, {}, 'LS_FOO'), TypeError); // Invalid string value test
await rejects(ls(__dirname, {}, []), TypeError); // Array test
},
false
);
16 changes: 16 additions & 0 deletions test/lsfnd.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ it('list root directory using file URL path', async () => {
await doesNotReject(ls('file:'.concat(rootDirPosix)), URIError);
}, false);

it('test if the options argument allows explicit null value', async () => {
await doesNotReject(lsFiles(__dirname, null), TypeError);
}, false);

it('test if the type argument accepts a string value', async () => {
await doesNotReject(ls(__dirname, {}, 'LS_D'), TypeError);
}, false);

it('throws an error if the given directory path not exist', async () => {
await rejects(ls('./this/is/not/exist/directory/path'), Error);
}, false);
Expand All @@ -53,3 +61,11 @@ it('throws an URIError if the given file URL path using unsupported protocol',
async () => await rejects(ls('http:'.concat(rootDirPosix)), URIError),
false
);

it('throws a `TypeError` if the given type is an unexpected value',
async () => {
await rejects(ls(__dirname, {}, 'LS_FOO'), TypeError); // Invalid string value test
await rejects(ls(__dirname, {}, []), TypeError); // Array test
},
false
);

0 comments on commit 87d9c54

Please sign in to comment.