Skip to content

Commit 4842870

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

9 files changed

Lines changed: 1203 additions & 3175 deletions

File tree

__tests__/context.test.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {beforeEach, describe, expect, test} from '@jest/globals';
1+
import {beforeEach, describe, expect, test} from 'vitest';
22
import * as os from 'os';
33
import * as path from 'path';
44

@@ -15,7 +15,7 @@ describe('getInputs', () => {
1515
});
1616

1717
// prettier-ignore
18-
test.each([
18+
const cases: [number, Map<string, string>, context.Inputs][] = [
1919
[
2020
0,
2121
new Map<string, string>([
@@ -35,7 +35,7 @@ describe('getInputs', () => {
3535
setHost: false,
3636
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
3737
githubToken: '',
38-
} as context.Inputs
38+
}
3939
],
4040
[
4141
1,
@@ -59,7 +59,7 @@ describe('getInputs', () => {
5959
setHost: false,
6060
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
6161
githubToken: '',
62-
} as context.Inputs
62+
}
6363
],
6464
[
6565
2,
@@ -79,7 +79,7 @@ describe('getInputs', () => {
7979
setHost: true,
8080
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
8181
githubToken: '',
82-
} as context.Inputs
82+
}
8383
],
8484
[
8585
3,
@@ -101,7 +101,7 @@ describe('getInputs', () => {
101101
setHost: false,
102102
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
103103
githubToken: '',
104-
} as context.Inputs
104+
}
105105
],
106106
[
107107
4,
@@ -121,7 +121,7 @@ describe('getInputs', () => {
121121
setHost: false,
122122
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
123123
githubToken: '',
124-
} as context.Inputs
124+
}
125125
],
126126
[
127127
5,
@@ -142,7 +142,7 @@ describe('getInputs', () => {
142142
rootless: false,
143143
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
144144
githubToken: '',
145-
} as context.Inputs
145+
}
146146
],
147147
[
148148
6,
@@ -163,7 +163,7 @@ describe('getInputs', () => {
163163
rootless: false,
164164
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
165165
githubToken: '',
166-
} as context.Inputs
166+
}
167167
],
168168
[
169169
7,
@@ -183,7 +183,7 @@ describe('getInputs', () => {
183183
rootless: false,
184184
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
185185
githubToken: '',
186-
} as context.Inputs
186+
}
187187
],
188188
[
189189
8,
@@ -203,7 +203,7 @@ describe('getInputs', () => {
203203
rootless: true,
204204
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
205205
githubToken: '',
206-
} as context.Inputs
206+
}
207207
],
208208
[
209209
9,
@@ -226,10 +226,11 @@ describe('getInputs', () => {
226226
setHost: false,
227227
runtimeBasedir: path.join(os.homedir(), `setup-docker-action`),
228228
githubToken: '',
229-
} as context.Inputs
229+
}
230230
],
231-
])(
232-
'[%d] given %p as inputs, returns %p',
231+
];
232+
test.each(cases)(
233+
'[%d] given %o as inputs, returns %o',
233234
async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
234235
inputs.forEach((value: string, name: string) => {
235236
setInput(name, value);

__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-setup-docker-action-'));
6+
7+
process.env = Object.assign({}, process.env, {
8+
TEMP: tmpDir,
9+
GITHUB_REPOSITORY: 'docker/setup-docker-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: 5 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');
@@ -19,26 +19,27 @@ const compat = new FlatCompat({
1919
module.exports = defineConfig([
2020
globalIgnores(['dist/**/*', 'coverage/**/*', 'node_modules/**/*']),
2121
{
22+
// prettier-ignore
2223
extends: fixupConfigRules(
2324
compat.extends(
2425
'eslint:recommended',
2526
'plugin:@typescript-eslint/eslint-recommended',
2627
'plugin:@typescript-eslint/recommended',
27-
'plugin:jest/recommended',
28+
'plugin:@vitest/legacy-recommended',
2829
'plugin:prettier/recommended'
2930
)
3031
),
3132

3233
plugins: {
3334
'@typescript-eslint': fixupPluginRules(typescriptEslint),
34-
jest: fixupPluginRules(jestPlugin),
35+
'@vitest': fixupPluginRules(vitestPlugin),
3536
prettier: fixupPluginRules(prettier)
3637
},
3738

3839
languageOptions: {
3940
globals: {
4041
...globals.node,
41-
...globals.jest
42+
...vitestPlugin.environments.env.globals
4243
},
4344
parser: tsParser,
4445
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
"all": "yarn run build && yarn run format && yarn test"
1515
},
1616
"repository": {
@@ -37,14 +37,14 @@
3737
"@typescript-eslint/eslint-plugin": "^8.50.0",
3838
"@typescript-eslint/parser": "^8.50.0",
3939
"@vercel/ncc": "^0.38.4",
40+
"@vitest/coverage-v8": "^4.0.18",
41+
"@vitest/eslint-plugin": "^1.6.9",
4042
"eslint": "^9.39.2",
4143
"eslint-config-prettier": "^10.1.8",
42-
"eslint-plugin-jest": "^29.5.0",
4344
"eslint-plugin-prettier": "^5.5.4",
44-
"jest": "^30.2.0",
4545
"prettier": "^3.7.4",
46-
"ts-jest": "^29.4.6",
4746
"ts-node": "^10.9.2",
48-
"typescript": "^5.9.3"
47+
"typescript": "^5.9.3",
48+
"vitest": "^4.0.18"
4949
}
5050
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"exclude": [
1515
"node_modules",
1616
"**/*.test.ts",
17-
"jest.config.ts"
17+
"vitest.config.ts"
1818
]
1919
}

vitest.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {defineConfig} from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
clearMocks: true,
6+
environment: 'node',
7+
setupFiles: ['./__tests__/setup.unit.ts'],
8+
include: ['**/*.test.ts'],
9+
coverage: {
10+
provider: 'v8',
11+
reporter: ['clover'],
12+
include: ['src/**/*.ts'],
13+
exclude: ['src/**/main.ts']
14+
}
15+
}
16+
});

0 commit comments

Comments
 (0)