11import * as fs from 'node:fs/promises'
22import path from 'node:path'
33
4- import { parseCucumberFeature } from './cucumber.js'
5- import { parseTestCases } from './js.js'
4+ import { getAstParser , getCucumberParser } from './utils.js'
65import type { ReadSpecsOptions } from '@vscode-wdio/types/api'
76import type { WorkerMetaContext } from '@vscode-wdio/types/worker'
87
8+ async function parseFeatureFile ( context : WorkerMetaContext , contents : string , normalizeSpecPath : string ) {
9+ const p = await getCucumberParser ( context )
10+ return p . call ( context , contents , normalizeSpecPath )
11+ }
12+
13+ async function parseJsFile ( context : WorkerMetaContext , contents : string , normalizeSpecPath : string ) {
14+ const p = await getAstParser ( context )
15+ return p . call ( context , contents , normalizeSpecPath )
16+ }
17+
918export async function parse ( this : WorkerMetaContext , options : ReadSpecsOptions ) {
1019 return await Promise . all (
1120 options . specs . map ( async ( spec ) => {
@@ -14,8 +23,8 @@ export async function parse(this: WorkerMetaContext, options: ReadSpecsOptions)
1423 const contents = await fs . readFile ( normalizeSpecPath , { encoding : 'utf8' } )
1524 try {
1625 const testCases = isCucumberFeatureFile ( normalizeSpecPath )
17- ? parseCucumberFeature . call ( this , contents , normalizeSpecPath ) // Parse Cucumber feature file
18- : parseTestCases . call ( this , contents , normalizeSpecPath ) // Parse JavaScript/TypeScript test file
26+ ? await parseFeatureFile ( this , contents , normalizeSpecPath ) // Parse Cucumber feature file
27+ : await parseJsFile ( this , contents , normalizeSpecPath ) // Parse JavaScript/TypeScript test file
1928
2029 this . log . debug ( `Successfully parsed: ${ normalizeSpecPath } ` )
2130 return {
0 commit comments