Skip to content

Commit

Permalink
tests: add NO_COLOR tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Beast committed Jun 29, 2024
1 parent 075d106 commit 5e164c7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: deno lint

- name: Run tests
run: deno test
run: deno task test-all

- name: Run dry publish
run: deno publish --dry-run
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ jobs:
- name: Run tests
run: |
npx --yes tsx --test **/*.test.ts
npx --yes tsx --test **/*.test.ts && \
NO_COLOR=1 npx --yes tsx --test **/*.test.ts
12 changes: 9 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
"version": "1.0.0-alpha.1",

"imports": {
"@crayon/crayon": "jsr:/@crayon/[email protected].2",
"@crayon/crayon": "jsr:/@crayon/[email protected].3",
// tests
"@cross/test": "jsr:@cross/[email protected]",
"@std/assert": "jsr:@std/[email protected]"
"@beast/compat": "jsr:@beast/compat@^0.2.5",
"@std/assert": "jsr:@std/assert@^0.221.0"
},
"exports": "./main.ts",

"tasks": {
"test-all": "deno task test && deno task test-nocolor",
"test": "deno test --fail-fast=1 --allow-env",
"test-nocolor": "NO_COLOR=1 deno task test"
},

"fmt": {
"lineWidth": 100
},
Expand Down
27 changes: 10 additions & 17 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions main.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
// Copyright 2024 Im-Beast. All rights reserved. MIT license.
import { test } from "@cross/test";
import { env, test } from "@beast/compat";
import { assert, assertEquals, assertThrows } from "@std/assert";

import crayon from "@crayon/crayon";
import "./main.ts";

test("Literal", () => {
const NO_COLOR = !!(env("NO_COLOR") && env("NO_COLOR") !== "0");

test.ignoreIf(!NO_COLOR)("NO_COLOR Literal", () => {
assertEquals(crayon`{bold.rgb(255) {red Hello {yellow world}}}`, "Hello world");
});

test.ignoreIf(NO_COLOR)("Literal", () => {
assert(crayon`{red {bold Hello} world!}`.endsWith("\x1b[0m"));
assertEquals(
crayon`{red {bold Hello} world!}`,
"\x1b[31m\x1b[1mHello\x1b[0m\x1b[31m world!\x1b[0m",
);

const styledText = "{rgb(255,0,17) methods {bgRgb(127,255,0) work!}}";
assertEquals(
crayon`${styledText}`,
crayon`{rgb(255,0,17) methods {bgRgb(127,255,0) work!}}`,
);

assertEquals(
crayon`{rgb(255,0,17) methods {bgRgb(127,255,0) work!}}`,
"\x1b[38;2;255;0;17mmethods \x1b[48;2;127;255;0mwork!\x1b[0m\x1b[38;2;255;0;17m\x1b[0m",
);
});

test("Errors", () => {
test.ignoreIf(NO_COLOR)("Errors", () => {
assertThrows(() => crayon`{inexistentStyle xyz}`);
});

0 comments on commit 5e164c7

Please sign in to comment.