Skip to content

Commit 26a2476

Browse files
committed
test_runner: parse extra AssertionError YAML keys
1 parent d4300e2 commit 26a2476

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

lib/internal/test_runner/tap_parser.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ const {
1414
ArrayPrototypeMap,
1515
ArrayPrototypePush,
1616
ArrayPrototypeIncludes,
17+
Boolean,
1718
Number,
1819
RegExpPrototypeExec,
1920
RegExpPrototypeSymbolReplace,
21+
String,
2022
StringPrototypeTrim,
2123
StringPrototypeSplit,
2224
} = primordials;
@@ -62,7 +64,7 @@ class TapParser extends Transform {
6264
#bufferedTestPoints = [];
6365
#flatAST = [];
6466
#subTestNestingLevel = 0;
65-
#lastTestPointDuration = 0;
67+
#lastTestPointDetails = {};
6668
#yamlBlockBuffer = [];
6769
#isYAMLBlock = false;
6870
#yamlCurrentIndentationLevel = 0;
@@ -209,7 +211,6 @@ class TapParser extends Transform {
209211

210212
let astNode = this.#TAPDocument(chunk);
211213

212-
213214
// Mark the current chunk as processed
214215
// only when there is data to emit
215216
if (astNode) {
@@ -382,7 +383,10 @@ class TapParser extends Transform {
382383
lastNode?.kind === TokenKind.TAP_TEST_POINT &&
383384
lastNode?.nesting === value.nesting
384385
) {
385-
lastNode.node.time = this.#lastTestPointDuration;
386+
lastNode.node.time = this.#lastTestPointDetails.duration;
387+
388+
// TODO(@manekinekko): figure out where to put the other diagnostic properties
389+
// See https://github.com/nodejs/node/pull/44952
386390
lastNode.node.diagnostics ||= [];
387391

388392
ArrayPrototypeForEach(value.node.diagnostics, (diagnostic) => {
@@ -395,8 +399,6 @@ class TapParser extends Transform {
395399
// No need to pass this node to the stream interface
396400
// because diagnostics are already added to the last test node
397401
return;
398-
399-
400402
}
401403

402404
// Orphan YAML blocks? These are maybe general purpose YAML blocks
@@ -731,7 +733,6 @@ class TapParser extends Transform {
731733
}
732734

733735
// If there is no comment content, then we ignore the current node
734-
735736
}
736737

737738
// ----------------YAMLBlock----------------
@@ -764,13 +765,13 @@ class TapParser extends Transform {
764765

765766
this.#isYAMLBlock = true;
766767
this.#yamlCurrentIndentationLevel = this.#subTestNestingLevel;
768+
this.#lastTestPointDetails = {};
767769

768770
// Consume the YAML start marker
769771
this.#next(false); // skip "---"
770772

771773
// No need to pass this token to the stream interface
772774
return;
773-
774775
} else if (yamlBlockSymbol.kind === TokenKind.TAP_YAML_END) {
775776
this.#next(false); // skip "..."
776777

@@ -812,11 +813,22 @@ class TapParser extends Transform {
812813
const yamlLiteral = this.#readNextLiterals();
813814
const { 0: key, 1: value } = StringPrototypeSplit(yamlLiteral, ':');
814815

816+
// Note that this.#lastTestPointDetails has been cleared when we encounter a YAML start marker
817+
815818
switch (key) {
816819
case 'duration_ms':
817-
this.#lastTestPointDuration = Number(value);
820+
this.#lastTestPointDetails.duration = Number(value);
821+
break;
822+
// Below are diagnostic properties introduced in https://github.com/nodejs/node/pull/44952
823+
case 'expected':
824+
this.#lastTestPointDetails.expected = Boolean(value);
825+
break;
826+
case 'actual':
827+
this.#lastTestPointDetails.actual = Boolean(value);
828+
break;
829+
case 'operator':
830+
this.#lastTestPointDetails.operator = String(value);
818831
break;
819-
// TODO(@manekinekko): should we handle other diagnostics data?
820832
}
821833

822834
ArrayPrototypePush(this.#yamlBlockBuffer, yamlLiteral);
@@ -837,8 +849,10 @@ class TapParser extends Transform {
837849
let nextToken = this.#peek();
838850
while (
839851
nextToken &&
840-
ArrayPrototypeIncludes([TokenKind.NEWLINE, TokenKind.EOF, TokenKind.EOL], nextToken.kind) ===
841-
false
852+
ArrayPrototypeIncludes(
853+
[TokenKind.NEWLINE, TokenKind.EOF, TokenKind.EOL],
854+
nextToken.kind
855+
) === false
842856
) {
843857
let isEnabled = true;
844858
const pragmaKeySign = this.#next();

0 commit comments

Comments
 (0)