Skip to content

Commit feaea73

Browse files
committed
Refactor CLI tests
1 parent ef55b76 commit feaea73

1 file changed

Lines changed: 39 additions & 42 deletions

File tree

‎test/cli.js‎

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { exec as execCallback } from "node:child_process";
2-
import { join as joinPaths, dirname as pathDirname, sep } from "node:path";
2+
import { join as joinPaths, dirname as pathDirname } from "node:path";
33
import { fileURLToPath } from "node:url";
44
import { promisify } from "node:util";
55
import tap from "tap";
@@ -9,6 +9,8 @@ const exec = promisify(execCallback);
99
/**
1010
* @file
1111
* This test checks that basic CLI functionality works.
12+
* Most of the args parsing is handled by a node module, so we don't
13+
* need to test a million edge cases, they should be handled correctly.
1214
*/
1315

1416
/**
@@ -18,60 +20,55 @@ const exec = promisify(execCallback);
1820
const dirname = pathDirname(fileURLToPath(import.meta.url));
1921

2022
/**
21-
* Skip the test on operating systems with non-standard path separators (Windows).
23+
* Skip the test on Windows. It has some weird args parsing that we don't want to deal with.
24+
* If the tests pass on all other platforms, we can expect it to work correctly on Windows as well.
2225
*/
23-
const skip = sep !== "/";
26+
const skip = process.platform === "win32";
2427

2528
const cwd = joinPaths(dirname, "..");
2629
const sizeOfFixtureFolder = "0.01 MB";
2730

28-
for (const folderArg of ["--folder=", "-f=", ""]) {
29-
const args = `${folderArg}test/fixture`;
31+
if (!skip) {
32+
for (const folderArg of ["--folder ", "--folder=", "-f ", ""]) {
33+
const args = `${folderArg}"test/fixture"`;
3034

31-
tap.test(`get folder size with args: ${args}`, async () => {
32-
if (skip) return;
35+
tap.test(`get folder size with args: ${args}`, async () => {
36+
const result = await exec(`bin/get-folder-size.js ${args}`, {
37+
cwd,
38+
});
3339

34-
const result = await exec(`bin/get-folder-size.js ${args}`, {
35-
cwd,
40+
tap.ok(
41+
result.stdout.startsWith(sizeOfFixtureFolder),
42+
"should return the size of the folder",
43+
);
3644
});
3745

38-
tap.ok(
39-
result.stdout.startsWith(sizeOfFixtureFolder),
40-
"should return the size of the folder",
41-
{ skip },
42-
);
43-
});
44-
45-
for (const ignoreArg of ["--ignore=", "-i="]) {
46-
for (const flipArgs of [false, true]) {
47-
const arg1 = `${folderArg}test/fixture`;
48-
const arg2 = `${ignoreArg}.*txt`;
49-
const args = flipArgs ? `${arg2} ${arg1}` : `${arg1} ${arg2}`;
46+
for (const ignoreArg of ["--ignore ", "--ignore=", "-i "]) {
47+
for (const flipArgs of [false, true]) {
48+
const arg1 = `${folderArg}"test/fixture"`;
49+
const arg2 = `${ignoreArg}".*txt"`;
50+
const args = flipArgs ? `${arg2} ${arg1}` : `${arg1} ${arg2}`;
5051

51-
tap.test(`get folder size with args: ${args}`, async () => {
52-
if (skip) return;
52+
tap.test(`get folder size with args: ${args}`, async () => {
53+
const result = await exec(
54+
`bin/get-folder-size.js ${args}`,
55+
{
56+
cwd,
57+
},
58+
);
5359

54-
const result = await exec(`bin/get-folder-size.js ${args}`, {
55-
cwd,
60+
tap.ok(
61+
result.stdout.startsWith("0.00 MB"),
62+
"should return zero as size",
63+
);
5664
});
57-
58-
tap.ok(
59-
result.stdout.startsWith("0.00 MB"),
60-
"should return zero as size",
61-
{ skip },
62-
);
63-
});
65+
}
6466
}
6567
}
66-
}
6768

68-
tap.test("get folder size with missing args", async () => {
69-
if (skip) return;
70-
tap.rejects(
71-
async () => {
69+
tap.test("get folder size with missing args", async () => {
70+
tap.rejects(async () => {
7271
await exec("bin/get-folder-size.js", { cwd });
73-
},
74-
"should reject since no folder path is provided",
75-
{ skip },
76-
);
77-
});
72+
}, "should reject since no folder path is provided");
73+
});
74+
}

0 commit comments

Comments
 (0)