Skip to content

Commit d6d2056

Browse files
feat: use vitest
1 parent 0866ea6 commit d6d2056

15 files changed

+136
-1872
lines changed

__tests__/config.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* eslint-disable no-magic-numbers */
2+
import { beforeEach, describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
3-
import {getParams} from '@technote-space/release-github-actions/lib/utils/misc';
4+
import {Misc} from '@technote-space/release-github-actions';
45
import {normalizeConfigKey, normalizeConfigKeys, getActionDefaultInputs, getConfig} from '../src/config';
56

67
const fixturesDir = resolve(__dirname, 'fixtures');
78
beforeEach(() => {
8-
getParams.clear();
9+
Misc.getParams.clear();
910
});
1011

1112
describe('normalizeConfigKey', () => {

__tests__/env.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable no-magic-numbers */
2+
import { beforeEach, describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {testEnv} from '@technote-space/github-action-test-helper';
4-
import {getParams} from '@technote-space/release-github-actions/lib/utils/misc';
5+
import {Misc} from '@technote-space/release-github-actions';
56
import {setEnv, loadTokenFromEnv} from '../src/env';
67

78
const fixturesDir = resolve(__dirname, 'fixtures');
89
beforeEach(() => {
9-
getParams.clear();
10+
Misc.getParams.clear();
1011
});
1112

1213
describe('setEnv', () => {

__tests__/index.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable no-magic-numbers */
2+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
23
import {
34
testEnv,
45
spyOnStdout,
@@ -10,14 +11,14 @@ import {
1011
setChildProcessParams,
1112
} from '@technote-space/github-action-test-helper';
1213
import {Logger} from '@technote-space/github-action-log-helper';
13-
import {getParams} from '@technote-space/release-github-actions/lib/utils/misc';
14+
import {Misc} from '@technote-space/release-github-actions';
1415
import {execute} from '../src';
1516

1617
const setExists = testFs(false);
1718
const saveArgv = process.argv;
1819
beforeEach(() => {
1920
Logger.resetForTesting();
20-
getParams.clear();
21+
Misc.getParams.clear();
2122
});
2223

2324
describe('execute', () => {

__tests__/misc.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/* eslint-disable no-magic-numbers */
2+
import { beforeEach, describe, expect, it } from 'vitest';
23
import {resolve} from 'path';
34
import {testEnv, testFs, setChildProcessParams} from '@technote-space/github-action-test-helper';
4-
import {getParams} from '@technote-space/release-github-actions/lib/utils/misc';
5+
import {Misc} from '@technote-space/release-github-actions';
56
import {getRepository, getContext, getContextArgs, getGitHelper} from '../src/misc';
67

78
const fixturesDir = resolve(__dirname, 'fixtures');
89
testFs(true);
910
beforeEach(() => {
10-
getParams.clear();
11+
Misc.getParams.clear();
1112
});
1213

1314
describe('getRepository', () => {

jest.config.js

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

jest.setup.ts

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

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
],
3131
"scripts": {
3232
"build": "yarn install && tsc && yarn install --production",
33-
"cover": "jest --coverage",
33+
"cover": "vitest run --coverage",
3434
"postinstall": "[ -n \"$CI\" ] || [ ! -f node_modules/.bin/husky ] || husky install",
3535
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache",
3636
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
@@ -43,7 +43,7 @@
4343
"dependencies": {
4444
"@technote-space/github-action-helper": "^5.3.5",
4545
"@technote-space/github-action-log-helper": "^0.2.4",
46-
"@technote-space/release-github-actions": "^7.2.0",
46+
"@technote-space/release-github-actions": "^7.2.1",
4747
"commander": "^9.2.0",
4848
"cosmiconfig": "^7.0.1",
4949
"dotenv": "^16.0.0",
@@ -53,18 +53,16 @@
5353
"@commitlint/cli": "^16.2.3",
5454
"@commitlint/config-conventional": "^16.2.1",
5555
"@technote-space/github-action-test-helper": "^0.9.5",
56-
"@types/jest": "^27.4.1",
5756
"@types/node": "^17.0.25",
5857
"@typescript-eslint/eslint-plugin": "^5.20.0",
5958
"@typescript-eslint/parser": "^5.20.0",
59+
"c8": "^7.11.2",
6060
"eslint": "^8.13.0",
6161
"husky": "^7.0.4",
62-
"jest": "^27.5.1",
63-
"jest-circus": "^27.5.1",
6462
"lint-staged": "^12.4.0",
6563
"pinst": "^3.0.0",
66-
"ts-jest": "^27.1.4",
67-
"typescript": "^4.6.3"
64+
"typescript": "^4.6.3",
65+
"vitest": "^0.9.4"
6866
},
6967
"publishConfig": {
7068
"access": "public"

src/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {Config} from './types';
22
import {cosmiconfigSync} from 'cosmiconfig';
3-
import {existsSync, readFileSync} from 'fs';
3+
import fs from 'fs';
44
import {resolve} from 'path';
55
import {load} from 'js-yaml';
66
import {getRepository} from './misc';
@@ -12,12 +12,12 @@ export const normalizeConfigKeys = (config: { [key: string]: string }): { [key:
1212
})));
1313

1414
/* istanbul ignore next */
15-
const getActionSettingFile = (): string => existsSync(resolve(__dirname, '../../release-github-actions/action.yml')) ?
15+
const getActionSettingFile = (): string => fs.existsSync(resolve(__dirname, '../../release-github-actions/action.yml')) ?
1616
resolve(__dirname, '../../release-github-actions/action.yml') :
1717
resolve(__dirname, '../node_modules/@technote-space/release-github-actions/action.yml');
1818

1919
export const getActionDefaultInputs = (): { [key: string]: string } => {
20-
const actionSetting = load(readFileSync(getActionSettingFile(), 'utf8'));
20+
const actionSetting = load(fs.readFileSync(getActionSettingFile(), 'utf8'));
2121
const inputs = actionSetting['inputs'];
2222
return Object.assign({}, ...Object.keys(inputs).filter(key => 'default' in inputs[key]).map(key => ({
2323
[normalizeConfigKey(key)]: `${inputs[key].default}`,

src/env.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type {Config} from './types';
22
import dotenv from 'dotenv';
3-
import {existsSync, readFileSync} from 'fs';
3+
import fs from 'fs';
44
import {resolve} from 'path';
55

66
export const loadTokenFromEnv = (dir: string): string | undefined => {
7-
if (!existsSync(resolve(dir, '.env'))) {
7+
if (!fs.existsSync(resolve(dir, '.env'))) {
88
return;
99
}
1010

11-
const config = dotenv.parse(readFileSync(resolve(dir, '.env')));
11+
const config = dotenv.parse(fs.readFileSync(resolve(dir, '.env')));
1212
return config.token ?? config.TOKEN;
1313
};
1414

src/misc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type {Context} from '@actions/github/lib/context';
22
import type {Config, ContextArgs} from './types';
3-
import {readFileSync} from 'fs';
3+
import fs from 'fs';
44
import {resolve} from 'path';
55
import {GitHelper} from '@technote-space/github-action-helper';
66
import {Logger} from '@technote-space/github-action-log-helper';
77

88
export const getRepository = (dir: string): { owner: string; repo: string } | never => {
9-
const json = JSON.parse(readFileSync(resolve(dir, 'package.json'), {encoding: 'utf8'}));
9+
const json = JSON.parse(fs.readFileSync(resolve(dir, 'package.json'), {encoding: 'utf8'}));
1010
const url = json ? json.repository?.url ?? json.homepage ?? json.bugs?.url : '';
1111
if (!url) {
1212
throw new Error('Invalid package file.');

0 commit comments

Comments
 (0)