@@ -3,6 +3,7 @@ import { pathToOpenapi } from '../../src/lib/path-to-openapi';
33import path from 'node:path' ;
44import { readFileSync } from 'node:fs' ;
55import type { OpenAPIV3 } from 'openapi-types' ;
6+ import axios from 'foca-axios' ;
67
78test ( '从本地获取json' , async ( ) => {
89 const result = await pathToOpenapi ( './openapi/openapi.json' ) ;
@@ -19,18 +20,13 @@ test('从本地获取yaml', async () => {
1920} ) ;
2021
2122test ( '从远程获取' , async ( ) => {
22- const originalFetch = globalThis . fetch ;
23- globalThis . fetch = vitest . fn ( ) . mockResolvedValueOnce ( {
24- ok : true ,
25- text : ( ) => {
26- return Promise . resolve (
27- JSON . stringify ( readFileSync ( path . resolve ( 'openapi' , 'openapi.json' ) , 'utf8' ) ) ,
28- ) ;
29- } ,
23+ const originalFetch = axios . request ;
24+ axios . request = vitest . fn ( ) . mockImplementation ( async ( ) => {
25+ return JSON . stringify ( readFileSync ( path . resolve ( 'openapi' , 'openapi.json' ) , 'utf8' ) ) ;
3026 } ) ;
3127 const result = await pathToOpenapi ( 'http://example.com' ) ;
3228 expect ( result ) . toMatchFileSnapshot ( path . resolve ( 'openapi' , 'openapi.json' ) ) ;
33- globalThis . fetch = originalFetch ;
29+ axios . request = originalFetch ;
3430} ) ;
3531
3632test ( '支持加载事件' , async ( ) => {
0 commit comments