Skip to content

Commit e06aa84

Browse files
committed
Port behavioural tests to JS.
1 parent 2b0a5c3 commit e06aa84

File tree

7 files changed

+303
-5
lines changed

7 files changed

+303
-5
lines changed

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,32 @@ lint: setup-js
1111
cargo clippy -- --deny warnings
1212
cargo fmt --check
1313
bun x readme-cli-help check
14+
bun x @biomejs/biome check
1415

1516
.PHONY: format
1617
format: setup-js
1718
cargo clippy
1819
cargo fmt
1920
bun x readme-cli-help update
21+
bun x @biomejs/biome check --write
22+
23+
.PHONY: setup
24+
setup: setup-js
2025

2126
.PHONY: setup-js
2227
setup-js:
2328
bun install --frozen-lockfile
2429

25-
.PHONY: cargo-test test
26-
test: test-behaviour lint
30+
.PHONY: test
31+
test: cargo-test test-behaviour
2732

2833
.PHONY: cargo-test
2934
cargo-test:
3035
cargo test
3136

3237
.PHONY: test-behaviour
33-
test-behaviour:
34-
./test/test-behaviour.sh
38+
test-behaviour: setup-js
39+
bun test --timeout 15000
3540

3641
.PHONY: publish
3742
publish:

biome.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"extends": ["./node_modules/@cubing/dev-config/biome/biome.json"],
4+
"files": {
5+
"includes": ["**", "!dist", "!package.json"]
6+
}
7+
}

bun.lock

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bunfig.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[install]
22
auto = "disable"
33
linker = "isolated"
4+
5+
[test]
6+
timeout = 15000

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
2-
"dependencies": {},
2+
"dependencies": {
3+
"path-class": "^0.10.3"
4+
},
35
"devDependencies": {
6+
"@biomejs/biome": "^2.3.8",
7+
"@cubing/dev-config": "^0.5.0",
8+
"@types/bun": "^1.3.4",
9+
"printable-shell-command": "^2.7.4",
410
"readme-cli-help": "^0.4.9"
511
}
612
}

