1
- /**
2
- * Unit tests for the action's main functionality, src/main.ts
3
- */
4
- import { jest } from '@jest/globals'
1
+ import {
2
+ vi ,
3
+ describe ,
4
+ expect ,
5
+ it ,
6
+ beforeEach ,
7
+ type MockedFunction
8
+ } from 'vitest'
5
9
import * as core from '../__fixtures__/core.js'
6
10
7
11
// Default to throwing errors to catch unexpected calls
8
- const mockExistsSync = jest . fn ( ) . mockImplementation ( ( ) => {
12
+ const mockExistsSync = vi . fn ( ) . mockImplementation ( ( ) => {
9
13
throw new Error (
10
14
'Unexpected call to existsSync - test should override this implementation'
11
15
)
12
16
} )
13
- const mockReadFileSync = jest . fn ( ) . mockImplementation ( ( ) => {
17
+ const mockReadFileSync = vi . fn ( ) . mockImplementation ( ( ) => {
14
18
throw new Error (
15
19
'Unexpected call to readFileSync - test should override this implementation'
16
20
)
17
21
} )
18
- const mockWriteFileSync = jest . fn ( )
22
+ const mockWriteFileSync = vi . fn ( )
19
23
20
24
/**
21
25
* Helper function to mock file system operations for one or more files
@@ -83,30 +87,30 @@ function verifyStandardResponse(): void {
83
87
)
84
88
}
85
89
86
- jest . unstable_mockModule ( 'fs' , ( ) => ( {
90
+ vi . mock ( 'fs' , ( ) => ( {
87
91
existsSync : mockExistsSync ,
88
92
readFileSync : mockReadFileSync ,
89
93
writeFileSync : mockWriteFileSync
90
94
} ) )
91
95
92
96
// Mock MCP and inference modules
93
97
// eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- const mockConnectToGitHubMCP = jest . fn ( ) as jest . MockedFunction < any >
98
+ const mockConnectToGitHubMCP = vi . fn ( ) as MockedFunction < any >
95
99
// eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- const mockSimpleInference = jest . fn ( ) as jest . MockedFunction < any >
100
+ const mockSimpleInference = vi . fn ( ) as MockedFunction < any >
97
101
// eslint-disable-next-line @typescript-eslint/no-explicit-any
98
- const mockMcpInference = jest . fn ( ) as jest . MockedFunction < any >
102
+ const mockMcpInference = vi . fn ( ) as MockedFunction < any >
99
103
100
- jest . unstable_mockModule ( '../src/mcp.js' , ( ) => ( {
104
+ vi . mock ( '../src/mcp.js' , ( ) => ( {
101
105
connectToGitHubMCP : mockConnectToGitHubMCP
102
106
} ) )
103
107
104
- jest . unstable_mockModule ( '../src/inference.js' , ( ) => ( {
108
+ vi . mock ( '../src/inference.js' , ( ) => ( {
105
109
simpleInference : mockSimpleInference ,
106
110
mcpInference : mockMcpInference
107
111
} ) )
108
112
109
- jest . unstable_mockModule ( '@actions/core' , ( ) => core )
113
+ vi . mock ( '@actions/core' , ( ) => core )
110
114
111
115
// The module being tested should be imported dynamically. This ensures that the
112
116
// mocks are used in place of any actual dependencies.
@@ -115,7 +119,7 @@ const { run } = await import('../src/main.js')
115
119
describe ( 'main.ts' , ( ) => {
116
120
// Reset all mocks before each test
117
121
beforeEach ( ( ) => {
118
- jest . clearAllMocks ( )
122
+ vi . clearAllMocks ( )
119
123
120
124
// Remove any existing GITHUB_TOKEN
121
125
delete process . env . GITHUB_TOKEN
0 commit comments