Skip to content

Commit 165ff7c

Browse files
committed
fix: unhandled parser error
When the test code has code error, the TestItem for the test file must be remain with empty children(test cases).
1 parent 22e5b7e commit 165ff7c

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

src/worker/parsers/index.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ export async function parse(this: WorkerMetaContext, options: ReadSpecsOptions)
1313
const normalizeSpecPath = path.normalize(spec)
1414
this.log.debug(`Parse spec file: ${normalizeSpecPath}`)
1515
const contents = await fs.readFile(normalizeSpecPath, { encoding: 'utf8' })
16+
try {
17+
const testCases = isCucumberFeatureFile(normalizeSpecPath)
18+
? parseCucumberFeature.call(this, contents, normalizeSpecPath) // Parse Cucumber feature file
19+
: parseTestCases.call(this, contents, normalizeSpecPath) // Parse JavaScript/TypeScript test file
1620

17-
const testCases = isCucumberFeatureFile(normalizeSpecPath)
18-
? parseCucumberFeature.call(this, contents, normalizeSpecPath) // Parse Cucumber feature file
19-
: parseTestCases.call(this, contents, normalizeSpecPath) // Parse JavaScript/TypeScript test file
20-
21-
this.log.debug(`Successfully parsed: ${normalizeSpecPath}`)
22-
return {
23-
spec: normalizeSpecPath,
24-
tests: testCases,
21+
this.log.debug(`Successfully parsed: ${normalizeSpecPath}`)
22+
return {
23+
spec: normalizeSpecPath,
24+
tests: testCases,
25+
}
26+
} catch (error) {
27+
const errorMessage = error instanceof Error ?error.message : String(error)
28+
this.log.error(`Parse error: ${errorMessage}`)
29+
return {
30+
spec: normalizeSpecPath,
31+
tests: [],
32+
}
2533
}
2634
})
2735
)

0 commit comments

Comments
 (0)