-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { exec as execCallback } from "node:child_process"; | ||
import { join as joinPaths, dirname as pathDirname } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import { promisify } from "node:util"; | ||
import tap from "tap"; | ||
|
||
const exec = promisify(execCallback); | ||
|
||
/** | ||
* @file | ||
* This test checks that basic CLI functionality works. | ||
*/ | ||
|
||
/** | ||
* TODO: replace with `import.meta.dirname` when it becomes stable: | ||
* https://nodejs.org/api/esm.html#importmeta | ||
*/ | ||
const dirname = pathDirname(fileURLToPath(import.meta.url)); | ||
|
||
const cwd = joinPaths(dirname, ".."); | ||
const sizeOfFixtureFolder = "0.01 MB"; | ||
|
||
for (const folderArg of ["--folder=", "-f=", ""]) { | ||
const args = `${folderArg}test/fixture`; | ||
|
||
tap.test(`get folder size with args: ${args}`, async () => { | ||
const result = await exec(`bin/get-folder-size.js ${args}`, { | ||
cwd, | ||
}); | ||
|
||
tap.ok( | ||
result.stdout.startsWith(sizeOfFixtureFolder), | ||
"should return the size of the folder", | ||
); | ||
}); | ||
|
||
for (const ignoreArg of ["--ignore=", "-i="]) { | ||
for (const flipArgs of [false, true]) { | ||
const arg1 = `${folderArg}test/fixture`; | ||
const arg2 = `${ignoreArg}.*txt`; | ||
const args = flipArgs ? `${arg2} ${arg1}` : `${arg1} ${arg2}`; | ||
|
||
tap.test(`get folder size with args: ${args}`, async () => { | ||
const result = await exec(`bin/get-folder-size.js ${args}`, { | ||
cwd, | ||
}); | ||
|
||
tap.ok( | ||
result.stdout.startsWith("0.00 MB"), | ||
"should return zero as size", | ||
); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
tap.test("get folder size with missing args", async () => { | ||
tap.rejects(async () => { | ||
await exec("bin/get-folder-size.js", { cwd }); | ||
}, "should reject since no folder path is provided"); | ||
}); |