1
+ import { beforeAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
2
+
1
3
import * as fs from 'node:fs/promises' ;
2
4
import * as path from 'node:path' ;
3
5
@@ -13,40 +15,43 @@ import {
13
15
mockHttpGet
14
16
} from './utils' ;
15
17
16
- jest . mock ( '@actions/cache' ) ;
17
- jest . mock ( '@actions/core' ) ;
18
- jest . mock ( 'node:fs/promises' ) ;
18
+ vi . mock ( '@actions/cache' ) ;
19
+ vi . mock ( '@actions/core' ) ;
20
+ vi . mock ( 'node:fs/promises' ) ;
19
21
20
22
// Spy the action's entrypoint
21
- const runSpy = jest . spyOn ( main , 'run' ) ;
23
+ const runSpy = vi . spyOn ( main , 'run' ) ;
24
+
25
+ let schemaContents : string ;
26
+ let invalidSchemaContents : string ;
27
+ let instanceContents : string ;
22
28
23
29
describe ( 'action' , ( ) => {
24
30
const schema = '/foo/bar' ;
25
31
const remoteSchema = 'https://foo.bar/schema.json' ;
26
32
const files = [ '/foo/bar/baz/**.yml' ] ;
27
33
28
- const schemaContents : string = jest
29
- . requireActual ( 'node:fs' )
30
- . readFileSync (
34
+ beforeAll ( async ( ) => {
35
+ // jest.mocked(core.debug).mockImplementation(console.debug);
36
+
37
+ const actualFs = await vi . importActual < typeof import ( 'node:fs' ) > ( 'node:fs' ) ;
38
+
39
+ schemaContents = actualFs . readFileSync (
31
40
path . join ( __dirname , 'fixtures' , 'evm-config.schema.json' ) ,
32
41
'utf-8'
33
42
) ;
34
- const invalidSchemaContents : string = jest
35
- . requireActual ( 'node:fs' )
36
- . readFileSync (
43
+ invalidSchemaContents = actualFs . readFileSync (
37
44
path . join ( __dirname , 'fixtures' , 'invalid.schema.json' ) ,
38
45
'utf-8'
39
46
) ;
40
- const instanceContents : string = jest
41
- . requireActual ( 'node:fs' )
42
- . readFileSync ( path . join ( __dirname , 'fixtures' , 'evm-config.yml' ) , 'utf-8' ) ;
43
-
44
- beforeAll ( ( ) => {
45
- // jest.mocked(core.debug).mockImplementation(console.debug);
47
+ instanceContents = actualFs . readFileSync (
48
+ path . join ( __dirname , 'fixtures' , 'evm-config.yml' ) ,
49
+ 'utf-8'
50
+ ) ;
46
51
} ) ;
47
52
48
53
beforeEach ( ( ) => {
49
- jest . clearAllMocks ( ) ;
54
+ vi . clearAllMocks ( ) ;
50
55
process . exitCode = undefined ;
51
56
} ) ;
52
57
@@ -85,7 +90,7 @@ describe('action', () => {
85
90
mockGetInput ( { schema } ) ;
86
91
mockGetMultilineInput ( { files } ) ;
87
92
88
- jest . mocked ( fs . readFile ) . mockImplementation ( ( ) => {
93
+ vi . mocked ( fs . readFile ) . mockImplementation ( ( ) => {
89
94
throw new Error ( 'File read error' ) ;
90
95
} ) ;
91
96
@@ -102,7 +107,7 @@ describe('action', () => {
102
107
mockGetInput ( { schema } ) ;
103
108
mockGetMultilineInput ( { files } ) ;
104
109
105
- jest . mocked ( fs . readFile ) . mockImplementation ( ( ) => {
110
+ vi . mocked ( fs . readFile ) . mockImplementation ( ( ) => {
106
111
throw 42 ; // eslint-disable-line no-throw-literal
107
112
} ) ;
108
113
@@ -119,7 +124,7 @@ describe('action', () => {
119
124
mockGetInput ( { schema } ) ;
120
125
mockGetMultilineInput ( { files } ) ;
121
126
122
- jest . mocked ( fs . readFile ) . mockResolvedValueOnce ( schemaContents ) ;
127
+ vi . mocked ( fs . readFile ) . mockResolvedValueOnce ( schemaContents ) ;
123
128
124
129
await main . run ( ) ;
125
130
expect ( runSpy ) . toHaveReturned ( ) ;
@@ -133,7 +138,7 @@ describe('action', () => {
133
138
mockGetInput ( { schema } ) ;
134
139
mockGetMultilineInput ( { files } ) ;
135
140
136
- jest . mocked ( fs . readFile ) . mockResolvedValueOnce ( schemaContents ) ;
141
+ vi . mocked ( fs . readFile ) . mockResolvedValueOnce ( schemaContents ) ;
137
142
138
143
await main . run ( ) ;
139
144
expect ( runSpy ) . toHaveReturned ( ) ;
@@ -148,7 +153,7 @@ describe('action', () => {
148
153
mockGetInput ( { schema : remoteSchema } ) ;
149
154
mockGetMultilineInput ( { files } ) ;
150
155
151
- jest . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( undefined ) ;
156
+ vi . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( undefined ) ;
152
157
const httpGetSpy = mockHttpGet ( schemaContents ) ;
153
158
154
159
await main . run ( ) ;
@@ -181,7 +186,7 @@ describe('action', () => {
181
186
mockGetInput ( { schema : remoteSchema } ) ;
182
187
mockGetMultilineInput ( { files } ) ;
183
188
184
- jest . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( undefined ) ;
189
+ vi . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( undefined ) ;
185
190
const httpGetSpy = mockHttpGet ( schemaContents ) ;
186
191
187
192
await main . run ( ) ;
@@ -192,7 +197,7 @@ describe('action', () => {
192
197
193
198
// Confirm cache calls use the same paths and key
194
199
expect ( cache . restoreCache ) . toHaveBeenCalledTimes ( 1 ) ;
195
- const [ paths , key ] = jest . mocked ( cache . restoreCache ) . mock . calls [ 0 ] ;
200
+ const [ paths , key ] = vi . mocked ( cache . restoreCache ) . mock . calls [ 0 ] ;
196
201
expect ( cache . saveCache ) . toHaveBeenCalledTimes ( 1 ) ;
197
202
expect ( cache . saveCache ) . toHaveBeenLastCalledWith ( paths , key ) ;
198
203
} ) ;
@@ -202,7 +207,7 @@ describe('action', () => {
202
207
mockGetInput ( { schema : remoteSchema } ) ;
203
208
mockGetMultilineInput ( { files } ) ;
204
209
205
- jest . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( 'cache-key' ) ;
210
+ vi . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( 'cache-key' ) ;
206
211
const httpGetSpy = mockHttpGet ( schemaContents ) ;
207
212
208
213
await main . run ( ) ;
@@ -217,7 +222,7 @@ describe('action', () => {
217
222
mockGetInput ( { schema : remoteSchema } ) ;
218
223
mockGetMultilineInput ( { files } ) ;
219
224
220
- jest . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( 'cache-key' ) ;
225
+ vi . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( 'cache-key' ) ;
221
226
mockHttpGet ( schemaContents ) ;
222
227
223
228
await main . run ( ) ;
@@ -250,7 +255,7 @@ describe('action', () => {
250
255
mockGetInput ( { schema : remoteSchema } ) ;
251
256
mockGetMultilineInput ( { files } ) ;
252
257
253
- jest . spyOn ( cache , 'restoreCache' ) . mockImplementation ( async ( ) => {
258
+ vi . spyOn ( cache , 'restoreCache' ) . mockImplementation ( async ( ) => {
254
259
throw error ;
255
260
} ) ;
256
261
@@ -272,8 +277,8 @@ describe('action', () => {
272
277
mockGetInput ( { schema : remoteSchema } ) ;
273
278
mockGetMultilineInput ( { files } ) ;
274
279
275
- jest . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( undefined ) ;
276
- jest . spyOn ( cache , 'saveCache' ) . mockImplementation ( async ( ) => {
280
+ vi . spyOn ( cache , 'restoreCache' ) . mockResolvedValue ( undefined ) ;
281
+ vi . spyOn ( cache , 'saveCache' ) . mockImplementation ( async ( ) => {
277
282
throw error ;
278
283
} ) ;
279
284
@@ -294,9 +299,9 @@ describe('action', () => {
294
299
mockGetInput ( { schema } ) ;
295
300
mockGetMultilineInput ( { files } ) ;
296
301
297
- jest
298
- . mocked ( fs . readFile )
299
- . mockResolvedValueOnce ( schemaContents . replace ( '$schema' , '_schema' ) ) ;
302
+ vi . mocked ( fs . readFile ) . mockResolvedValueOnce (
303
+ schemaContents . replace ( '$schema' , '_schema' )
304
+ ) ;
300
305
301
306
await main . run ( ) ;
302
307
expect ( runSpy ) . toHaveReturned ( ) ;
@@ -312,7 +317,7 @@ describe('action', () => {
312
317
mockGetInput ( { schema } ) ;
313
318
mockGetMultilineInput ( { files } ) ;
314
319
315
- jest . mocked ( fs . readFile ) . mockResolvedValueOnce ( schemaContents ) ;
320
+ vi . mocked ( fs . readFile ) . mockResolvedValueOnce ( schemaContents ) ;
316
321
317
322
await main . run ( ) ;
318
323
expect ( runSpy ) . toHaveReturned ( ) ;
@@ -326,8 +331,7 @@ describe('action', () => {
326
331
mockGetInput ( { schema } ) ;
327
332
mockGetMultilineInput ( { files } ) ;
328
333
329
- jest
330
- . mocked ( fs . readFile )
334
+ vi . mocked ( fs . readFile )
331
335
. mockResolvedValueOnce ( schemaContents )
332
336
. mockResolvedValueOnce ( instanceContents ) ;
333
337
mockGlobGenerator ( [ '/foo/bar/baz/config.yml' ] ) ;
@@ -345,8 +349,7 @@ describe('action', () => {
345
349
mockGetInput ( { schema } ) ;
346
350
mockGetMultilineInput ( { files } ) ;
347
351
348
- jest
349
- . mocked ( fs . readFile )
352
+ vi . mocked ( fs . readFile )
350
353
. mockResolvedValueOnce ( schemaContents )
351
354
. mockResolvedValueOnce ( 'invalid content' )
352
355
. mockResolvedValueOnce ( instanceContents ) ;
@@ -365,8 +368,7 @@ describe('action', () => {
365
368
mockGetInput ( { schema } ) ;
366
369
mockGetMultilineInput ( { files } ) ;
367
370
368
- jest
369
- . mocked ( fs . readFile )
371
+ vi . mocked ( fs . readFile )
370
372
. mockResolvedValueOnce ( schemaContents )
371
373
. mockResolvedValueOnce ( 'invalid content' )
372
374
. mockResolvedValueOnce ( instanceContents ) ;
@@ -387,8 +389,7 @@ describe('action', () => {
387
389
388
390
const paths = [ '/foo/bar/baz/config.yml' , '/foo/bar/baz/e/config.yml' ] ;
389
391
390
- jest
391
- . mocked ( fs . readFile )
392
+ vi . mocked ( fs . readFile )
392
393
. mockResolvedValueOnce ( schemaContents )
393
394
. mockResolvedValueOnce ( 'invalid content' )
394
395
. mockResolvedValueOnce ( instanceContents ) ;
@@ -407,8 +408,7 @@ describe('action', () => {
407
408
mockGetInput ( { schema } ) ;
408
409
mockGetMultilineInput ( { files } ) ;
409
410
410
- jest
411
- . mocked ( fs . readFile )
411
+ vi . mocked ( fs . readFile )
412
412
. mockResolvedValueOnce (
413
413
schemaContents . replace (
414
414
'http://json-schema.org/draft-07/schema#' ,
@@ -436,7 +436,7 @@ describe('action', () => {
436
436
} ) ;
437
437
438
438
it ( 'which are valid' , async ( ) => {
439
- jest . mocked ( fs . readFile ) . mockResolvedValueOnce ( schemaContents ) ;
439
+ vi . mocked ( fs . readFile ) . mockResolvedValueOnce ( schemaContents ) ;
440
440
441
441
await main . run ( ) ;
442
442
expect ( runSpy ) . toHaveReturned ( ) ;
@@ -449,7 +449,7 @@ describe('action', () => {
449
449
it ( 'which are invalid' , async ( ) => {
450
450
mockGetBooleanInput ( { 'fail-on-invalid' : false } ) ;
451
451
452
- jest . mocked ( fs . readFile ) . mockResolvedValueOnce ( invalidSchemaContents ) ;
452
+ vi . mocked ( fs . readFile ) . mockResolvedValueOnce ( invalidSchemaContents ) ;
453
453
454
454
await main . run ( ) ;
455
455
expect ( runSpy ) . toHaveReturned ( ) ;
@@ -460,14 +460,12 @@ describe('action', () => {
460
460
} ) ;
461
461
462
462
it ( 'using JSON Schema draft-04' , async ( ) => {
463
- jest
464
- . mocked ( fs . readFile )
465
- . mockResolvedValueOnce (
466
- schemaContents . replace (
467
- 'http://json-schema.org/draft-07/schema#' ,
468
- 'http://json-schema.org/draft-04/schema#'
469
- )
470
- ) ;
463
+ vi . mocked ( fs . readFile ) . mockResolvedValueOnce (
464
+ schemaContents . replace (
465
+ 'http://json-schema.org/draft-07/schema#' ,
466
+ 'http://json-schema.org/draft-04/schema#'
467
+ )
468
+ ) ;
471
469
472
470
await main . run ( ) ;
473
471
expect ( runSpy ) . toHaveReturned ( ) ;
@@ -478,9 +476,9 @@ describe('action', () => {
478
476
} ) ;
479
477
480
478
it ( 'but fails if $schema key is missing' , async ( ) => {
481
- jest
482
- . mocked ( fs . readFile )
483
- . mockResolvedValueOnce ( schemaContents . replace ( '$schema' , '_schema' ) ) ;
479
+ vi . mocked ( fs . readFile ) . mockResolvedValueOnce (
480
+ schemaContents . replace ( '$schema' , '_schema' )
481
+ ) ;
484
482
485
483
await main . run ( ) ;
486
484
expect ( runSpy ) . toHaveReturned ( ) ;
0 commit comments