Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: "deno test" should respect NO_COLOR=true (denoland#6371)
  • Loading branch information
uki00a committed Jun 19, 2020
1 parent ffedbd7 commit 345a5b3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cli/js/testing.ts
Expand Up @@ -9,9 +9,6 @@ import { metrics } from "./ops/runtime.ts";
import { resources } from "./ops/resources.ts";
import { assert } from "./util.ts";

const RED_FAILED = red("FAILED");
const GREEN_OK = green("ok");
const YELLOW_IGNORED = yellow("ignored");
const disabledConsole = new Console((): void => {});

function delay(n: number): Promise<void> {
Expand Down Expand Up @@ -178,6 +175,9 @@ function log(msg: string, noNewLine = false): void {
}

function reportToConsole(message: TestMessage): void {
const redFailed = red("FAILED");
const greenOk = green("ok");
const yellowIgnored = yellow("ignored");
if (message.start != null) {
log(`running ${message.start.tests.length} tests`);
} else if (message.testStart != null) {
Expand All @@ -188,13 +188,13 @@ function reportToConsole(message: TestMessage): void {
} else if (message.testEnd != null) {
switch (message.testEnd.status) {
case "passed":
log(`${GREEN_OK} ${formatDuration(message.testEnd.duration)}`);
log(`${greenOk} ${formatDuration(message.testEnd.duration)}`);
break;
case "failed":
log(`${RED_FAILED} ${formatDuration(message.testEnd.duration)}`);
log(`${redFailed} ${formatDuration(message.testEnd.duration)}`);
break;
case "ignored":
log(`${YELLOW_IGNORED} ${formatDuration(message.testEnd.duration)}`);
log(`${yellowIgnored} ${formatDuration(message.testEnd.duration)}`);
break;
}
} else if (message.end != null) {
Expand All @@ -215,15 +215,15 @@ function reportToConsole(message: TestMessage): void {
}
}
log(
`\ntest result: ${message.end.failed ? RED_FAILED : GREEN_OK}. ` +
`\ntest result: ${message.end.failed ? redFailed : greenOk}. ` +
`${message.end.passed} passed; ${message.end.failed} failed; ` +
`${message.end.ignored} ignored; ${message.end.measured} measured; ` +
`${message.end.filtered} filtered out ` +
`${formatDuration(message.end.duration)}\n`
);

if (message.end.usedOnly && message.end.failed == 0) {
log(`${RED_FAILED} because the "only" option was used\n`);
log(`${redFailed} because the "only" option was used\n`);
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions cli/tests/deno_test_no_color.ts
@@ -0,0 +1,17 @@
Deno.test({
name: "success",
fn() {},
});

Deno.test({
name: "fail",
fn() {
throw new Error("fail");
},
});

Deno.test({
name: "ignored",
ignore: true,
fn() {},
});
16 changes: 16 additions & 0 deletions cli/tests/integration_tests.rs
Expand Up @@ -1119,6 +1119,22 @@ fn repl_test_assign_underscore_error() {
assert_eq!(err, "Thrown: 2\n");
}

#[test]
fn deno_test_no_color() {
let (out, _) = util::run_and_collect_output(
false,
"test deno_test_no_color.ts",
None,
Some(vec![("NO_COLOR".to_owned(), "true".to_owned())]),
false,
);
// ANSI escape codes should be stripped.
assert!(out.contains("test success ... ok"));
assert!(out.contains("test fail ... FAILED"));
assert!(out.contains("test ignored ... ignored"));
assert!(out.contains("test result: FAILED. 1 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out"));
}

#[test]
fn util_test() {
util::run_python_script("tools/util_test.py")
Expand Down

0 comments on commit 345a5b3

Please sign in to comment.