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