|
| 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 | +} |
0 commit comments