Skip to content

Commit 66da6fe

Browse files
pulkit-30MoLow
authored andcommitted
fix: fix tap parser fails if a test logs a number
PR-URL: nodejs/node#46056 Fixes: nodejs/node#46048 Reviewed-By: Moshe Atlow <[email protected]> (cherry picked from commit 4c08c20e575a0954fe3977a20e9f52b4980a2e48)
1 parent b5b3f0b commit 66da6fe

File tree

3 files changed

+202
-143
lines changed

3 files changed

+202
-143
lines changed

lib/internal/test_runner/tap_parser.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/931f035bac8326a11f42fc05463d5b21d9bec502/lib/internal/test_runner/tap_parser.js
1+
// https://github.com/nodejs/node/blob/4c08c20e575a0954fe3977a20e9f52b4980a2e48/lib/internal/test_runner/tap_parser.js
22
'use strict'
33

44
const {
@@ -271,8 +271,19 @@ class TapParser extends Transform {
271271
this.#yamlCurrentIndentationLevel = this.#subTestNestingLevel
272272
}
273273

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

277288
// Emit the parsed node to both the stream and the AST
278289
this.#emitOrBufferCurrentNode(node)
@@ -283,12 +294,6 @@ class TapParser extends Transform {
283294
}
284295

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

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

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

0 commit comments

Comments
 (0)