test/test-behaviour.test.ts

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
#!/usr/bin/env -S bun run --
2+
3+
import { expect, test } from "bun:test";
4+
import { Readable } from "node:stream";
5+
import { Path } from "path-class";
6+
import { PrintableShellCommand } from "printable-shell-command";
7+
8+
const EXAMPLES = new Path("./examples/");
9+
10+
let compilePromise: Promise<void> | undefined;
11+
async function cmd(
12+
args: ConstructorParameters<typeof PrintableShellCommand>[1],
13+
) {
14+
// biome-ignore lint/suspicious/noAssignInExpressions: Caching pattern.
15+
await (compilePromise ??= new PrintableShellCommand("cargo", [
16+
"build",
17+
"--release",
18+
]).shellOut());
19+
return new PrintableShellCommand("./target/release/folderify", args);
20+
}
21+
22+
async function shellOut(
23+
args: ConstructorParameters<typeof PrintableShellCommand>[1],
24+
) {
25+
return (await cmd(args)).shellOut();
26+
}
27+
28+
test("Help flag", async () => {
29+
await shellOut(["--help"]);
30+
});
31+
32+
test("Generate icon file", async () => {
33+
await shellOut([EXAMPLES.join("src/apple.png")]);
34+
expect(await EXAMPLES.join("src/apple.icns").existsAsFile()).toBe(true);
35+
expect(await EXAMPLES.join("src/apple.iconset/").existsAsDir()).toBe(true);
36+
for (const pngSuffix of [
37+
"512x512@2x",
38+
"256x256@2x",
39+
"512x512",
40+
"128x128@2x",
41+
"256x256",
42+
"128x128",
43+
"16x16@2x",
44+
"16x16",
45+
"32x32@2x",
46+
"32x32",
47+
]) {
48+
expect(
49+
await EXAMPLES.join(
50+
`src/apple.iconset/icon_${pngSuffix}.png`,
51+
).existsAsFile(),
52+
).toBe(true);
53+
}
54+
});
55+
56+
test("Assign folder icon", async () => {
57+
const tempDir = await Path.makeTempDir();
58+
await shellOut([EXAMPLES.join("src/apple.png"), tempDir]);
59+
expect(await tempDir.join("Icon\r").exists()).toBe(true);
60+
});
61+
62+
test("Assign folder icon using Rez", async () => {
63+
const tempDir = await Path.makeTempDir();
64+
await shellOut([
65+
["--set-icon-using", "Rez"],
66+
EXAMPLES.join("src/apple.png"),
67+
tempDir,
68+
]);
69+
expect(await tempDir.join("Icon\r").exists()).toBe(true);
70+
});
71+
72+
test("Test that `--verbose` is accepted.", async () => {
73+
await shellOut(["--verbose", EXAMPLES.join("src/apple.png")]);
74+
});
75+
76+
test("Test that `--no-trim` is accepted.", async () => {
77+
await shellOut(["--no-trim", EXAMPLES.join("src/apple.png")]);
78+
});
79+
80+
test("Test that `--color-scheme auto` is accepted.", async () => {
81+
await shellOut([["--color-scheme", "auto"], EXAMPLES.join("src/apple.png")]);
82+
});
83+
84+
test("Test that `--color-scheme light` is accepted.", async () => {
85+
await shellOut([["--color-scheme", "light"], EXAMPLES.join("src/apple.png")]);
86+
});
87+
88+
test("Test that `--color-scheme dark` is accepted.", async () => {
89+
await shellOut([["--color-scheme", "dark"], EXAMPLES.join("src/apple.png")]);
90+
});
91+
92+
test("Test that `--no-progress` is accepted.", async () => {
93+
await shellOut(["--no-progress", EXAMPLES.join("src/apple.png")]);
94+
});
95+
96+
test("Test that `--badge alias` is accepted.", async () => {
97+
await shellOut([["--badge", "alias"], EXAMPLES.join("src/apple.png")]);
98+
});
99+
100+
test("Test that `--output-icns …` works.", async () => {
101+
await shellOut([
102+
["--output-icns", EXAMPLES.join("./src/folder_outline_custom_path_1.icns")],
103+
EXAMPLES.join("src/apple.png"),
104+
]);
105+
expect(
106+
await EXAMPLES.join("./src/folder_outline_custom_path_1.icns").exists(),
107+
).toBe(true);
108+
expect(await EXAMPLES.join("./src/folder_outline.icns").exists()).toBe(false);
109+
expect(await EXAMPLES.join("./src/folder_outline.iconset").exists()).toBe(
110+
false,
111+
);
112+
});
113+
114+
test("Test that `--output-iconset …` works.", async () => {
115+
await shellOut([
116+
[
117+
"--output-iconset",
118+
EXAMPLES.join("./src/folder_outline_custom_path_2.iconset"),
119+
],
120+
EXAMPLES.join("src/apple.png"),
121+
]);
122+
expect(
123+
await EXAMPLES.join("./src/folder_outline_custom_path_2.iconset").exists(),
124+
).toBe(true);
125+
expect(await EXAMPLES.join("./src/folder_outline.icns").exists()).toBe(false);
126+
expect(await EXAMPLES.join("./src/folder_outline.iconset").exists()).toBe(
127+
false,
128+
);
129+
});
130+
131+
test("Test that `--output-icns …` and `--output-iconset …` can be used together.", async () => {
132+
await shellOut([
133+
["--output-icns", EXAMPLES.join("./src/folder_outline_custom_path_3.icns")],
134+
[
135+
"--output-iconset",
136+
EXAMPLES.join("./src/folder_outline_custom_path_4.iconset"),
137+
],
138+
EXAMPLES.join("src/apple.png"),
139+
]);
140+
expect(
141+
await EXAMPLES.join("./src/folder_outline_custom_path_3.icns").exists(),
142+
).toBe(true);
143+
expect(
144+
await EXAMPLES.join("./src/folder_outline_custom_path_4.iconset").exists(),
145+
).toBe(true);
146+
expect(await EXAMPLES.join("./src/folder_outline.icns").exists()).toBe(false);
147+
expect(await EXAMPLES.join("./src/folder_outline.iconset").exists()).toBe(
148+
false,
149+
);
150+
});
151+
152+
for (const macOSVersion of ["10.5", "10.8", "10.15"]) {
153+
test(`Test that known macOS ${macOSVersion} is rejected`, async () => {
154+
expect(
155+
await (async () => {
156+
const { stderr } = (
157+
await cmd([["--macOS", macOSVersion], EXAMPLES.join("src/apple.png")])
158+
).spawn({ stdio: ["ignore", "ignore", "pipe"] });
159+
return new Response(Readable.from(stderr)).text();
160+
})(),
161+
).toMatch(
162+
"Error: OS X / macOS 10 was specified. This is no longer supported by folderify v3.",
163+
);
164+
});
165+
}
166+
167+
for (const macOSVersion of ["10.16", "99.0"]) {
168+
test(`Test that known macOS ${macOSVersion} is accepted with a warning`, async () => {
169+
expect(
170+
await (async () => {
171+
const { stderr } = (
172+
await cmd([["--macOS", macOSVersion], EXAMPLES.join("src/apple.png")])
173+
).spawn({ stdio: ["ignore", "ignore", "pipe"] });
174+
return new Response(Readable.from(stderr)).text();
175+
})(),
176+
).toMatch("Warning: Unknown macOS version specified.");
177+
});
178+
}
179+
180+
for (const macOSVersion of ["11.0", "12.1", "14.2.1", "26"]) {
181+
test(`Test that known macOS ${macOSVersion} is accepted without a warning`, async () => {
182+
expect(
183+
await (async () => {
184+
const { stderr } = (
185+
await cmd([["--macOS", macOSVersion], EXAMPLES.join("src/apple.png")])
186+
)
187+
.print()
188+
.spawn({ stdio: ["ignore", "ignore", "pipe"] });
189+
return new Response(Readable.from(stderr)).text();
190+
})(),
191+
).not.toMatch("Warning: Unknown macOS version specified.");
192+
});
193+
}

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./node_modules/@cubing/dev-config/ts/es2022-types/no-dom/tsconfig.json"
3+
}

0 commit comments

Comments
 (0)