Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
a9412ce
test_runner: add initial TAP parser
manekinekko Jun 11, 2022
487ccd4
test_runner: wip
manekinekko Jun 12, 2022
605a29c
test_runner: tap parser (wip)
manekinekko Jun 13, 2022
01ecd07
test_runner: tap parser (wip)
manekinekko Jun 13, 2022
3b01d1c
test_runner: tap parser (wip)
manekinekko Jun 14, 2022
3951075
test_runner: tap parser
manekinekko Jun 14, 2022
61dc763
test_runner: tap parser
manekinekko Jun 16, 2022
23b0e10
test_runner: tap parser
manekinekko Jun 17, 2022
660cf7f
test_runner: tap parser
manekinekko Jun 17, 2022
dfbaedd
test_runner: tap parser
manekinekko Jun 17, 2022
37d9ecf
test_runner: tap parser
manekinekko Jun 17, 2022
4a8c65b
test_runner: tap parser
manekinekko Jun 17, 2022
3ee7515
test_runner: tap parser
manekinekko Jun 17, 2022
2416978
test_runner: tap parser
manekinekko Jun 17, 2022
0ece7b0
test_runner: tap parser
manekinekko Jun 19, 2022
9ab6884
test_runner: tap parser
manekinekko Jun 19, 2022
517a908
test_runner: tap parser
manekinekko Jun 20, 2022
9475fa9
test_runner: tap parser
manekinekko Jun 20, 2022
3833046
test_runner: tap parser
manekinekko Jun 20, 2022
62246df
test_runner: tap parser
manekinekko Jun 20, 2022
e4b2e9b
test_runner: tap parser
manekinekko Jun 20, 2022
5ed3ca3
test_runner: tap parser
manekinekko Jun 20, 2022
7acf083
test_runner: tap parser
manekinekko Jun 21, 2022
a0d5a8e
test_runner: remove scanAll()
manekinekko Jun 27, 2022
0a1924a
test_runner: add tests for TapParser
manekinekko Jun 27, 2022
65ae33c
test_runner: improve YAML block parsing
manekinekko Jun 30, 2022
c8406cc
test_runner: improve edge cases parsing
manekinekko Jul 1, 2022
09ce126
test_runner: add TAP checker
manekinekko Jul 1, 2022
bc02445
test_runner: use consistent method names
manekinekko Jul 2, 2022
e7217b0
test_runner: refactor tap checker
manekinekko Jul 12, 2022
f5a5d50
test_runner: multiple changes
manekinekko Jul 12, 2022
8a77263
test_runner: multiple changes in lexer
manekinekko Jul 12, 2022
aa9ce96
test_runner: fix linting issues
manekinekko Jul 13, 2022
32028b9
test_runner: add initial stream parsing foundation
manekinekko Sep 22, 2022
4f2392a
test_runner: add stream parsing support
manekinekko Sep 22, 2022
86d554b
test_runner: remove unused fixture
manekinekko Sep 23, 2022
ff3e1a5
test_runner: rename level to nesting
manekinekko Sep 23, 2022
7e65f67
test_runner: remove unnecessary calls
manekinekko Sep 23, 2022
b05921f
test_runner: fix formatting
manekinekko Sep 23, 2022
8684a53
test_runner: update test events in test.md
manekinekko Sep 23, 2022
a6051d2
test_runner: remove unnecessary async
manekinekko Sep 23, 2022
5090016
test_runner: rename variable
manekinekko Sep 23, 2022
7a56b6e
test_runner: fix lint errors
manekinekko Sep 27, 2022
83c5d05
test_runner: lowercase TAP validation errors
manekinekko Sep 27, 2022
4a2e830
test_runner: remove --expose-internals
manekinekko Sep 27, 2022
2a5c87b
test_runner: add regex parser
manekinekko Sep 30, 2022
7a5a6a2
test_runner: optimize lexer
manekinekko Oct 1, 2022
1714ed8
test_runner: add benchmark results
manekinekko Oct 1, 2022
c75d215
test_runner: fix lint errors
manekinekko Oct 1, 2022
24f5463
test_runner: output invalid nesting as comment
manekinekko Oct 1, 2022
84b9608
test_runner: support other TAP specs in stream
manekinekko Oct 1, 2022
b7d58d6
test_runner: Update doc/api/test.md
manekinekko Oct 3, 2022
92a1ff7
test_runner: Update doc/api/test.md
manekinekko Oct 3, 2022
a73a2c8
test_runner: fix lint errors
manekinekko Oct 3, 2022
2c4996a
test_runner: update tests
manekinekko Oct 3, 2022
62d42e7
test_runner: migrate to primordials
manekinekko Oct 5, 2022
7bdd9fc
test_runner: fix lint errors
manekinekko Oct 5, 2022
a724ebb
test_runner: clean unit tests
manekinekko Oct 6, 2022
0d2f1b7
test_runner: remove benchmark code
manekinekko Oct 7, 2022
ee914de
test_runner: address code review changes
manekinekko Oct 10, 2022
d3f5b73
test_runner: scanTAPkeyword -> scanTAPKeyword
manekinekko Oct 10, 2022
d33b5c6
test_runner: address code review
manekinekko Oct 10, 2022
153a1eb
test_runner: fix typo
manekinekko Oct 10, 2022
2522806
test_runner: handle empty TAP content
manekinekko Oct 10, 2022
75607bf
test_runner: handle tests emitted by child process
manekinekko Oct 11, 2022
abb9841
test_runner: fix lint errors
manekinekko Oct 11, 2022
754289b
test_runner: add time + comments to test nodes
manekinekko Oct 11, 2022
2959e52
test_runner: update runner with new AST signature
manekinekko Oct 12, 2022
882ac35
test_runner: add test for TAP stream parser
manekinekko Oct 12, 2022
8b9aeb8
test_runner: emit diagnostic data with test points
manekinekko Oct 12, 2022
addc228
test_runner: add new line in test file
manekinekko Oct 13, 2022
880eacd
test_runner: add output message tests
manekinekko Oct 16, 2022
e78a43f
test_runner: parse extra AssertionError YAML keys
manekinekko Oct 16, 2022
b68be46
test_runner: surface data on stderr
manekinekko Oct 16, 2022
88d63da
test_runner: revert tap_stream code
manekinekko Oct 16, 2022
eef13be
test_runner: surface invalid data on stderr
manekinekko Oct 16, 2022
3281172
test_runner: rename fixture file name
manekinekko Oct 16, 2022
5500967
Update test/parallel/test-runner-tap-checker.js
manekinekko Oct 17, 2022
84048d3
Update lib/internal/test_runner/tap_stream.js
manekinekko Oct 17, 2022
05966ea
Update lib/internal/test_runner/tap_stream.js
manekinekko Oct 17, 2022
5d17b66
Update test/message/test_runner_output_cli.js
manekinekko Oct 17, 2022
6a9c2db
Update lib/internal/test_runner/tap_checker.js
manekinekko Oct 17, 2022
815619d
test_runner: sort TAP errors alphabetically
manekinekko Oct 17, 2022
e87ea14
test_runner: move kDefaultIndent to test.js
manekinekko Oct 17, 2022
7391efa
test_runner: update TAP version in test message
manekinekko Oct 17, 2022
87fb339
test_runner: update formatting
manekinekko Oct 17, 2022
07aa2cb
test_runner: revert surfacing data on stderr
manekinekko Oct 17, 2022
002e780
test_runner: improve buffered test points
manekinekko Oct 20, 2022
bb6dcf8
test_runner: remove message tests - add parallel
manekinekko Oct 21, 2022
56d7cec
test_runner: fix regex lint errors
manekinekko Oct 21, 2022
7559958
test_runner: revert testcfg.py
manekinekko Oct 21, 2022
7a606e6
test_runner: clean console logs
manekinekko Oct 21, 2022
c454f9b
test_runner: buffer stream data
manekinekko Oct 27, 2022
8c83787
test_runner: fix undefined callbacks
manekinekko Oct 28, 2022
4194651
test_runner: add aduh95 suggestions from code review
manekinekko Nov 19, 2022
962fae8
test_runner: fix conflicts with main
manekinekko Nov 19, 2022
d355e4c
test_runner: get rid of the unused code blocks in TAPChecker tests
manekinekko Nov 21, 2022
4f5bbc2
test_runner: fix indentation in TAPChecker tests
manekinekko Nov 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test_runner: add time + comments to test nodes
  • Loading branch information
