Skip to content

Commit 4ba8e6b

Browse files
committed
feat: moves project to using vitest
1 parent 64cbe74 commit 4ba8e6b

15 files changed

+3798
-10265
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
- name: Test
4545
id: npm-ci-test
46-
run: npm run ci-test
46+
run: npm run test
4747
env:
4848
GITHUB_TOKEN: ${{ github.token }}
4949

__fixtures__/core.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type * as core from '@actions/core'
2-
import { jest } from '@jest/globals'
2+
import { vi } from 'vitest'
33

4-
export const debug = jest.fn<typeof core.debug>()
5-
export const error = jest.fn<typeof core.error>()
6-
export const info = jest.fn<typeof core.info>()
7-
export const getInput = jest.fn<typeof core.getInput>()
8-
export const getBooleanInput = jest.fn<typeof core.getBooleanInput>()
9-
export const setOutput = jest.fn<typeof core.setOutput>()
10-
export const setFailed = jest.fn<typeof core.setFailed>()
11-
export const warning = jest.fn<typeof core.warning>()
4+
export const debug = vi.fn<typeof core.debug>()
5+
export const error = vi.fn<typeof core.error>()
6+
export const info = vi.fn<typeof core.info>()
7+
export const getInput = vi.fn<typeof core.getInput>()
8+
export const getBooleanInput = vi.fn<typeof core.getBooleanInput>()
9+
export const setOutput = vi.fn<typeof core.setOutput>()
10+
export const setFailed = vi.fn<typeof core.setFailed>()
11+
export const warning = vi.fn<typeof core.warning>()

__fixtures__/wait.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { jest } from '@jest/globals'
1+
import { vi } from 'vitest'
22

3-
export const wait = jest.fn<typeof import('../src/wait.js').wait>()
3+
export const wait = vi.fn<typeof import('../src/wait.js').wait>()

