-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enhance APIs with file URL path support (#2)
This changes brings new features, enhance the functionality APIs, improve documentation, and ensure compatibility across different environments. Signed-off-by: Ryuu Mitsuki <dhefam31@gmail.com>
- Loading branch information
Showing
5 changed files
with
218 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,51 @@ | ||
const { join, basename } = require('node:path'); | ||
/** | ||
* A test module for `lsfnd` package designed for CommonJS module (CJS). | ||
* @author Ryuu Mitsuki (https://github.com/mitsuki31) | ||
*/ | ||
|
||
const path = require('node:path'); | ||
const { pathToFileURL } = require('node:url'); | ||
const { ls, lsFiles, lsDirs } = require('..'); | ||
const { it, rejects, deepEq } = require('./lib/simpletest'); | ||
const { it, rejects, doesNotReject, deepEq } = require('./lib/simpletest'); | ||
|
||
const rootDir = path.resolve('..'); | ||
const rootDirPosix = path.posix.resolve('..'); | ||
|
||
console.log(`\n\x1b[1m${basename(__filename)}:\x1b[0m`); | ||
console.log(`\n\x1b[1m${path.basename(__filename)}:\x1b[0m`); | ||
|
||
it('test `ls` function by listing this file directory', async () => { | ||
const results = await ls(__dirname, {}, 0); | ||
const expected = [ 'lib', 'lsfnd.spec.cjs', 'lsfnd.spec.mjs' ] | ||
.map((e) => join(__dirname, e)); | ||
.map((e) => path.join(__dirname, e)); | ||
deepEq(results, expected); | ||
}, false); | ||
|
||
it('test `lsFiles` function by listing this file directory', async () => { | ||
const results = await lsFiles(__dirname); | ||
const expected = [ 'lsfnd.spec.cjs', 'lsfnd.spec.mjs' ] | ||
.map((e) => join(__dirname, e)); | ||
.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); | ||
|
||
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) => join(__dirname, e)); | ||
const expected = [ 'lib' ].map((e) => path.join(__dirname, e)); | ||
deepEq(results, expected); | ||
}, false); | ||
|
||
it('throws an error if given directory path not exist', async () => { | ||
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', | ||
async () => await rejects(ls('http:'.concat(rootDirPosix)), URIError), | ||
false | ||
); |
Oops, something went wrong.