1+ import { Mock } from 'vitest' ;
12import { makeDocumentFromString , lint , bundle } from '@redocly/openapi-core' ;
23import * as fs from 'node:fs' ;
34
@@ -7,29 +8,34 @@ import { runTestFile, runStep } from '../../../flow-runner';
78import { readYaml } from '../../../../utils/yaml' ;
89import { writeFileSync } from 'node:fs' ;
910
10- jest . mock ( '../../../../utils/yaml' , ( ) => {
11- const originalModule = jest . requireActual ( '../../../../utils/yaml' ) ;
11+ vi . mock ( '../../../../utils/yaml' , ( ) => {
12+ const originalModule = vi . importActual ( '../../../../utils/yaml' ) ;
13+
1214 return {
1315 ...originalModule , // In case there are other exports you want to preserve
14- readYaml : jest . fn ( ) ,
16+ readYaml : vi . fn ( ) ,
1517 } ;
1618} ) ;
1719
18- jest . mock ( '@redocly/openapi-core' , ( ) => ( {
19- ...jest . requireActual ( '@redocly/openapi-core' ) , // Preserve other exports
20- formatProblems : jest . fn ( ) , // Mock formatProblems to do nothing
21- lint : jest . fn ( ) ,
22- bundle : jest . fn ( ) ,
23- } ) ) ;
20+ vi . mock ( import ( '@redocly/openapi-core' ) , async ( importOriginal ) => {
21+ const originalModule = await importOriginal ( ) ;
22+
23+ return {
24+ ...originalModule , // Preserve other exports
25+ formatProblems : vi . fn ( ) , // Mock formatProblems to do nothing
26+ lint : vi . fn ( ) ,
27+ bundle : vi . fn ( ) ,
28+ } ;
29+ } ) ;
2430
25- jest . mock ( '../../../flow-runner/run-step' , ( ) => ( {
26- runStep : jest . fn ( ) ,
31+ vi . mock ( '../../../flow-runner/run-step' , ( ) => ( {
32+ runStep : vi . fn ( ) ,
2733} ) ) ;
2834
29- jest . mock ( 'node:fs' , ( ) => {
30- const actual = jest . requireActual ( 'node:fs' ) ;
31- const mockExistsSync = jest . fn ( ) ;
32- const mockWriteFileSync = jest . fn ( ) ;
35+ vi . mock ( 'node:fs' , ( ) => {
36+ const actual = vi . importActual ( 'node:fs' ) ;
37+ const mockExistsSync = vi . fn ( ) ;
38+ const mockWriteFileSync = vi . fn ( ) ;
3339
3440 return {
3541 __esModule : true ,
@@ -41,7 +47,7 @@ jest.mock('node:fs', () => {
4147 } ;
4248} ) ;
4349
44- const mockExistsSync = fs . existsSync as jest . Mock ;
50+ const mockExistsSync = fs . existsSync as Mock ;
4551
4652describe ( 'runTestFile' , ( ) => {
4753 beforeEach ( ( ) => {
@@ -61,17 +67,17 @@ describe('runTestFile', () => {
6167 }
6268 return false ;
6369 } ) ;
64- ( readYaml as jest . Mock ) . mockReset ( ) . mockResolvedValue ( {
70+ ( readYaml as Mock ) . mockReset ( ) . mockResolvedValue ( {
6571 openapi : '1.0.0' ,
6672 info : { title : 'Cat Facts API' , version : '1.0' } ,
6773 } ) ;
68- ( lint as jest . Mock ) . mockReset ( ) . mockResolvedValue ( [ ] ) ;
69- ( bundle as jest . Mock ) . mockReset ( ) ;
70- ( runStep as jest . Mock ) . mockReset ( ) ;
74+ ( lint as Mock ) . mockReset ( ) . mockResolvedValue ( [ ] ) ;
75+ ( bundle as Mock ) . mockReset ( ) ;
76+ ( runStep as Mock ) . mockReset ( ) ;
7177 } ) ;
7278
7379 afterAll ( ( ) => {
74- jest . resetAllMocks ( ) ;
80+ vi . resetAllMocks ( ) ;
7581 } ) ;
7682
7783 it ( `should trow error if filename is not correct` , async ( ) => {
@@ -87,7 +93,7 @@ describe('runTestFile', () => {
8793 'test.yml'
8894 ) ;
8995
90- ( readYaml as jest . Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
96+ ( readYaml as Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
9197
9298 await expect ( runTestFile ( { file : 'test.yaml' } , { } ) ) . rejects . toThrowError (
9399 'No test files found. File test.yaml does not follows naming pattern "*.[yaml | yml | json]" or have not valid "Arazzo" description.'
@@ -113,7 +119,7 @@ describe('runTestFile', () => {
113119 'test.yml'
114120 ) ;
115121
116- ( lint as jest . Mock ) . mockResolvedValueOnce ( [
122+ ( lint as Mock ) . mockResolvedValueOnce ( [
117123 {
118124 ruleId : 'spec' ,
119125 severity : 'error' ,
@@ -132,7 +138,7 @@ describe('runTestFile', () => {
132138 } ,
133139 ] ) ;
134140
135- ( readYaml as jest . Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
141+ ( readYaml as Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
136142
137143 await expect (
138144 runTestFile (
@@ -198,9 +204,9 @@ describe('runTestFile', () => {
198204 'api-test-framework/test.yml'
199205 ) ;
200206
201- ( readYaml as jest . Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
202- ( lint as jest . Mock ) . mockResolvedValueOnce ( [ ] ) ;
203- ( bundle as jest . Mock ) . mockResolvedValueOnce ( {
207+ ( readYaml as Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
208+ ( lint as Mock ) . mockResolvedValueOnce ( [ ] ) ;
209+ ( bundle as Mock ) . mockResolvedValueOnce ( {
204210 bundle : {
205211 parsed : mockDocument . parsed ,
206212 } ,
@@ -291,9 +297,9 @@ describe('runTestFile', () => {
291297 'test.yml'
292298 ) ;
293299
294- ( readYaml as jest . Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
295- ( lint as jest . Mock ) . mockResolvedValueOnce ( [ ] ) ;
296- ( bundle as jest . Mock ) . mockResolvedValueOnce ( {
300+ ( readYaml as Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
301+ ( lint as Mock ) . mockResolvedValueOnce ( [ ] ) ;
302+ ( bundle as Mock ) . mockResolvedValueOnce ( {
297303 bundle : {
298304 parsed : mockDocument . parsed ,
299305 } ,
@@ -385,9 +391,9 @@ describe('runTestFile', () => {
385391 'api-test-framework/test.yml'
386392 ) ;
387393
388- ( readYaml as jest . Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
389- ( lint as jest . Mock ) . mockResolvedValueOnce ( [ ] ) ;
390- ( bundle as jest . Mock ) . mockResolvedValueOnce ( {
394+ ( readYaml as Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
395+ ( lint as Mock ) . mockResolvedValueOnce ( [ ] ) ;
396+ ( bundle as Mock ) . mockResolvedValueOnce ( {
391397 bundle : {
392398 parsed : mockDocument . parsed ,
393399 } ,
@@ -476,15 +482,15 @@ describe('runTestFile', () => {
476482 'api-test-framework/test.yml'
477483 ) ;
478484
479- ( readYaml as jest . Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
480- ( lint as jest . Mock ) . mockResolvedValueOnce ( [ ] ) ;
481- ( bundle as jest . Mock ) . mockResolvedValueOnce ( {
485+ ( readYaml as Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
486+ ( lint as Mock ) . mockResolvedValueOnce ( [ ] ) ;
487+ ( bundle as Mock ) . mockResolvedValueOnce ( {
482488 bundle : {
483489 parsed : mockDocument . parsed ,
484490 } ,
485491 } ) ;
486492
487- ( runStep as jest . Mock ) . mockImplementation ( ( { step, ctx } : { step : Step ; ctx : TestContext } ) => {
493+ ( runStep as Mock ) . mockImplementation ( ( { step, ctx } : { step : Step ; ctx : TestContext } ) => {
488494 step . checks = [ { name : step . stepId , passed : false , severity : 'error' } ] ;
489495 ctx . executedSteps . push ( step ) ;
490496 } ) ;
@@ -537,9 +543,9 @@ describe('runTestFile', () => {
537543 'api-test-framework/test.yml'
538544 ) ;
539545
540- ( readYaml as jest . Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
541- ( lint as jest . Mock ) . mockResolvedValueOnce ( [ ] ) ;
542- ( bundle as jest . Mock ) . mockResolvedValueOnce ( {
546+ ( readYaml as Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
547+ ( lint as Mock ) . mockResolvedValueOnce ( [ ] ) ;
548+ ( bundle as Mock ) . mockResolvedValueOnce ( {
543549 bundle : {
544550 parsed : mockDocument . parsed ,
545551 } ,
@@ -592,9 +598,9 @@ describe('runTestFile', () => {
592598 'api-test-framework/test.yml'
593599 ) ;
594600
595- ( readYaml as jest . Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
596- ( lint as jest . Mock ) . mockResolvedValueOnce ( [ ] ) ;
597- ( bundle as jest . Mock ) . mockResolvedValueOnce ( {
601+ ( readYaml as Mock ) . mockResolvedValue ( mockDocument . parsed ) ;
602+ ( lint as Mock ) . mockResolvedValueOnce ( [ ] ) ;
603+ ( bundle as Mock ) . mockResolvedValueOnce ( {
598604 bundle : {
599605 parsed : mockDocument . parsed ,
600606 } ,
0 commit comments