__tests__/helpers-inference.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect } from '@jest/globals'
1+
import { describe, it, expect } from 'vitest'
22
import {
33
buildMessages,
44
buildResponseFormat,

__tests__/helpers.test.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
/**
2-
* Unit tests for the helpers module, src/helpers.ts
3-
*/
4-
import { jest } from '@jest/globals'
1+
import { vi, it, expect, beforeEach, describe } from 'vitest'
52
import * as core from '../__fixtures__/core.js'
63

7-
// Mock fs module
8-
const mockExistsSync = jest.fn()
9-
const mockReadFileSync = jest.fn()
4+
const mockExistsSync = vi.fn()
5+
const mockReadFileSync = vi.fn()
106

11-
jest.unstable_mockModule('fs', () => ({
7+
vi.mock('fs', () => ({
128
existsSync: mockExistsSync,
139
readFileSync: mockReadFileSync
1410
}))
1511

16-
jest.unstable_mockModule('@actions/core', () => core)
12+
vi.mock('@actions/core', () => core)
1713

18-
// Import the module being tested
1914
const { loadContentFromFileOrInput } = await import('../src/helpers.js')
2015

2116
describe('helpers.ts', () => {
2217
beforeEach(() => {
23-
jest.clearAllMocks()
18+
vi.clearAllMocks()
2419
})
2520

2621
describe('loadContentFromFileOrInput', () => {

__tests__/inference.test.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
/**
2-
* Unit tests for the inference module, src/inference.ts
3-
*/
4-
import { jest } from '@jest/globals'
1+
import {
2+
vi,
3+
type MockedFunction,
4+
beforeEach,
5+
expect,
6+
describe,
7+
it
8+
} from 'vitest'
59
import * as core from '../__fixtures__/core.js'
610

7-
// Mock Azure AI Inference
811
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9-
const mockPost = jest.fn() as jest.MockedFunction<any>
10-
const mockPath = jest.fn(() => ({ post: mockPost }))
11-
const mockClient = jest.fn(() => ({ path: mockPath }))
12+
const mockPost = vi.fn() as MockedFunction<any>
13+
const mockPath = vi.fn(() => ({ post: mockPost }))
14+
const mockClient = vi.fn(() => ({ path: mockPath }))
1215

13-
jest.unstable_mockModule('@azure-rest/ai-inference', () => ({
16+
vi.mock('@azure-rest/ai-inference', () => ({
1417
default: mockClient,
15-
isUnexpected: jest.fn(() => false)
18+
isUnexpected: vi.fn(() => false)
1619
}))
1720

18-
jest.unstable_mockModule('@azure/core-auth', () => ({
19-
AzureKeyCredential: jest.fn()
21+
vi.mock('@azure/core-auth', () => ({
22+
AzureKeyCredential: vi.fn()
2023
}))
2124

22-
// Mock MCP functions
2325
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24-
const mockExecuteToolCalls = jest.fn() as jest.MockedFunction<any>
25-
jest.unstable_mockModule('../src/mcp.js', () => ({
26+
const mockExecuteToolCalls = vi.fn() as MockedFunction<any>
27+
vi.mock('../src/mcp.js', () => ({
2628
executeToolCalls: mockExecuteToolCalls
2729
}))
2830

29-
jest.unstable_mockModule('@actions/core', () => core)
31+
vi.mock('@actions/core', () => core)
3032

3133
// Import the module being tested
3234
const { simpleInference, mcpInference } = await import('../src/inference.js')
@@ -44,7 +46,7 @@ describe('inference.ts', () => {
4446
}
4547

4648
beforeEach(() => {
47-
jest.clearAllMocks()
49+
vi.clearAllMocks()
4850
})
4951

5052
describe('simpleInference', () => {

__tests__/main-prompt-integration.test.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,54 @@
1-
import { describe, it, expect, beforeEach, jest } from '@jest/globals'
1+
import {
2+
describe,
3+
it,
4+
expect,
5+
beforeEach,
6+
vi,
7+
type MockedFunction,
8+
type Mock
9+
} from 'vitest'
210
import * as core from '../__fixtures__/core.js'
311

412
// Create fs mocks
5-
const mockExistsSync = jest.fn()
6-
const mockReadFileSync = jest.fn()
7-
const mockWriteFileSync = jest.fn()
13+
const mockExistsSync = vi.fn()
14+
const mockReadFileSync = vi.fn()
15+
const mockWriteFileSync = vi.fn()
816

917
// Create inference mocks
1018
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11-
const mockSimpleInference = jest.fn() as jest.MockedFunction<any>
12-
const mockMcpInference = jest.fn()
19+
const mockSimpleInference = vi.fn() as MockedFunction<any>
20+
const mockMcpInference = vi.fn()
1321

1422
// Create MCP mocks
15-
const mockConnectToGitHubMCP = jest.fn()
23+
const mockConnectToGitHubMCP = vi.fn()
1624

1725
// Mock fs module
18-
jest.unstable_mockModule('fs', () => ({
26+
vi.mock('fs', () => ({
1927
existsSync: mockExistsSync,
2028
readFileSync: mockReadFileSync,
2129
writeFileSync: mockWriteFileSync
2230
}))
2331

2432
// Mock the inference functions
25-
jest.unstable_mockModule('../src/inference.js', () => ({
33+
vi.mock('../src/inference.js', () => ({
2634
simpleInference: mockSimpleInference,
2735
mcpInference: mockMcpInference
2836
}))
2937

3038
// Mock the MCP connection
31-
jest.unstable_mockModule('../src/mcp.js', () => ({
39+
vi.mock('../src/mcp.js', () => ({
3240
connectToGitHubMCP: mockConnectToGitHubMCP
3341
}))
3442

35-
jest.unstable_mockModule('@actions/core', () => core)
43+
vi.mock('@actions/core', () => core)
3644

3745
// The module being tested should be imported dynamically. This ensures that the
3846
// mocks are used in place of any actual dependencies.
3947
const { run } = await import('../src/main.js')
4048

4149
describe('main.ts - prompt.yml integration', () => {
4250
beforeEach(() => {
43-
jest.clearAllMocks()
51+
vi.clearAllMocks()
4452

4553
// Mock environment variables
4654
process.env['GITHUB_TOKEN'] = 'test-token'
@@ -62,7 +70,7 @@ describe('main.ts - prompt.yml integration', () => {
6270
})
6371

6472
// Mock core.getBooleanInput
65-
const mockGetBooleanInput = core.getBooleanInput as jest.Mock
73+
const mockGetBooleanInput = core.getBooleanInput as Mock
6674
mockGetBooleanInput.mockReturnValue(false)
6775

6876
// Mock fs.readFileSync for prompt file

__tests__/main.test.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
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'
59
import * as core from '../__fixtures__/core.js'
610

711
// Default to throwing errors to catch unexpected calls
8-
const mockExistsSync = jest.fn().mockImplementation(() => {
12+
const mockExistsSync = vi.fn().mockImplementation(() => {
913
throw new Error(
1014
'Unexpected call to existsSync - test should override this implementation'
1115
)
1216
})
13-
const mockReadFileSync = jest.fn().mockImplementation(() => {
17+
const mockReadFileSync = vi.fn().mockImplementation(() => {
1418
throw new Error(
1519
'Unexpected call to readFileSync - test should override this implementation'
1620
)
1721
})
18-
const mockWriteFileSync = jest.fn()
22+
const mockWriteFileSync = vi.fn()
1923

2024
/**
2125
* Helper function to mock file system operations for one or more files
@@ -83,30 +87,30 @@ function verifyStandardResponse(): void {
8387
)
8488
}
8589

86-
jest.unstable_mockModule('fs', () => ({
90+
vi.mock('fs', () => ({
8791
existsSync: mockExistsSync,
8892
readFileSync: mockReadFileSync,
8993
writeFileSync: mockWriteFileSync
9094
}))
9195

9296
// Mock MCP and inference modules
9397
// 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>
9599
// 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>
97101
// 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>
99103

100-
jest.unstable_mockModule('../src/mcp.js', () => ({
104+
vi.mock('../src/mcp.js', () => ({
101105
connectToGitHubMCP: mockConnectToGitHubMCP
102106
}))
103107

104-
jest.unstable_mockModule('../src/inference.js', () => ({
108+
vi.mock('../src/inference.js', () => ({
105109
simpleInference: mockSimpleInference,
106110
mcpInference: mockMcpInference
107111
}))
108112

109-
jest.unstable_mockModule('@actions/core', () => core)
113+
vi.mock('@actions/core', () => core)
110114

111115
// The module being tested should be imported dynamically. This ensures that the
112116
// mocks are used in place of any actual dependencies.
@@ -115,7 +119,7 @@ const { run } = await import('../src/main.js')
115119
describe('main.ts', () => {
116120
// Reset all mocks before each test
117121
beforeEach(() => {
118-
jest.clearAllMocks()
122+
vi.clearAllMocks()
119123

120124
// Remove any existing GITHUB_TOKEN
121125
delete process.env.GITHUB_TOKEN

__tests__/mcp.test.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
/**
2-
* Unit tests for the MCP module, src/mcp.ts
3-
*/
4-
import { jest } from '@jest/globals'
1+
import {
2+
vi,
3+
type MockedFunction,
4+
describe,
5+
it,
6+
expect,
7+
beforeEach
8+
} from 'vitest'
59
import * as core from '../__fixtures__/core.js'
610

711
// Mock MCP SDK
812
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9-
const mockConnect = jest.fn() as jest.MockedFunction<any>
13+
const mockConnect = vi.fn() as MockedFunction<any>
1014
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11-
const mockListTools = jest.fn() as jest.MockedFunction<any>
15+
const mockListTools = vi.fn() as MockedFunction<any>
1216
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13-
const mockCallTool = jest.fn() as jest.MockedFunction<any>
17+
const mockCallTool = vi.fn() as MockedFunction<any>
1418

1519
const mockClient = {
1620
connect: mockConnect,
@@ -19,18 +23,15 @@ const mockClient = {
1923
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2024
} as any
2125

22-
jest.unstable_mockModule('@modelcontextprotocol/sdk/client/index.js', () => ({
23-
Client: jest.fn(() => mockClient)
26+
vi.mock('@modelcontextprotocol/sdk/client/index.js', () => ({
27+
Client: vi.fn(() => mockClient)
2428
}))
2529

26-
jest.unstable_mockModule(
27-
'@modelcontextprotocol/sdk/client/streamableHttp.js',
28-
() => ({
29-
StreamableHTTPClientTransport: jest.fn()
30-
})
31-
)
30+
vi.mock('@modelcontextprotocol/sdk/client/streamableHttp.js', () => ({
31+
StreamableHTTPClientTransport: vi.fn()
32+
}))
3233

33-
jest.unstable_mockModule('@actions/core', () => core)
34+
vi.mock('@actions/core', () => core)
3435

3536
// Import the module being tested
3637
const { connectToGitHubMCP, executeToolCall, executeToolCalls } = await import(
@@ -39,7 +40,7 @@ const { connectToGitHubMCP, executeToolCall, executeToolCalls } = await import(
3940

4041
describe('mcp.ts', () => {
4142
beforeEach(() => {
42-
jest.clearAllMocks()
43+
vi.clearAllMocks()
4344
})
4445

4546
describe('connectToGitHubMCP', () => {

__tests__/prompt.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect } from '@jest/globals'
1+
import { describe, it, expect } from 'vitest'
22
import * as path from 'path'
33
import { fileURLToPath } from 'url'
44
import {

0 commit comments

Comments
 (0)