Skip to content

Commit

Permalink
test(cli): improve Spinner test (#5108)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Jun 24, 2024
1 parent e276271 commit 3fac8a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cli/spinner_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
assertEquals,
assertGreater,
assertLess,
assertLessOrEqual,
assertStringIncludes,
} from "@std/assert";
import { delay } from "@std/async/delay";
Expand Down Expand Up @@ -183,10 +184,9 @@ Deno.test("Spinner.start() begins the sequence", async () => {

Deno.test("Spinner.stop() terminates the sequence", async () => {
const text = await spawnDeno(["cli/testdata/spinner_cases/stop.ts"]);
assertEquals(
text,
`${LINE_CLEAR}${COLOR_RESET} ${LINE_CLEAR}${COLOR_RESET} `,
);
// Spinner renders 2 times and then renders LINE_CLEAR at the end.
// (LINE_CLEAR(4) + ⠋(1) COLOR_RESET(4) + SPACE(1)) * 2 + LINE_CLEAR(4) = 24
assertLessOrEqual(text.length, 24);
});

Deno.test("Spinner.message can be updated", async () => {
Expand Down
3 changes: 2 additions & 1 deletion cli/testdata/spinner_cases/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ const spinner = new Spinner();

spinner.start();

setTimeout(spinner.stop, 200);
setTimeout(() => spinner.stop(), 200);
setTimeout(() => {}, 500);

0 comments on commit 3fac8a2

Please sign in to comment.