mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix: "deno test" should respect NO_COLOR=true (#6371)
This commit is contained in:
parent
ffedbd79ad
commit
345a5b3dff
3 changed files with 41 additions and 8 deletions
|
@ -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> {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -215,7 +215,7 @@ 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 ` +
|
||||
|
@ -223,7 +223,7 @@ function reportToConsole(message: TestMessage): void {
|
|||
);
|
||||
|
||||
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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
17
cli/tests/deno_test_no_color.ts
Normal file
17
cli/tests/deno_test_no_color.ts
Normal file
|
@ -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() {},
|
||||
});
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue