diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-08-10 01:40:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-10 01:40:34 +0200 |
commit | 04a259e2c8b3fdca8371f35e923bc239e8bb9ec0 (patch) | |
tree | 536b3c134cad5dcd8345c19f6433e9e03669d9be /cli/js | |
parent | 414274b68a80199c3fb6bfb3890b0afb79f5b7f9 (diff) |
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.
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/40_testing.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js index c073b1c18..21417db23 100644 --- a/cli/js/40_testing.js +++ b/cli/js/40_testing.js @@ -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; |