File tree Expand file tree Collapse file tree 1 file changed +30
-21
lines changed
src/__tests__/__helpers__ Expand file tree Collapse file tree 1 file changed +30
-21
lines changed Original file line number Diff line number Diff line change @@ -116,35 +116,44 @@ export async function run(spec: string) {
116116 const id = Date . now ( ) . toString ( ) ;
117117 const fs = virtualFS ( ) ;
118118
119- when ( jest . spyOn ( nodeFS , 'readFile' ) ) . mockImplementation ( ( _ , callback ) => {
120- callback ( null , Buffer . from ( spec , 'utf-8' ) ) ;
121- } ) ;
119+ const tempFilePath = `/tmp/openapi-test- ${ id } .yaml` ;
120+
121+ nodeFS . writeFileSync ( tempFilePath , spec ) ;
122122
123123 when ( jest . spyOn ( nodeFS . promises , 'writeFile' ) ) . mockImplementation ( async ( file , content ) => {
124124 fs . writeFile ( file . toString ( ) , content ) ;
125125 } ) ;
126126
127127 when ( jest . spyOn ( nodeFS . promises , 'mkdir' ) ) . mockImplementation ( async ( ) => undefined ) ;
128128
129- await includerFunction ( {
130- index : 0 ,
131- readBasePath : '' ,
132- writeBasePath : '' ,
133- vars : { } ,
134- passedParams : {
135- input : id ,
136- } ,
137- tocPath : 'toc' ,
138- item : {
139- name : id ,
140- href : '' ,
141- include : {
142- path : 'openapi' ,
143- repo : '__tests__' ,
129+ try {
130+ await includerFunction ( {
131+ index : 0 ,
132+ readBasePath : '' ,
133+ writeBasePath : '' ,
134+ vars : { } ,
135+ passedParams : {
136+ input : tempFilePath ,
144137 } ,
145- items : [ ] ,
146- } ,
147- } ) ;
138+ tocPath : 'toc' ,
139+ item : {
140+ name : id ,
141+ href : '' ,
142+ include : {
143+ path : 'openapi' ,
144+ repo : '__tests__' ,
145+ } ,
146+ items : [ ] ,
147+ } ,
148+ } ) ;
149+
150+ nodeFS . unlinkSync ( tempFilePath ) ;
151+ } catch ( error ) {
152+ try {
153+ nodeFS . unlinkSync ( tempFilePath ) ;
154+ } catch ( e ) { }
155+ throw error ;
156+ }
148157
149158 jest . clearAllMocks ( ) ;
150159
You can’t perform that action at this time.
0 commit comments