Skip to content

Commit 3832769

Browse files
refactor: migrate testing framework from Jest to Vitest (#87)
* refactor: migrate testing framework from Jest to Vitest - Updated package.json to replace Jest with Vitest for testing scripts. - Removed Jest configuration from package.json. - Added Vitest configuration in a new vitest.config.ts file. - Updated tsconfig.json to include Vitest types and exclude vitest.config.ts from compilation. - Adjusted test scripts to support coverage reporting with Vitest. * fix: add "type": "module" to package.json * feat: add Vitest configuration and update references in ESLint and TypeScript config
1 parent ca09286 commit 3832769

File tree

11 files changed

+3226
-6165
lines changed

11 files changed

+3226
-6165
lines changed

.github/linters/eslint.config.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import jest from 'eslint-plugin-jest'
1+
import vitest from 'eslint-plugin-vitest'
22
import typescriptEslint from '@typescript-eslint/eslint-plugin'
33
import globals from 'globals'
44
import tsParser from '@typescript-eslint/parser'
@@ -26,24 +26,24 @@ export default [
2626
'**/lib/**',
2727
'**/dist/**',
2828
'**/coverage/**',
29-
'**/.github/linters/**'
29+
'**/.github/linters/**',
30+
'vitest.config.mts'
3031
]
3132
},
3233
...compat.extends(
3334
'eslint:recommended',
34-
'plugin:@typescript-eslint/recommended-type-checked',
35-
'plugin:jest/recommended'
35+
'plugin:@typescript-eslint/recommended-type-checked'
3636
),
37+
vitest.configs.recommended,
3738
{
3839
plugins: {
39-
jest,
40+
vitest,
4041
'@typescript-eslint': typescriptEslint
4142
},
4243

4344
languageOptions: {
4445
globals: {
4546
...globals.node,
46-
...globals.jest,
4747
Atomics: 'readonly',
4848
SharedArrayBuffer: 'readonly'
4949
},

__tests__/dependabot-validator.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
import * as core from '@actions/core'
77
import * as github from '@actions/github'
88
import { DependabotValidator } from '../src/dependabot-validator'
9+
import { vi, describe, test, expect, beforeEach } from 'vitest'
910

10-
jest.mock('@actions/core')
11+
vi.mock('@actions/core')
1112

1213
/**
1314
* Test suite for the DependabotValidator class
1415
*/
1516
describe('DependabotValidator', () => {
1617
// Setup test environment and mocks
17-
const mockSetFailed = jest.mocked(core.setFailed)
18-
const mockInfo = jest.mocked(core.info)
18+
const mockSetFailed = vi.mocked(core.setFailed)
19+
const mockInfo = vi.mocked(core.info)
1920

20-
const mockGetContent = jest.fn()
21+
const mockGetContent = vi.fn()
2122
const mockOctokit = {
2223
rest: {
2324
repos: {
@@ -29,7 +30,7 @@ describe('DependabotValidator', () => {
2930
const validator = new DependabotValidator(mockOctokit)
3031

3132
beforeEach(() => {
32-
jest.clearAllMocks()
33+
vi.clearAllMocks()
3334
})
3435

3536
describe('configuration validation', () => {

__tests__/ecosystem-mapping.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
*/
55

66
import { getEcosystemLanguageMapping } from '../src/ecosystem-mapping'
7+
import { vi, describe, test, expect, beforeEach } from 'vitest'
78

8-
jest.mock('@actions/core')
9+
vi.mock('@actions/core')
910

1011
/**
1112
* Test suite for the ecosystem mapping functionality
1213
*/
1314
describe('ecosystem-mapping module', () => {
1415
beforeEach(() => {
15-
jest.clearAllMocks()
16+
vi.clearAllMocks()
1617
})
1718

1819
describe('language mapping', () => {

__tests__/index.test.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
/**
2-
* Unit tests for the action's entrypoint (index.ts)
3-
* Verifies that the action's main function is called when the module is imported
2+
* Unit tests for the action's entrypoint (src/index.ts)
43
*/
54

65
import * as main from '../src/main'
6+
import { vi, describe, it, expect } from 'vitest'
77

8-
// Mock the action's entrypoint
9-
const runMock = jest.spyOn(main, 'run').mockImplementation()
8+
/**
9+
* Mock implementation of the main run function
10+
*/
11+
const mockRun = vi.spyOn(main, 'run').mockImplementation()
1012

1113
/**
12-
* Test suite for the index module
14+
* Test suite for the action's entry point
1315
*/
14-
describe('index module', () => {
15-
test('should call run function when module is imported', () => {
16-
// eslint-disable-next-line @typescript-eslint/no-require-imports
17-
require('../src/index')
16+
describe('index', () => {
17+
/**
18+
* Test case: Verifies that the run function is called when the index is imported
19+
*/
20+
it('calls run when imported', async () => {
21+
await import('../src/index')
1822

19-
expect(runMock).toHaveBeenCalled()
23+
expect(mockRun).toHaveBeenCalled()
2024
})
2125
})

__tests__/main.test.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,41 @@ import * as core from '@actions/core'
77
import * as github from '@actions/github'
88
import { Context } from '@actions/github/lib/context'
99
import { run } from '../src/main'
10-
11-
jest.mock('@actions/core')
12-
jest.mock('@actions/github')
10+
import {
11+
vi,
12+
describe,
13+
test,
14+
expect,
15+
beforeEach,
16+
type MockInstance
17+
} from 'vitest'
18+
19+
vi.mock('@actions/core')
20+
vi.mock('@actions/github')
1321

1422
/**
1523
* Main test suite for the validate-dependabot integration
1624
* Tests various scenarios including successful execution and error handling
1725
*/
1826
describe('validate-dependabot integration', () => {
1927
// Setup mock implementations
20-
const mockGetInput = core.getInput as jest.MockedFunction<
21-
typeof core.getInput
22-
>
23-
const mockSetFailed = core.setFailed as jest.MockedFunction<
24-
typeof core.setFailed
25-
>
28+
let mockGetInput: MockInstance<typeof core.getInput>
29+
let mockSetFailed: MockInstance<typeof core.setFailed>
2630
const mockOctokit = {
2731
rest: {
2832
repos: {
29-
listLanguages: jest.fn(),
30-
getContent: jest.fn()
33+
listLanguages: vi.fn(),
34+
getContent: vi.fn()
3135
}
3236
}
3337
}
3438

3539
beforeEach(() => {
36-
jest.clearAllMocks()
40+
vi.clearAllMocks()
41+
mockGetInput = vi.spyOn(core, 'getInput')
42+
mockSetFailed = vi.spyOn(core, 'setFailed')
3743
mockGetInput.mockReturnValue('mock-token')
38-
;(github.getOctokit as jest.Mock).mockReturnValue(mockOctokit)
44+
vi.mocked(github.getOctokit).mockReturnValue(mockOctokit)
3945
Object.defineProperty(github, 'context', {
4046
value: {
4147
repo: {

dist/index.js

Lines changed: 17 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)