Skip to content

Commit 0d7ae7c

Browse files
committed
test: Add picocolor test to check for ANSI format character problems
1 parent 6a413dc commit 0d7ae7c

5 files changed

Lines changed: 85 additions & 1 deletion

File tree

packages/clifty/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@types/node": "^22.14.1",
3030
"typescript": "^5.8.3",
3131
"vite": "^6.3.2",
32-
"vitest": "^3.1.1"
32+
"vitest": "^3.1.1",
33+
"picocolors": "^1.1.1"
3334
}
3435
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, it, expect } from "vitest";
2+
import { KEYS, withEnv } from "../src";
3+
4+
describe("clifty with picocolors", () => {
5+
it("handles colorized and ansi-formatted output", async () => {
6+
const result = await withEnv({ debug: true })
7+
.defineInteraction()
8+
.expectOutput(
9+
"This is a simple flow for testing output with colorized and formatted output"
10+
)
11+
.whenAsked("What is your name?")
12+
.respondWith("H4cktor", KEYS.ENTER)
13+
.expectOutput("Hello H4cktor (clack.log.success)")
14+
.expectOutput("Hello H4cktor (clack.log.info)")
15+
.expectOutput("Hello H4cktor (clack.log.error)")
16+
.expectOutput("Hello H4cktor (clack.log.warn)")
17+
.expectOutput("Hello H4cktor (red)")
18+
.expectOutput("Hello H4cktor (red + bg)")
19+
.expectOutput("Hello H4cktor (italic + bg)")
20+
.expectOutput("greeting H4cktor in progress")
21+
.expectOutput("greeting H4cktor in progress 50%")
22+
.expectOutput("Greeted H4cktor")
23+
.expectOutput("Goodbye")
24+
.run("node test/testcli/bin.mjs picocolors");
25+
26+
expect(result).toBe(0);
27+
});
28+
});

packages/clifty/test/testcli/bin.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import yargs from "yargs";
22
import { execute as executeInOut } from "./inOut.mjs";
3+
import { execute as executePicocolors } from "./picocolors.mjs";
34

45
yargs(process.argv.slice(2))
56
.command("inOut", "test input and output", () => {
67
executeInOut();
78
})
9+
.command("picocolors", "test picocolors", () => {
10+
executePicocolors();
11+
})
812
.parse();
913

1014
// executeInOut();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as clack from "@clack/prompts";
2+
import pc from "picocolors";
3+
4+
export async function execute(args) {
5+
clack.intro("picocolors");
6+
clack.note(
7+
"This is a simple flow for testing output with colorized and formatted output"
8+
);
9+
10+
const name = await clack.text({
11+
message: "What is your name?",
12+
placeholder: "Enter your name",
13+
});
14+
15+
if (clack.isCancel(name)) {
16+
clack.cancel("Goodbye");
17+
}
18+
19+
// clack prints some extra characters, let's just make sure these don't mess up output expectations
20+
clack.log.success(`Hello ${pc.green(name)} (clack.log.success)`);
21+
clack.log.info(`Hello ${pc.blue(name)} (clack.log.info)`);
22+
clack.log.error(`Hello ${pc.red(name)} (clack.log.error)`);
23+
clack.log.warn(`Hello ${pc.yellow(name)} (clack.log.warn)`);
24+
clack.log.step(`Hello ${pc.cyan(name)} (clack.log.step)`);
25+
26+
console.log(pc.red(`\nHello ${name} (red)`));
27+
console.log(
28+
pc.green(`Hello ${pc.underline(name)} ${pc.dim(pc.bgRed("(red + bg)"))}`)
29+
);
30+
31+
console.log(
32+
pc.italic(pc.bgWhite(`Hello ${pc.cyanBright(name)} (italic + bg)`))
33+
);
34+
35+
const spinner = clack.spinner({ indicator: "timer" });
36+
37+
spinner.start(`greeting ${pc.cyanBright(name)} in progress`);
38+
39+
await new Promise((resolve) => setTimeout(resolve, 1000));
40+
41+
spinner.message(`greeting ${pc.cyanBright(name)} in progress 50%`);
42+
43+
await new Promise((resolve) => setTimeout(resolve, 1000));
44+
45+
spinner.stop(`Greeted ${pc.cyanBright(name)}`);
46+
47+
clack.outro("Goodbye");
48+
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)