Skip to content

Commit 4f5aff2

Browse files
pulkit-30juanarbol
authored andcommitted
test: fix tap parser fails if a test logs a number
PR-URL: #46056 Backport-PR-URL: #46839 Fixes: #46048 Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent ba784e8 commit 4f5aff2

File tree

3 files changed

+199
-140
lines changed

3 files changed

+199
-140
lines changed

lib/internal/test_runner/tap_parser.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,19 @@ class TapParser extends Transform {
270270
this.#yamlCurrentIndentationLevel = this.#subTestNestingLevel;
271271
}
272272

273+
let node;
274+
273275
// Parse current chunk
274-
const node = this.#TAPDocument(chunk);
276+
try {
277+
node = this.#TAPDocument(chunk);
278+
} catch {
279+
node = {
280+
kind: TokenKind.UNKNOWN,
281+
node: {
282+
value: this.#currentChunkAsString,
283+
},
284+
};
285+
}
275286

276287
// Emit the parsed node to both the stream and the AST
277288
this.#emitOrBufferCurrentNode(node);
@@ -282,12 +293,6 @@ class TapParser extends Transform {
282293
}
283294

284295
#error(message) {
285-
if (!this.#isSyncParsingEnabled) {
286-
// When async parsing is enabled, don't throw.
287-
// Unrecognized tokens would be ignored.
288-
return;
289-
}
290-
291296
const token = this.#currentToken || { value: '', kind: '' };
292297
// Escape NewLine characters
293298
if (token.value === '\n') {

test/parallel/test-runner-tap-parser-stream.js

+187
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,193 @@ const cases = [
1717
},
1818
],
1919
},
20+
{
21+
input: '123',
22+
expected: [
23+
{
24+
kind: 'Unknown',
25+
node: { value: '123' },
26+
nesting: 0,
27+
lexeme: '123',
28+
},
29+
],
30+
},
31+
{
32+
input: '# 123',
33+
expected: [
34+
{
35+
kind: 'Comment',
36+
node: { comment: '123' },
37+
nesting: 0,
38+
lexeme: '# 123',
39+
},
40+
],
41+
},
42+
{
43+
input: '1..',
44+
expected: [
45+
{
46+
kind: 'Unknown',
47+
node: { value: '1..' },
48+
nesting: 0,
49+
lexeme: '1..',
50+
},
51+
],
52+
},
53+
{
54+
input: '1..abc',
55+
expected: [
56+
{
57+
kind: 'Unknown',
58+
node: { value: '1..abc' },
59+
nesting: 0,
60+
lexeme: '1..abc',
61+
},
62+
],
63+
},
64+
{
65+
input: '1..-1',
66+
expected: [
67+
{
68+
kind: 'Unknown',
69+
node: { value: '1..-1' },
70+
nesting: 0,
71+
lexeme: '1..-1',
72+
},
73+
],
74+
},
75+
{
76+
input: '1.1',
77+
expected: [
78+
{
79+
kind: 'Unknown',
80+
node: { value: '1.1' },
81+
nesting: 0,
82+
lexeme: '1.1',
83+
},
84+
],
85+
},
86+
{
87+
input: '1.....4',
88+
expected: [
89+
{
90+
kind: 'Unknown',
91+
node: { value: '1.....4' },
92+
nesting: 0,
93+
lexeme: '1.....4',
94+
},
95+
],
96+
},
97+
{
98+
input: 'TAP 12',
99+
expected: [
100+
{
101+
kind: 'Unknown',
102+
node: { value: 'TAP 12' },
103+
nesting: 0,
104+
lexeme: 'TAP 12',
105+
},
106+
],
107+
},
108+
{
109+
input: 'TAP version',
110+
expected: [
111+
{
112+
kind: 'Unknown',
113+
node: { value: 'TAP version' },
114+
nesting: 0,
115+
lexeme: 'TAP version',
116+
},
117+
],
118+
},
119+
{
120+
input: 'TAP version v14',
121+
expected: [
122+
{
123+
kind: 'Unknown',
124+
node: { value: 'TAP version v14' },
125+
nesting: 0,
126+
lexeme: 'TAP version v14',
127+
},
128+
],
129+
},
130+
{
131+
input: 'TAP TAP TAP',
132+
expected: [
133+
{
134+
kind: 'Unknown',
135+
node: { value: 'TAP TAP TAP' },
136+
nesting: 0,
137+
lexeme: 'TAP TAP TAP',
138+
},
139+
],
140+
},
141+
{
142+
input: '--- yaml',
143+
expected: [
144+
{
145+
kind: 'Unknown',
146+
node: { value: '--- yaml' },
147+
nesting: 0,
148+
lexeme: '--- yaml',
149+
},
150+
],
151+
},
152+
{
153+
input: '... ... yaml',
154+
expected: [
155+
{
156+
kind: 'Unknown',
157+
node: { value: '... ... yaml' },
158+
nesting: 0,
159+
lexeme: '... ... yaml',
160+
},
161+
],
162+
},
163+
{
164+
input: 'ook 1',
165+
expected: [
166+
{
167+
kind: 'Unknown',
168+
node: { value: 'ook 1' },
169+
nesting: 0,
170+
lexeme: 'ook 1',
171+
},
172+
],
173+
},
174+
{
175+
input: ' ok 98',
176+
expected: [
177+
{
178+
kind: 'Unknown',
179+
node: { value: ' ok 98' },
180+
nesting: 0,
181+
lexeme: ' ok 98',
182+
},
183+
],
184+
},
185+
{
186+
input: 'pragma ++++++',
187+
expected: [
188+
{
189+
kind: 'Unknown',
190+
node: { value: 'pragma ++++++' },
191+
nesting: 0,
192+
lexeme: 'pragma ++++++',
193+
},
194+
],
195+
},
196+
{
197+
input: 'Bailout!',
198+
expected: [
199+
{
200+
kind: 'Unknown',
201+
node: { value: 'Bailout!' },
202+
nesting: 0,
203+
lexeme: 'Bailout!',
204+
},
205+
],
206+
},
20207
{
21208
input: 'invalid tap',
22209
expected: [

0 commit comments

Comments
 (0)