Skip to content

Commit

Permalink
test: Add new test cases to test encoding option
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuki31 committed Apr 27, 2024
1 parent b62712d commit 46b776c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/lsfnd.spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ it('test if the type argument accepts a string value', async () => {
await doesNotReject(ls(__dirname, {}, 'LS_D'), TypeError);
}, false);

it("list this file directory with 'base64' encoding", async () => {
const results = await ls(__dirname, { rootDir: __dirname, encoding: 'base64' });
const expected = [ 'lib', 'lsfnd.spec.cjs', 'lsfnd.spec.mjs' ]
.map((e) => Buffer.from(e, 'utf8').toString('base64'));
deepEq(results, expected);
}, false);

// --- [ ERROR TESTS ] --- //

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 @@ -65,3 +74,8 @@ it('throws a `TypeError` if the given type is an unexpected value',
},
false
);

it('throws an error if the given encoding option is unknown', async () => {
await rejects(lsFiles(__dirname, { encoding: 'NotDefinedEncoding' }), TypeError);
await rejects(lsFiles(__dirname, { encoding: true }), TypeError);
});
14 changes: 14 additions & 0 deletions test/lsfnd.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ it('test if the type argument accepts a string value', async () => {
await doesNotReject(ls(__dirname, {}, 'LS_D'), TypeError);
}, false);

it("list this file directory with 'base64' encoding", async () => {
const results = await ls(__dirname, { rootDir: __dirname, encoding: 'base64' });
const expected = [ 'lib', 'lsfnd.spec.cjs', 'lsfnd.spec.mjs' ]
.map((e) => Buffer.from(e, 'utf8').toString('base64'));
deepEq(results, expected);
}, false);

// --- [ ERROR TESTS ] --- //

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 @@ -69,3 +78,8 @@ it('throws a `TypeError` if the given type is an unexpected value',
},
false
);

it('throws an error if the given encoding option is unknown', async () => {
await rejects(lsFiles(__dirname, { encoding: 'NotDefinedEncoding' }), TypeError);
await rejects(lsFiles(__dirname, { encoding: true }), TypeError);
});

0 comments on commit 46b776c

Please sign in to comment.