88
99import * as core from '@actions/core'
1010import * as main from '../src/main'
11+ import { describe , it , beforeEach , expect , vi } from 'vitest'
1112
1213// Mock the action's main function
13- const runMock = jest . spyOn ( main , 'run' )
14+ const runMock = vi . spyOn ( main , 'run' )
1415
1516// Other utilities
1617const timeRegex = / ^ \d { 2 } : \d { 2 } : \d { 2 } /
1718
1819// Mock the GitHub Actions core library
19- let debugMock : jest . SpiedFunction < typeof core . debug >
20- let errorMock : jest . SpiedFunction < typeof core . error >
21- let getInputMock : jest . SpiedFunction < typeof core . getInput >
22- let setFailedMock : jest . SpiedFunction < typeof core . setFailed >
23- let setOutputMock : jest . SpiedFunction < typeof core . setOutput >
20+ let debugMock : ReturnType < typeof vi . spyOn >
21+ let errorMock : ReturnType < typeof vi . spyOn >
22+ let getInputMock : ReturnType < typeof vi . spyOn >
23+ let setFailedMock : ReturnType < typeof vi . spyOn >
24+ let setOutputMock : ReturnType < typeof vi . spyOn >
2425
2526describe ( 'action' , ( ) => {
2627 beforeEach ( ( ) => {
27- jest . clearAllMocks ( )
28+ vi . clearAllMocks ( )
2829
29- debugMock = jest . spyOn ( core , 'debug' ) . mockImplementation ( )
30- errorMock = jest . spyOn ( core , 'error' ) . mockImplementation ( )
31- getInputMock = jest . spyOn ( core , 'getInput' ) . mockImplementation ( )
32- setFailedMock = jest . spyOn ( core , 'setFailed' ) . mockImplementation ( )
33- setOutputMock = jest . spyOn ( core , 'setOutput' ) . mockImplementation ( )
30+ debugMock = vi . spyOn ( core , 'debug' ) . mockImplementation ( )
31+ errorMock = vi . spyOn ( core , 'error' ) . mockImplementation ( )
32+ getInputMock = vi . spyOn ( core , 'getInput' ) . mockImplementation ( )
33+ setFailedMock = vi . spyOn ( core , 'setFailed' ) . mockImplementation ( )
34+ setOutputMock = vi . spyOn ( core , 'setOutput' ) . mockImplementation ( )
3435 } )
3536
36- it ( 'sets the time output' , async ( ) => {
37- // Set the action's inputs as return values from core.getInput()
38- getInputMock . mockImplementation ( name => {
39- switch ( name ) {
40- case 'milliseconds' :
41- return '500'
42- default :
43- return ''
44- }
45- } )
46-
47- await main . run ( )
48- expect ( runMock ) . toHaveReturned ( )
49-
50- // Verify that all of the core library functions were called correctly
51- expect ( debugMock ) . toHaveBeenNthCalledWith ( 1 , 'Waiting 500 milliseconds ...' )
52- expect ( debugMock ) . toHaveBeenNthCalledWith (
53- 2 ,
54- expect . stringMatching ( timeRegex )
55- )
56- expect ( debugMock ) . toHaveBeenNthCalledWith (
57- 3 ,
58- expect . stringMatching ( timeRegex )
59- )
60- expect ( setOutputMock ) . toHaveBeenNthCalledWith (
61- 1 ,
62- 'time' ,
63- expect . stringMatching ( timeRegex )
64- )
65- expect ( errorMock ) . not . toHaveBeenCalled ( )
66- } )
6737
68- it ( 'sets a failed status' , async ( ) => {
38+ it ( 'sets a failed status for unsupported platform ' , async ( ) => {
6939 // Set the action's inputs as return values from core.getInput()
7040 getInputMock . mockImplementation ( name => {
7141 switch ( name ) {
72- case 'milliseconds' :
73- return 'this is not a number'
42+ case 'action' :
43+ return 'test-action'
44+ case 'project' :
45+ return 'test-project'
46+ case 'pipelab-version' :
47+ return '1.0.0'
7448 default :
7549 return ''
7650 }
@@ -79,11 +53,8 @@ describe('action', () => {
7953 await main . run ( )
8054 expect ( runMock ) . toHaveReturned ( )
8155
82- // Verify that all of the core library functions were called correctly
83- expect ( setFailedMock ) . toHaveBeenNthCalledWith (
84- 1 ,
85- 'milliseconds not a number'
86- )
56+ // Verify that the core.setFailed function was called correctly
57+ expect ( setFailedMock ) . toHaveBeenCalledWith ( 'You are using an unsupported platform' )
8758 expect ( errorMock ) . not . toHaveBeenCalled ( )
8859 } )
8960} )
0 commit comments