99import * as fs from 'fs'
1010import * as os from 'os'
1111import * as path from 'path'
12- import * as core from '@actions/core'
13- import * as main from '../src/main'
14- import { getMSYS } from '../src/get-msys'
12+ import { expect , jest , describe , beforeEach , afterAll , it } from '@jest/globals'
1513
1614// Some expected string
1715const mdCoverageTable = `| Total | Frontend | Backend | SimCode | Templates | Compilation | Simulation | Verification |
1816| --- | --- | --- | --- | --- | --- | --- | --- |
1917| 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 |`
2018
21- // Mock the action's main function
22- const runMock = jest . spyOn ( main , 'run' )
2319const modelicaFile = path . resolve (
2420 path . join ( 'examples' , 'MyLibrary' , 'package.mo' )
2521)
2622const referenceFilesDir = path . resolve ( path . join ( 'examples' , 'ReferenceFiles' ) )
2723
2824// Mock the GitHub Actions core library
29- let debugMock : jest . SpyInstance
30- let errorMock : jest . SpyInstance
31- let infoMock : jest . SpyInstance
32- let getInputMock : jest . SpyInstance
33- let setFailedMock : jest . SpyInstance
34- let setOutputMock : jest . SpyInstance
25+ const debugMock = jest
26+ . fn < ( message : string ) => void > ( )
27+ . mockImplementation ( msg => console . log ( `::debug::${ msg } ` ) )
28+ const infoMock = jest
29+ . fn < ( message : string ) => void > ( )
30+ . mockImplementation ( msg => console . log ( `::info::${ msg } ` ) )
31+ const errorMock = jest
32+ . fn < ( message : string | Error ) => void > ( )
33+ . mockImplementation ( msg => console . log ( `::error::${ msg } ` ) )
34+ const getInputMock =
35+ jest . fn < ( name : string , options ?: { required ?: boolean } ) => string > ( )
36+ const setFailedMock = jest . fn < ( message : string | Error ) => void > ( )
37+ const setOutputMock = jest . fn < ( name : string , value : unknown ) => void > ( )
38+
39+ jest . unstable_mockModule ( '@actions/core' , ( ) => ( {
40+ debug : debugMock ,
41+ info : infoMock ,
42+ warning : jest . fn ( ) ,
43+ error : errorMock ,
44+ getInput : getInputMock ,
45+ setFailed : setFailedMock ,
46+ setOutput : setOutputMock ,
47+ summary : {
48+ addRaw : jest . fn ( ) . mockReturnThis ( ) ,
49+ write : jest . fn < ( ) => Promise < void > > ( ) . mockResolvedValue ( undefined )
50+ }
51+ } ) )
3552
3653// Mock @actions /artifact and @actions /github
37- jest . mock ( '@actions/artifact' )
38- jest . mock ( '@actions/github' )
54+ const uploadArtifactMock = jest
55+ . fn < ( ) => Promise < { size : number ; id : number } > > ( )
56+ . mockResolvedValue ( { size : 0 , id : 0 } )
57+
58+ jest . unstable_mockModule ( '@actions/artifact' , ( ) => ( {
59+ DefaultArtifactClient : jest . fn ( ) . mockImplementation ( ( ) => ( {
60+ uploadArtifact : uploadArtifactMock
61+ } ) )
62+ } ) )
63+
64+ jest . unstable_mockModule ( '@actions/github' , ( ) => ( {
65+ context : {
66+ repo : { owner : 'test' , repo : 'test' } ,
67+ runId : 123
68+ }
69+ } ) )
70+
71+ // Dynamic imports after mocking
72+ const main = await import ( '../src/main' )
73+ const { getMSYS } = await import ( '../src/get-msys' )
3974
4075// Set GitHub summary file
4176const gitHubStepSummaryFile = path . resolve (
@@ -57,18 +92,9 @@ describe('action', () => {
5792
5893 jest . clearAllMocks ( )
5994
60- debugMock = jest
61- . spyOn ( core , 'debug' )
62- . mockImplementation ( msg => console . log ( `::debug::${ msg } ` ) )
63- infoMock = jest
64- . spyOn ( core , 'info' )
65- . mockImplementation ( msg => console . log ( `::info::${ msg } ` ) )
66- errorMock = jest
67- . spyOn ( core , 'error' )
68- . mockImplementation ( msg => console . log ( `::error::${ msg } ` ) )
69- getInputMock = jest . spyOn ( core , 'getInput' ) . mockImplementation ( )
70- setFailedMock = jest . spyOn ( core , 'setFailed' ) . mockImplementation ( )
71- setOutputMock = jest . spyOn ( core , 'setOutput' ) . mockImplementation ( )
95+ debugMock . mockImplementation ( msg => console . log ( `::debug::${ msg } ` ) )
96+ infoMock . mockImplementation ( msg => console . log ( `::info::${ msg } ` ) )
97+ errorMock . mockImplementation ( msg => console . log ( `::error::${ msg } ` ) )
7298 } )
7399
74100 it (
@@ -101,7 +127,6 @@ describe('action', () => {
101127 } )
102128
103129 await main . run ( )
104- expect ( runMock ) . toHaveReturned ( )
105130
106131 // Verify that all of the core library functions were called correctly
107132 expect ( debugMock ) . toHaveBeenNthCalledWith ( 1 , 'Get inputs' )
0 commit comments