manekinekko committed Nov 19, 2022
commit 754289b7f3887ad73bab9e3f1bd82927c5995ff5
10 changes: 4 additions & 6 deletions lib/internal/test_runner/tap_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TAPValidationStrategy {
throw new ERR_TAP_VALIDATION_ERROR('missing TAP plan');
}

const { plan } = entry.node;
const plan = entry.node;

if (!plan.start) {
throw new ERR_TAP_VALIDATION_ERROR('missing plan start');
Expand Down Expand Up @@ -81,12 +81,10 @@ class TAPValidationStrategy {
);
const testPointEntries = ArrayPrototypeFilter(
ast,
(node) =>
node.kind === TokenKind.TAP_TEST_OK ||
node.kind === TokenKind.TAP_TEST_NOTOK
(node) => node.kind === TokenKind.TAP_TEST_POINT
);

const { plan } = planEntry.node;
const plan = planEntry.node;

const planStart = NumberParseInt(plan.start, 10);
const planEnd = NumberParseInt(plan.end, 10);
Expand All @@ -111,7 +109,7 @@ class TAPValidationStrategy {
}

for (let i = 0; i < testPointEntries.length; i++) {
const { test } = testPointEntries[i].node;
const test = testPointEntries[i].node;
const testId = NumberParseInt(test.id, 10);

if (testId < planStart || testId > planEnd) {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/test_runner/tap_lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const TokenKind = {
TAP: 'TAPKeyword',
TAP_VERSION: 'VersionKeyword',
TAP_PLAN: 'PlanKeyword',
TAP_TEST_POINT: 'TestPointKeyword',
TAP_SUBTEST_POINT: 'SubTestPointKeyword',
TAP_TEST_OK: 'TestOkKeyword',
TAP_TEST_NOTOK: 'TestNotOkKeyword',
Expand Down
93 changes: 80 additions & 13 deletions lib/internal/test_runner/tap_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ const {
const { kEmptyObject } = require('internal/util');
const {
ArrayPrototypeFilter,
ArrayPrototypeForEach,
ArrayPrototypeJoin,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeIncludes,
Number,
RegExpPrototypeExec,
RegExpPrototypeSymbolReplace,
StringPrototypeTrim,
StringPrototypeSplit,
} = primordials;
Comment on lines +3 to +25

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const Transform = require('internal/streams/transform');
const { TapLexer, TokenKind } = require('internal/test_runner/tap_lexer');
const { TapChecker } = require('internal/test_runner/tap_checker');
const {
codes: { ERR_TAP_VALIDATION_ERROR, ERR_TAP_PARSER_ERROR },
} = require('internal/errors');
const { kEmptyObject } = require('internal/util');
const {
ArrayPrototypeFilter,
ArrayPrototypeForEach,
ArrayPrototypeJoin,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeIncludes,
ArrayPrototypeSplice,
Boolean,
Number,
RegExpPrototypeExec,
RegExpPrototypeSymbolReplace,
String,
StringPrototypeTrim,
StringPrototypeSplit,
} = primordials;
const {
ArrayPrototypeFilter,
ArrayPrototypeForEach,
ArrayPrototypeIncludes,
ArrayPrototypeJoin,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeSplice,
Boolean,
Number,
RegExpPrototypeExec,
RegExpPrototypeSymbolReplace,
String,
StringPrototypeSplit,
StringPrototypeTrim,
hardenRegExp,
} = primordials;
const Transform = require('internal/streams/transform');
const { TapLexer, TokenKind } = require('internal/test_runner/tap_lexer');
const { TapChecker } = require('internal/test_runner/tap_checker');
const {
codes: { ERR_TAP_VALIDATION_ERROR, ERR_TAP_PARSER_ERROR },
} = require('internal/errors');
const { kEmptyObject } = require('internal/util');

/**
*
Expand Down Expand Up @@ -55,8 +58,10 @@ class TapParser extends Transform {
#currentTokenIndex = 0;
#currentTokenChunk = 0;
#currentToken = null;
#flatAst = [];
#commentsBuffer = [];
#flatAST = [];
#subTestNestingLevel = 0;
#lastTestPointDuration = 0;
#yamlBlockBuffer = [];
#isYAMLBlock = false;
#yamlCurrentIndentationLevel = 0;
Expand Down Expand Up @@ -103,14 +108,20 @@ class TapParser extends Transform {
this.#error('Expected end of YAML block');
}

return this.#flatAst;
if (this.#commentsBuffer.length > 0) {
ArrayPrototypeForEach(this.#commentsBuffer, (comment) => {
ArrayPrototypePush(this.#flatAST, comment);
});
}

return this.#flatAST;
}

// Check if the TAP content is semantically valid
// Note: Validating the TAP content requires the whole AST to be available.
check() {
if (this.#isSyncParsingEnabled) {
return this.#checker.check(this.#flatAst);
return this.#checker.check(this.#flatAST);
}

// TODO(@manekinekko): when running in async mode, it doesn't make sense to
Expand Down Expand Up @@ -159,7 +170,6 @@ class TapParser extends Transform {
// ----------------------------- Private API ----------------------------//
// ----------------------------------------------------------------------//


#parseTokens(callback = null) {
for (let index = 0; index < this.#tokens.length; index++) {
const chunk = this.#tokens[index];
Expand Down Expand Up @@ -303,20 +313,72 @@ class TapParser extends Transform {
return (whitespaceCount / this.#kSubtestBlockIndentationFactor) | 0;
}

// This method has 2 purposes:
// 1. It adds a new node to the (flat) AST
// 2. It returns that same node to the stream interface (for async parsing)
#emit(value) {
value = {
...value,
nesting: this.#subTestNestingLevel,
};
ArrayPrototypePush(this.#flatAst, value);

// If we are emitting a YAML block, we need to update the last node in the
// AST to include the YAML block as diagnostic.
// We only do this to produce an AST with fewer nodes.
if (value.kind === TokenKind.TAP_YAML_END) {
const lastNode = this.#flatAST.at(-1);

// Diagnostic nodes are only added to Test points of the same nesting level
if (
lastNode?.kind === TokenKind.TAP_TEST_POINT &&
lastNode?.nesting === value.nesting
) {
lastNode.node.time = this.#lastTestPointDuration;
lastNode.node.diagnostics ||= [];

ArrayPrototypeForEach(value.node.diagnostics, (diagnostic) => {
ArrayPrototypePush(lastNode.node.diagnostics, diagnostic);
});

// eslint-disable-next-line brace-style
}

// Orphan YAML blocks? These are maybe general purpose YAML blocks
// So we add them to the AST as a YAML diagnostic.
else {
ArrayPrototypePush(this.#flatAST, value);
}
// eslint-disable-next-line brace-style
}

// We process any pending comments before emitting the current node
else if (value.kind === TokenKind.COMMENT) {
ArrayPrototypePush(this.#commentsBuffer, value);
} else {
// If we have pending comments, we add them to the current node
if (this.#commentsBuffer.length > 0) {
value.comments = ArrayPrototypeMap(
this.#commentsBuffer,
(c) => c.node.comment
);
this.#commentsBuffer = [];
}

ArrayPrototypePush(this.#flatAST, value);
}

return value;
}

#serializeChunk(chunk) {
return ArrayPrototypeJoin(
ArrayPrototypeMap(
// Exclude EOL and EOF tokens
ArrayPrototypeFilter(chunk, (token) => token.kind !== TokenKind.EOL && token.kind !== TokenKind.EOF),
ArrayPrototypeFilter(
chunk,
(token) =>
token.kind !== TokenKind.EOL && token.kind !== TokenKind.EOF
),
(token) => token.value
),
''
Expand Down Expand Up @@ -448,9 +510,7 @@ class TapParser extends Transform {

const node = {
kind: TokenKind.TAP_PLAN,
node: {
plan,
},
node: plan,
};

return this.#emit(node);
Expand Down Expand Up @@ -499,6 +559,7 @@ class TapParser extends Transform {
id: numberToken,
description: '',
reason: '',
time: 0,
};

// Read optional description prefix " - "
Expand Down Expand Up @@ -543,10 +604,8 @@ class TapParser extends Transform {
}

const node = {
kind: isTestFailed ? TokenKind.TAP_TEST_NOTOK : TokenKind.TAP_TEST_OK,
node: {
test,
},
kind: TokenKind.TAP_TEST_POINT,
node: test,
};

return this.#emit(node);
Expand Down Expand Up @@ -687,6 +746,14 @@ class TapParser extends Transform {
// YAMLLine := " " (YAML)* "\n"
#YAMLLine() {
const yamlLiteral = this.#readNextLiterals();
const { 0: key, 1: value } = StringPrototypeSplit(yamlLiteral, ':');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { 0: key, 1: value } = StringPrototypeSplit(yamlLiteral, ':');
const { 0: key, 1: value } = StringPrototypeSplit(yamlLiteral, ':', 2);


switch (key) {
case 'duration_ms':
this.#lastTestPointDuration = Number(value);
break;
}

ArrayPrototypePush(this.#yamlBlockBuffer, yamlLiteral);
}

Expand Down
Loading