@@ -6,12 +6,10 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
66// Import parse function from parsers
77
88import { parse } from '../../src/parsers/index.js'
9- import { parseTestCases } from '../../src/parsers/js.js'
10- import { getCucumberParser } from '../../src/parsers/utils.js'
9+ import { getAstParser , getCucumberParser } from '../../src/parsers/utils.js'
1110import type { ReadSpecsOptions } from '@vscode-wdio/types/api'
1211import type { WorkerMetaContext , TestData , CucumberTestData } from '@vscode-wdio/types/worker'
1312
14- // Import the types
1513// Mock fs module
1614vi . mock ( 'node:fs/promises' , ( ) => ( {
1715 readFile : vi . fn ( ) ,
@@ -20,14 +18,9 @@ vi.mock('node:fs/promises', () => ({
2018// Mock the parsers
2119vi . mock ( '../../src/parsers/utils.js' , ( ) => ( {
2220 getCucumberParser : vi . fn ( ) ,
21+ getAstParser : vi . fn ( ) ,
2322} ) )
2423
25- vi . mock ( '../../src/parsers/js.js' , ( ) => ( {
26- parseTestCases : vi . fn ( ) ,
27- } ) )
28-
29- // Import mocked modules
30-
3124describe ( 'Parser Index' , ( ) => {
3225 // Create mock context
3326 const mockContext : WorkerMetaContext = {
@@ -59,6 +52,7 @@ describe('Parser Index', () => {
5952 ] ,
6053 } ,
6154 ]
55+ const mockAstParser = vi . fn ( ( ) => jsMockTestData )
6256
6357 const cucumberMockTestData : CucumberTestData [ ] = [
6458 {
@@ -93,8 +87,9 @@ describe('Parser Index', () => {
9387 vi . resetAllMocks ( )
9488
9589 // Mock the parseTestCases and parseCucumberFeature functions
96- vi . mocked ( parseTestCases ) . mockReturnValue ( jsMockTestData )
90+ // vi.mocked(parseTestCases).mockReturnValue(jsMockTestData)
9791 vi . mocked ( getCucumberParser ) . mockResolvedValue ( mockCucumberParser )
92+ vi . mocked ( getAstParser ) . mockResolvedValue ( mockAstParser )
9893 } )
9994
10095 afterEach ( ( ) => {
@@ -120,7 +115,7 @@ describe('Parser Index', () => {
120115 expect ( result [ 0 ] . tests ) . toEqual ( jsMockTestData )
121116
122117 // Verify the correct parser was called
123- expect ( parseTestCases ) . toHaveBeenCalledWith ( jsTestContent , path . normalize ( '/path/to/test.js' ) )
118+ expect ( mockAstParser ) . toHaveBeenCalledWith ( jsTestContent , path . normalize ( '/path/to/test.js' ) )
124119 expect ( mockCucumberParser ) . not . toHaveBeenCalled ( )
125120
126121 // Verify logging
@@ -148,7 +143,7 @@ describe('Parser Index', () => {
148143 expect ( result [ 0 ] . tests ) . toEqual ( jsMockTestData )
149144
150145 // Verify the correct parser was called
151- expect ( parseTestCases ) . toHaveBeenCalledWith ( jsTestContent , path . normalize ( '/path/to/test.ts' ) )
146+ expect ( mockAstParser ) . toHaveBeenCalledWith ( jsTestContent , path . normalize ( '/path/to/test.ts' ) )
152147 expect ( mockCucumberParser ) . not . toHaveBeenCalled ( )
153148 } )
154149
@@ -174,7 +169,7 @@ describe('Parser Index', () => {
174169 cucumberFeatureContent ,
175170 path . normalize ( '/path/to/test.feature' )
176171 )
177- expect ( parseTestCases ) . not . toHaveBeenCalled ( )
172+ expect ( mockAstParser ) . not . toHaveBeenCalled ( )
178173 } )
179174
180175 it ( 'should handle uppercase feature file extensions' , async ( ) => {
@@ -199,7 +194,7 @@ describe('Parser Index', () => {
199194 cucumberFeatureContent ,
200195 path . normalize ( '/path/to/test.FEATURE' )
201196 )
202- expect ( parseTestCases ) . not . toHaveBeenCalled ( )
197+ expect ( mockAstParser ) . not . toHaveBeenCalled ( )
203198 } )
204199
205200 it ( 'should parse multiple spec files' , async ( ) => {
@@ -232,7 +227,7 @@ describe('Parser Index', () => {
232227 expect ( result [ 1 ] . tests ) . toEqual ( cucumberMockTestData )
233228
234229 // Verify the correct parsers were called
235- expect ( parseTestCases ) . toHaveBeenCalledWith ( jsTestContent , path . normalize ( '/path/to/test.js' ) )
230+ expect ( mockAstParser ) . toHaveBeenCalledWith ( jsTestContent , path . normalize ( '/path/to/test.js' ) )
236231 expect ( mockCucumberParser ) . toHaveBeenCalledWith (
237232 cucumberFeatureContent ,
238233 path . normalize ( '/path/to/test.feature' )
@@ -269,7 +264,7 @@ describe('Parser Index', () => {
269264 expect ( result [ 0 ] . spec ) . toBe ( path . normalize ( 'C:\\path\\to\\test.js' ) )
270265
271266 // Verify the parser was called with the normalized path
272- expect ( parseTestCases ) . toHaveBeenCalledWith ( jsTestContent , path . normalize ( 'C:\\path\\to\\test.js' ) )
267+ expect ( mockAstParser ) . toHaveBeenCalledWith ( jsTestContent , path . normalize ( 'C:\\path\\to\\test.js' ) )
273268 } )
274269
275270 it ( 'should handle empty specs array' , async ( ) => {
@@ -284,7 +279,7 @@ describe('Parser Index', () => {
284279 // Verify
285280 expect ( result ) . toEqual ( [ ] )
286281 expect ( fs . readFile ) . not . toHaveBeenCalled ( )
287- expect ( parseTestCases ) . not . toHaveBeenCalled ( )
282+ expect ( mockAstParser ) . not . toHaveBeenCalled ( )
288283 expect ( mockCucumberParser ) . not . toHaveBeenCalled ( )
289284 } )
290285 } )
0 commit comments