Skip to content

Commit e2b402d

Browse files
committed
switch from jest to vitest
Signed-off-by: CrazyMax <[email protected]>
1 parent e79596b commit e2b402d

9 files changed

Lines changed: 1367 additions & 3427 deletions

File tree

__tests__/context.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
1+
import {beforeEach, describe, expect, vi, test} from 'vitest';
22
import * as fs from 'fs';
3+
import * as os from 'os';
34
import * as path from 'path';
45

56
import {Context} from '@docker/actions-toolkit/lib/context';
67

78
import * as context from '../src/context';
89

9-
// prettier-ignore
10-
const tmpDir = path.join(process.env.TEMP || '/tmp', 'setup-compose-jest');
11-
const tmpName = path.join(tmpDir, '.tmpname-jest');
10+
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'context-'));
11+
const tmpName = path.join(tmpDir, '.tmpname-vi');
1212

13-
jest.spyOn(Context, 'tmpDir').mockImplementation((): string => {
13+
vi.spyOn(Context, 'tmpDir').mockImplementation((): string => {
1414
if (!fs.existsSync(tmpDir)) {
1515
fs.mkdirSync(tmpDir, {recursive: true});
1616
}
1717
return tmpDir;
1818
});
1919

20-
jest.spyOn(Context, 'tmpName').mockImplementation((): string => {
20+
vi.spyOn(Context, 'tmpName').mockImplementation((): string => {
2121
return tmpName;
2222
});
2323

__tests__/setup.unit.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import fs from 'node:fs';
2+
import os from 'node:os';
3+
import path from 'node:path';
4+
5+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-actions-toolkit-'));
6+
7+
process.env = Object.assign({}, process.env, {
8+
TEMP: tmpDir,
9+
GITHUB_REPOSITORY: 'docker/setup-compose-action',
10+
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
11+
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
12+
});

dev.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ FROM deps AS test
7474
RUN --mount=type=bind,target=.,rw \
7575
--mount=type=cache,target=/src/.yarn/cache \
7676
--mount=type=cache,target=/src/node_modules \
77-
yarn run test --coverage --coverageDirectory=/tmp/coverage
77+
yarn run test --coverage --coverage.reportsDirectory=/tmp/coverage
7878

7979
FROM scratch AS test-coverage
8080
COPY --from=test /tmp/coverage /

eslint.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const {defineConfig, globalIgnores} = require('eslint/config');
33
const {fixupConfigRules, fixupPluginRules} = require('@eslint/compat');
44
const typescriptEslint = require('@typescript-eslint/eslint-plugin');
5-
const jestPlugin = require('eslint-plugin-jest');
5+
const vitestPlugin = require('@vitest/eslint-plugin');
66
const prettier = require('eslint-plugin-prettier');
77
const globals = require('globals');
88
const tsParser = require('@typescript-eslint/parser');
@@ -25,21 +25,21 @@ module.exports = defineConfig([
2525
'eslint:recommended',
2626
'plugin:@typescript-eslint/eslint-recommended',
2727
'plugin:@typescript-eslint/recommended',
28-
'plugin:jest/recommended',
28+
'plugin:@vitest/legacy-recommended',
2929
'plugin:prettier/recommended'
3030
)
3131
),
3232

3333
plugins: {
3434
'@typescript-eslint': fixupPluginRules(typescriptEslint),
35-
jest: fixupPluginRules(jestPlugin),
35+
'@vitest': fixupPluginRules(vitestPlugin),
3636
prettier: fixupPluginRules(prettier)
3737
},
3838

3939
languageOptions: {
4040
globals: {
4141
...globals.node,
42-
...globals.jest
42+
...vitestPlugin.environments.env.globals
4343
},
4444
parser: tsParser,
4545
ecmaVersion: 'latest',

jest.config.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"eslint:fix": "eslint --fix .",
1111
"prettier": "prettier --check \"./**/*.ts\"",
1212
"prettier:fix": "prettier --write \"./**/*.ts\"",
13-
"test": "jest"
13+
"test": "vitest run"
1414
},
1515
"repository": {
1616
"type": "git",
@@ -36,14 +36,14 @@
3636
"@typescript-eslint/eslint-plugin": "^8.50.0",
3737
"@typescript-eslint/parser": "^8.50.0",
3838
"@vercel/ncc": "^0.38.4",
39+
"@vitest/coverage-v8": "^4.0.18",
40+
"@vitest/eslint-plugin": "^1.6.9",
3941
"eslint": "^9.39.2",
4042
"eslint-config-prettier": "^10.1.8",
41-
"eslint-plugin-jest": "^29.5.0",
4243
"eslint-plugin-prettier": "^5.5.4",
43-
"jest": "^30.2.0",
4444
"prettier": "^3.7.4",
45-
"ts-jest": "^29.4.6",
4645
"ts-node": "^10.9.2",
47-
"typescript": "^5.9.3"
46+
"typescript": "^5.9.3",
47+
"vitest": "^4.0.18"
4848
}
4949
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"./__tests__/**/*",
1717
"./lib/**/*",
1818
"node_modules",
19-
"jest.config.ts"
19+
"vitest.config.ts"
2020
]
2121
}

vitest.config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright 2026 actions-toolkit authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {defineConfig} from 'vitest/config';
18+
19+
export default defineConfig({
20+
test: {
21+
clearMocks: true,
22+
environment: 'node',
23+
setupFiles: ['./__tests__/setup.unit.ts'],
24+
include: ['**/*.test.ts'],
25+
coverage: {
26+
provider: 'v8',
27+
reporter: ['clover'],
28+
include: ['src/**/*.ts'],
29+
exclude: ['src/**/main.ts', '__tests__/**', 'dist/**']
30+
}
31+
}
32+
});

0 commit comments

Comments
 (0)