| 1 | import { |
| 2 | formatResourceTag, |
| 3 | stripChildEffectPrefix, |
| 4 | } from "@/Util/ResourceOutput.ts"; |
| 5 | import { describe, expect, it } from "alchemy-test"; |
| 6 | |
| 7 | describe("stripChildEffectPrefix", { tags: ["unit", "local"] }, () => { |
| 8 | it("removes an Effect pretty prefix", () => { |
| 9 | expect( |
| 10 | stripChildEffectPrefix( |
| 11 | "[14:49:25.594] INFO (#1836): Cloudflare Worker reconcile: starting", |
| 12 | ), |
| 13 | ).toBe("Cloudflare Worker reconcile: starting"); |
| 14 | }); |
| 15 | |
| 16 | it("removes a colored prefix without stripping message color", () => { |
| 17 | expect( |
| 18 | stripChildEffectPrefix( |
| 19 | "\x1b[37m[14:49:25.594]\x1b[0m \x1b[32mINFO\x1b[0m (#1836): \x1b[36mmessage\x1b[0m", |
| 20 | ), |
| 21 | ).toBe("\x1b[36mmessage\x1b[0m"); |
| 22 | }); |
| 23 | |
| 24 | it("leaves ordinary child output unchanged", () => { |
| 25 | expect(stripChildEffectPrefix("vite building for production...")).toBe( |
| 26 | "vite building for production...", |
| 27 | ); |
| 28 | }); |
| 29 | }); |
| 30 | |
| 31 | describe("formatResourceTag", { tags: ["unit", "local"] }, () => { |
| 32 | it("uses the Sigil info color when colors are enabled", () => { |
| 33 | expect(formatResourceTag("Site/Worker", true)).toMatch( |
| 34 | /^\x1b\[38;2;\d+;\d+;\d+m\[Site\/Worker\]\x1b\[0m$/, |
| 35 | ); |
| 36 | }); |
| 37 | |
| 38 | it("stays parseable when colors are disabled", () => { |
| 39 | expect(formatResourceTag("Site/Worker", false)).toBe("[Site/Worker]"); |
| 40 | }); |
| 41 | }); |