mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix(test): handle ASCII escape chars in test name (#20081)
Handles ASCCI espace chars in test and bench name making test and bench reporting more reliable. This one is also tested in the fixture of "node:test" module.
This commit is contained in:
parent
414274b68a
commit
04a259e2c8
3 changed files with 75 additions and 3 deletions
|
@ -27,6 +27,7 @@ const {
|
|||
Promise,
|
||||
SafeArrayIterator,
|
||||
Set,
|
||||
StringPrototypeReplaceAll,
|
||||
SymbolToStringTag,
|
||||
TypeError,
|
||||
} = primordials;
|
||||
|
@ -516,6 +517,21 @@ function withPermissions(fn, permissions) {
|
|||
};
|
||||
}
|
||||
|
||||
const ESCAPE_ASCII_CHARS = [
|
||||
["\b", "\\b"],
|
||||
["\f", "\\f"],
|
||||
["\t", "\\t"],
|
||||
["\n", "\\n"],
|
||||
["\r", "\\r"],
|
||||
["\v", "\\v"],
|
||||
];
|
||||
|
||||
function escapeName(name) {
|
||||
for (const [escape, replaceWith] of ESCAPE_ASCII_CHARS) {
|
||||
name = StringPrototypeReplaceAll(name, escape, replaceWith);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @typedef {{
|
||||
* id: number,
|
||||
|
@ -693,6 +709,7 @@ function test(
|
|||
}
|
||||
testDesc.location = location;
|
||||
testDesc.fn = wrapTest(testDesc);
|
||||
testDesc.name = escapeName(testDesc.name);
|
||||
|
||||
const { id, origin } = ops.op_register_test(testDesc);
|
||||
testDesc.id = id;
|
||||
|
@ -818,6 +835,7 @@ function bench(
|
|||
benchDesc.async = AsyncFunction === benchDesc.fn.constructor;
|
||||
benchDesc.fn = wrapBenchmark(benchDesc);
|
||||
benchDesc.warmup = false;
|
||||
benchDesc.name = escapeName(benchDesc.name);
|
||||
|
||||
const { id, origin } = ops.op_register_bench(benchDesc);
|
||||
benchDesc.id = id;
|
||||
|
@ -1190,7 +1208,8 @@ function createTestContext(desc) {
|
|||
stepDesc.level = level + 1;
|
||||
stepDesc.parent = desc;
|
||||
stepDesc.rootId = rootId;
|
||||
stepDesc.rootName = rootName;
|
||||
stepDesc.name = escapeName(stepDesc.name);
|
||||
stepDesc.rootName = escapeName(rootName);
|
||||
stepDesc.fn = wrapTest(stepDesc);
|
||||
const { id, origin } = ops.op_register_test_step(stepDesc);
|
||||
stepDesc.id = id;
|
||||
|
|
34
cli/tests/testdata/test/pass.out
vendored
34
cli/tests/testdata/test/pass.out
vendored
|
@ -1,5 +1,5 @@
|
|||
Check [WILDCARD]/test/pass.ts
|
||||
running 10 tests from ./test/pass.ts
|
||||
running 16 tests from ./test/pass.ts
|
||||
test 0 ... ok ([WILDCARD])
|
||||
test 1 ... ok ([WILDCARD])
|
||||
test 2 ... ok ([WILDCARD])
|
||||
|
@ -18,6 +18,36 @@ test 9 ...
|
|||
console.error
|
||||
----- output end -----
|
||||
test 9 ... ok ([WILDCARD])
|
||||
test\b ...
|
||||
------- output -------
|
||||
console.error
|
||||
----- output end -----
|
||||
test\b ... ok ([WILDCARD])
|
||||
test\f ...
|
||||
------- output -------
|
||||
console.error
|
||||
----- output end -----
|
||||
test\f ... ok ([WILDCARD])
|
||||
test\t ...
|
||||
------- output -------
|
||||
console.error
|
||||
----- output end -----
|
||||
test\t ... ok ([WILDCARD])
|
||||
test\n ...
|
||||
------- output -------
|
||||
console.error
|
||||
----- output end -----
|
||||
test\n ... ok ([WILDCARD])
|
||||
test\r ...
|
||||
------- output -------
|
||||
console.error
|
||||
----- output end -----
|
||||
test\r ... ok ([WILDCARD])
|
||||
test\v ...
|
||||
------- output -------
|
||||
console.error
|
||||
----- output end -----
|
||||
test\v ... ok ([WILDCARD])
|
||||
|
||||
ok | 10 passed | 0 failed ([WILDCARD])
|
||||
ok | 16 passed | 0 failed ([WILDCARD])
|
||||
|
||||
|
|
23
cli/tests/testdata/test/pass.ts
vendored
23
cli/tests/testdata/test/pass.ts
vendored
|
@ -12,3 +12,26 @@ Deno.test("test 8", () => {
|
|||
Deno.test("test 9", () => {
|
||||
console.error("console.error");
|
||||
});
|
||||
|
||||
Deno.test("test\b", () => {
|
||||
console.error("console.error");
|
||||
});
|
||||
Deno.test("test\f", () => {
|
||||
console.error("console.error");
|
||||
});
|
||||
|
||||
Deno.test("test\t", () => {
|
||||
console.error("console.error");
|
||||
});
|
||||
|
||||
Deno.test("test\n", () => {
|
||||
console.error("console.error");
|
||||
});
|
||||
|
||||
Deno.test("test\r", () => {
|
||||
console.error("console.error");
|
||||
});
|
||||
|
||||
Deno.test("test\v", () => {
|
||||
console.error("console.error");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue