|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -const Transform = require('internal/streams/transform'); |
4 | | -const { TapLexer, TokenKind } = require('internal/test_runner/tap_lexer'); |
5 | | -const { TapChecker } = require('internal/test_runner/tap_checker'); |
6 | | -const { |
7 | | - codes: { ERR_TAP_VALIDATION_ERROR, ERR_TAP_PARSER_ERROR }, |
8 | | -} = require('internal/errors'); |
9 | | -const { kEmptyObject } = require('internal/util'); |
10 | 3 | const { |
11 | 4 | ArrayPrototypeFilter, |
12 | 5 | ArrayPrototypeForEach, |
| 6 | + ArrayPrototypeIncludes, |
13 | 7 | ArrayPrototypeJoin, |
14 | 8 | ArrayPrototypeMap, |
| 9 | + ArrayPrototypePop, |
15 | 10 | ArrayPrototypePush, |
16 | | - ArrayPrototypeIncludes, |
17 | | - ArrayPrototypeSplice, |
18 | 11 | Boolean, |
19 | 12 | Number, |
20 | 13 | RegExpPrototypeExec, |
21 | | - RegExpPrototypeSymbolReplace, |
22 | 14 | String, |
23 | | - StringPrototypeTrim, |
| 15 | + StringPrototypeEndsWith, |
| 16 | + StringPrototypeReplaceAll, |
| 17 | + StringPrototypeSlice, |
24 | 18 | StringPrototypeSplit, |
| 19 | + StringPrototypeTrim, |
25 | 20 | } = primordials; |
| 21 | +const Transform = require('internal/streams/transform'); |
| 22 | +const { TapLexer, TokenKind } = require('internal/test_runner/tap_lexer'); |
| 23 | +const { TapChecker } = require('internal/test_runner/tap_checker'); |
| 24 | +const { |
| 25 | + codes: { ERR_TAP_VALIDATION_ERROR, ERR_TAP_PARSER_ERROR }, |
| 26 | +} = require('internal/errors'); |
| 27 | +const { kEmptyObject } = require('internal/util'); |
26 | 28 | /** |
27 | 29 | * |
28 | 30 | * TAP14 specifications |
@@ -149,22 +151,26 @@ class TapParser extends Transform { |
149 | 151 | processChunk(chunk) { |
150 | 152 | const str = this.#lastLine + chunk.toString('utf8'); |
151 | 153 | const lines = StringPrototypeSplit(str, '\n'); |
152 | | - this.#lastLine = ArrayPrototypeSplice(lines, lines.length - 1, 1)[0]; |
| 154 | + this.#lastLine = ArrayPrototypePop(lines); |
153 | 155 |
|
154 | | - let chunkAsString = lines.join('\n'); |
| 156 | + let chunkAsString = ArrayPrototypeJoin(lines, '\n'); |
155 | 157 | // Special case where chunk is emitted by a child process |
156 | | - chunkAsString = RegExpPrototypeSymbolReplace( |
157 | | - /\[out\] /g, |
| 158 | + chunkAsString = StringPrototypeReplaceAll( |
158 | 159 | chunkAsString, |
| 160 | + '[out] ', |
159 | 161 | '' |
160 | 162 | ); |
161 | | - chunkAsString = RegExpPrototypeSymbolReplace( |
162 | | - /\[err\] /g, |
| 163 | + chunkAsString = StringPrototypeReplaceAll( |
163 | 164 | chunkAsString, |
| 165 | + '[err] ', |
164 | 166 | '' |
165 | 167 | ); |
166 | | - chunkAsString = RegExpPrototypeSymbolReplace(/\n$/, chunkAsString, ''); |
167 | | - chunkAsString = RegExpPrototypeSymbolReplace(/EOF$/, chunkAsString, ''); |
| 168 | + if (StringPrototypeEndsWith(chunkAsString, '\n')) { |
| 169 | + chunkAsString = StringPrototypeSlice(chunkAsString, 0, -1); |
| 170 | + } |
| 171 | + if (StringPrototypeEndsWith(chunkAsString, 'EOF')) { |
| 172 | + chunkAsString = StringPrototypeSlice(chunkAsString, 0, -3); |
| 173 | + } |
168 | 174 |
|
169 | 175 | return chunkAsString; |
170 | 176 | } |
@@ -371,7 +377,7 @@ class TapParser extends Transform { |
371 | 377 | } |
372 | 378 |
|
373 | 379 | #addDiagnosticsToLastTestPoint(currentNode) { |
374 | | - const lastTestPoint = this.#bufferedTestPoints.at(-1); |
| 380 | + const { length, [length - 1]: lastTestPoint } = this.#bufferedTestPoints; |
375 | 381 |
|
376 | 382 | // Diagnostic nodes are only added to Test points of the same nesting level |
377 | 383 | if (lastTestPoint && lastTestPoint.nesting === currentNode.nesting) { |
@@ -396,7 +402,7 @@ class TapParser extends Transform { |
396 | 402 |
|
397 | 403 | #flushBufferedTestPointNode(shouldClearBuffer = true) { |
398 | 404 | if (this.#bufferedTestPoints.length > 0) { |
399 | | - this.#emit(this.#bufferedTestPoints.at(0)); |
| 405 | + this.#emit(this.#bufferedTestPoints[0]); |
400 | 406 |
|
401 | 407 | if (shouldClearBuffer) { |
402 | 408 | this.#bufferedTestPoints = []; |
@@ -797,7 +803,7 @@ class TapParser extends Transform { |
797 | 803 |
|
798 | 804 | const commentContent = this.#peek(); |
799 | 805 | if (commentContent) { |
800 | | - if (/^Subtest:/i.test(commentContent.value)) { |
| 806 | + if (RegExpPrototypeExec(/^Subtest:/i, commentContent.value) !== null) { |
801 | 807 | this.#next(); // skip subtest keyword |
802 | 808 | const name = StringPrototypeTrim(this.#readNextLiterals()); |
803 | 809 | const node = { |
@@ -898,7 +904,7 @@ class TapParser extends Transform { |
898 | 904 | // YAMLLine := " " (YAML)* "\n" |
899 | 905 | #YAMLLine() { |
900 | 906 | const yamlLiteral = this.#readNextLiterals(); |
901 | | - const { 0: key, 1: value } = StringPrototypeSplit(yamlLiteral, ':'); |
| 907 | + const { 0: key, 1: value } = StringPrototypeSplit(yamlLiteral, ':', 2); |
902 | 908 |
|
903 | 909 | // Note that this.#lastTestPointDetails has been cleared when we encounter a YAML start marker |
904 | 910 |
|
@@ -960,7 +966,7 @@ class TapParser extends Transform { |
960 | 966 |
|
961 | 967 | // In some cases, pragma key can be followed by a comma separator, |
962 | 968 | // so we need to remove it |
963 | | - pragmaKey = RegExpPrototypeSymbolReplace(/,/g, pragmaKey, ''); |
| 969 | + pragmaKey = StringPrototypeReplaceAll(pragmaKey, ',', ''); |
964 | 970 |
|
965 | 971 | pragmas[pragmaKey] = isEnabled; |
966 | 972 | nextToken = this.#peek(); |
|