Skip to content

Commit cb8a2a1

Browse files
committed
test: migrate to vitest
1 parent e0e6b5b commit cb8a2a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1176
-952
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ lib/
22
coverage/
33
node_modules/
44
fixtures/
5+
/auto-imports.d.ts

.eslintrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
'import/no-extraneous-dependencies': [
3232
'error',
3333
{
34-
devDependencies: ['**/*.test.js', '**/*.test.ts'],
34+
devDependencies: ['**/*.test.js', '**/*.test.ts', 'vitest.config.ts'],
3535
},
3636
],
3737
},

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ coverage/
33
node_modules/
44
fixtures/
55
CHANGELOG.md
6+
/auto-imports.d.ts

@commitlint/config-angular/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "module",
44
"version": "18.6.0",
55
"description": "Shareable commitlint config enforcing the angular commit convention",
6+
"main": "index.js",
67
"files": [
78
"index.js"
89
],

@commitlint/config-conventional/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "module",
44
"version": "18.6.0",
55
"description": "Shareable commitlint config enforcing conventional commits",
6+
"main": "index.js",
67
"files": [
78
"index.js"
89
],

@commitlint/config-lerna-scopes/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "module",
44
"version": "18.4.4",
55
"description": "Shareable commitlint config enforcing lerna package and workspace names as scopes",
6+
"main": "index.js",
67
"files": [
78
"index.js"
89
],
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,135 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`validation should fail for defaultIgnoresNotBoolean 1`] = `
4-
"Commitlint configuration in defaultIgnoresNotBoolean.js is invalid:
3+
exports[`validation should fail for > defaultIgnoresNotBoolean 1`] = `
4+
[Error: Commitlint configuration in defaultIgnoresNotBoolean.js is invalid:
55
- Property "defaultIgnores" has the wrong type - must be boolean.
6-
"
6+
]
77
`;
88

9-
exports[`validation should fail for extendsAsObject 1`] = `
10-
"Commitlint configuration in extendsAsObject.js is invalid:
9+
exports[`validation should fail for > extendsAsObject 1`] = `
10+
[Error: Commitlint configuration in extendsAsObject.js is invalid:
1111
- Property "extends" has the wrong type - must be array.
1212
- Property "extends" has the wrong type - must be string.
1313
- "/extends" must match exactly one schema in oneOf. Value: {"test":1}.
14-
"
14+
]
1515
`;
1616

17-
exports[`validation should fail for extendsWithFunction 1`] = `
18-
"Commitlint configuration in extendsWithFunction.js is invalid:
17+
exports[`validation should fail for > extendsWithFunction 1`] = `
18+
[Error: Commitlint configuration in extendsWithFunction.js is invalid:
1919
- Property "extends/0" has the wrong type - must be string.
2020
- Property "extends" has the wrong type - must be string.
2121
- "/extends" must match exactly one schema in oneOf. Value: [null].
22-
"
22+
]
2323
`;
2424

25-
exports[`validation should fail for formatterAsObject 1`] = `
26-
"Commitlint configuration in formatterAsObject.js is invalid:
25+
exports[`validation should fail for > formatterAsObject 1`] = `
26+
[Error: Commitlint configuration in formatterAsObject.js is invalid:
2727
- Property "formatter" has the wrong type - must be string.
28-
"
28+
]
2929
`;
3030

31-
exports[`validation should fail for helpUrlAsArray 1`] = `
32-
"Commitlint configuration in helpUrlAsArray.js is invalid:
31+
exports[`validation should fail for > helpUrlAsArray 1`] = `
32+
[Error: Commitlint configuration in helpUrlAsArray.js is invalid:
3333
- Property "helpUrl" has the wrong type - must be string.
34-
"
34+
]
3535
`;
3636

37-
exports[`validation should fail for helpUrlNotString 1`] = `
38-
"Commitlint configuration in helpUrlNotString.js is invalid:
37+
exports[`validation should fail for > helpUrlNotString 1`] = `
38+
[Error: Commitlint configuration in helpUrlNotString.js is invalid:
3939
- Property "helpUrl" has the wrong type - must be string.
40-
"
40+
]
4141
`;
4242

43-
exports[`validation should fail for ignoresFunction 1`] = `
44-
"Commitlint configuration in ignoresFunction.js is invalid:
43+
exports[`validation should fail for > ignoresFunction 1`] = `
44+
[Error: Commitlint configuration in ignoresFunction.js is invalid:
4545
- Property "ignores" has the wrong type - must be array.
46-
"
46+
]
4747
`;
4848

49-
exports[`validation should fail for ignoresNotFunction 1`] = `
50-
"Commitlint configuration in ignoresNotFunction.js is invalid:
49+
exports[`validation should fail for > ignoresNotFunction 1`] = `
50+
[Error: Commitlint configuration in ignoresNotFunction.js is invalid:
5151
- "/ignores/0" should be a function. Value: 1.
52-
"
52+
]
5353
`;
5454

55-
exports[`validation should fail for parserPreset 1`] = `
56-
"Commitlint configuration in parserPreset.js is invalid:
55+
exports[`validation should fail for > parserPreset 1`] = `
56+
[Error: Commitlint configuration in parserPreset.js is invalid:
5757
- Property "parserPreset" has the wrong type - must be string.
5858
- Property "parserPreset" has the wrong type - must be object.
5959
- "/parserPreset" should be a function. Value: [].
6060
- "/parserPreset" must match exactly one schema in oneOf. Value: [].
61-
"
61+
]
6262
`;
6363

64-
exports[`validation should fail for pluginsNotArray 1`] = `
65-
"Commitlint configuration in pluginsNotArray.js is invalid:
64+
exports[`validation should fail for > pluginsNotArray 1`] = `
65+
[Error: Commitlint configuration in pluginsNotArray.js is invalid:
6666
- Property "plugins" has the wrong type - must be array.
67-
"
67+
]
6868
`;
6969

70-
exports[`validation should fail for rules1 1`] = `
71-
"Commitlint configuration in rules1.js is invalid:
70+
exports[`validation should fail for > rules1 1`] = `
71+
[Error: Commitlint configuration in rules1.js is invalid:
7272
- "/rules/a/0" must be equal to one of the allowed values. Value: 3.
7373
- "/rules/a" should be a function. Value: [3].
7474
- "/rules/a" must match exactly one schema in oneOf. Value: [3].
75-
"
75+
]
7676
`;
7777

78-
exports[`validation should fail for rules2 1`] = `
79-
"Commitlint configuration in rules2.js is invalid:
78+
exports[`validation should fail for > rules2 1`] = `
79+
[Error: Commitlint configuration in rules2.js is invalid:
8080
- "/rules/b" must NOT have more than 3 items. Value: [1,"test",2,2].
8181
- "/rules/b" should be a function. Value: [1,"test",2,2].
8282
- "/rules/b" must match exactly one schema in oneOf. Value: [1,"test",2,2].
83-
"
83+
]
8484
`;
8585

86-
exports[`validation should fail for rules3 1`] = `
87-
"Commitlint configuration in rules3.js is invalid:
86+
exports[`validation should fail for > rules3 1`] = `
87+
[Error: Commitlint configuration in rules3.js is invalid:
8888
- "/rules/c" must NOT have fewer than 1 items. Value: [].
8989
- "/rules/c" should be a function. Value: [].
9090
- "/rules/c" must match exactly one schema in oneOf. Value: [].
91-
"
91+
]
9292
`;
9393

94-
exports[`validation should fail for rules4 1`] = `
95-
"Commitlint configuration in rules4.js is invalid:
94+
exports[`validation should fail for > rules4 1`] = `
95+
[Error: Commitlint configuration in rules4.js is invalid:
9696
- Property "rules/d/0" has the wrong type - must be number.
9797
- "/rules/d/0" must be equal to one of the allowed values. Value: [].
9898
- "/rules/d" should be a function. Value: [[],[],[]].
9999
- "/rules/d" must match exactly one schema in oneOf. Value: [[],[],[]].
100-
"
100+
]
101101
`;
102102

103-
exports[`validation should fail for rules5 1`] = `
104-
"Commitlint configuration in rules5.js is invalid:
103+
exports[`validation should fail for > rules5 1`] = `
104+
[Error: Commitlint configuration in rules5.js is invalid:
105105
- Property "rules/e" has the wrong type - must be array.
106106
- "/rules/e" should be a function. Value: {}.
107107
- "/rules/e" must match exactly one schema in oneOf. Value: {}.
108-
"
108+
]
109109
`;
110110

111-
exports[`validation should fail for rulesAsArray 1`] = `
112-
"Commitlint configuration in rulesAsArray.js is invalid:
111+
exports[`validation should fail for > rulesAsArray 1`] = `
112+
[Error: Commitlint configuration in rulesAsArray.js is invalid:
113113
- Property "rules" has the wrong type - must be object.
114-
"
114+
]
115115
`;
116116

117-
exports[`validation should fail for whenConfigIsNotObject 1`] = `
118-
"Commitlint configuration in whenConfigIsNotObject.js is invalid:
117+
exports[`validation should fail for > whenConfigIsNotObject 1`] = `
118+
[Error: Commitlint configuration in whenConfigIsNotObject.js is invalid:
119119
- Config has the wrong type - must be object.
120-
"
120+
]
121121
`;
122122

123-
exports[`validation should fail for whenConfigIsNotObject2 1`] = `
124-
"Commitlint configuration in whenConfigIsNotObject2.js is invalid:
123+
exports[`validation should fail for > whenConfigIsNotObject2 1`] = `
124+
[Error: Commitlint configuration in whenConfigIsNotObject2.js is invalid:
125125
- Config has the wrong type - must be object.
126-
"
126+
]
127127
`;
128128

129-
exports[`validation should fail for withPluginsAsObject 1`] = `
130-
"Commitlint configuration in withPluginsAsObject.js is invalid:
129+
exports[`validation should fail for > withPluginsAsObject 1`] = `
130+
[Error: Commitlint configuration in withPluginsAsObject.js is invalid:
131131
- Property "plugins/0" has the wrong type - must be string.
132132
- "/plugins/0" must have required property 'rules'. Value: {}.
133133
- "/plugins/0" must match a schema in anyOf. Value: {}.
134-
"
134+
]
135135
`;

@commitlint/config-validator/src/validate.test.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {validateConfig} from './validate';
21
import {RuleConfigSeverity, UserConfig} from '@commitlint/types';
32

3+
import {validateConfig} from './validate.js';
4+
45
const validSchemas: Record<string, UserConfig> = {
56
empty: {},
67
withEmptyExtends: {extends: []},
@@ -9,7 +10,13 @@ const validSchemas: Record<string, UserConfig> = {
910
withMultipleExtends: {extends: ['test', 'test2']},
1011
withFormatter: {formatter: ''},
1112
withHelpUrl: {helpUrl: ''},
12-
withRules: {rules: {a: [RuleConfigSeverity.Disabled], b: [RuleConfigSeverity.Warning, 'never'], c: [RuleConfigSeverity.Error, 'never', true]}},
13+
withRules: {
14+
rules: {
15+
a: [RuleConfigSeverity.Disabled],
16+
b: [RuleConfigSeverity.Warning, 'never'],
17+
c: [RuleConfigSeverity.Error, 'never', true],
18+
},
19+
},
1320
withParserPresetString: {parserPreset: 'test'},
1421
withParserPresetObject: {parserPreset: {}},
1522
withParserPresetObject2: {parserPreset: {name: 'string', path: 'string'}},

@commitlint/cz-commitlint/src/Process.test.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import {QualifiedRules, RuleConfigSeverity, UserPromptConfig} from '@commitlint/
22
import {Answers, DistinctQuestion} from 'inquirer';
33
import isFunction from 'lodash.isfunction';
44

5-
import {jest} from '@jest/globals';
5+
import process from './Process.js';
66

7-
import process from './Process';
8-
9-
const mockShowTitle = jest.fn();
10-
const mockShowValidation = jest.fn((message) => message);
7+
const mockShowTitle = vi.fn();
8+
const mockShowValidation = vi.fn((message) => message);
119

1210
// mock inquirer
13-
const mockPrompt = jest.fn(async function (
11+
const mockPrompt = vi.fn(async function (
1412
questions: DistinctQuestion[],
1513
answers: Answers
1614
) {

@commitlint/cz-commitlint/src/Question.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import chalk from 'chalk';
22
import inquirer, {Answers, InputQuestionOptions} from 'inquirer';
33

4-
import {jest} from '@jest/globals';
5-
6-
import Question from './Question';
4+
import Question from './Question.js';
75

86
const MESSAGES = {
97
skip: '(press enter to skip)',
@@ -179,7 +177,7 @@ describe('message', () => {
179177
});
180178

181179
test('should execute function beforeQuestionStart when init message', () => {
182-
const mockFn = jest.fn();
180+
const mockFn = vi.fn();
183181
class CustomQuestion extends Question {
184182
beforeQuestionStart(answers: Answers): void {
185183
mockFn(answers);

@commitlint/cz-commitlint/src/SectionBody.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {RuleConfigSeverity} from '@commitlint/types';
2-
import {combineCommitMessage, getQuestions} from './SectionBody';
3-
import {setRules} from './store/rules';
2+
3+
import {combineCommitMessage, getQuestions} from './SectionBody.js';
4+
import {setRules} from './store/rules.js';
45

56
describe('getQuestions', () => {
67
test('should exclude question when body must be empty', () => {

@commitlint/cz-commitlint/src/SectionFooter.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {RuleConfigSeverity} from '@commitlint/types';
2-
import {combineCommitMessage, getQuestions} from './SectionFooter';
3-
import {setPromptConfig} from './store/prompts';
4-
import {setRules} from './store/rules';
2+
3+
import {combineCommitMessage, getQuestions} from './SectionFooter.js';
4+
import {setPromptConfig} from './store/prompts.js';
5+
import {setRules} from './store/rules.js';
56

67
beforeEach(() => {
78
setRules({});

@commitlint/cz-commitlint/src/SectionHeader.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {RuleConfigSeverity} from '@commitlint/types';
2+
23
import {
34
combineCommitMessage,
45
getQuestions,
56
getQuestionConfig,
6-
} from './SectionHeader';
7-
import {setPromptConfig} from './store/prompts';
8-
import {setRules} from './store/rules';
7+
} from './SectionHeader.js';
8+
import {setPromptConfig} from './store/prompts.js';
9+
import {setRules} from './store/rules.js';
910

1011
beforeEach(() => {
1112
setRules({});

@commitlint/cz-commitlint/src/services/getRuleQuestionConfig.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {RuleConfigSeverity} from '@commitlint/types';
2-
import {setPromptConfig} from '../store/prompts';
3-
import {setRules} from '../store/rules';
4-
import getRuleQuestionConfig from './getRuleQuestionConfig';
2+
3+
import {setPromptConfig} from '../store/prompts.js';
4+
import {setRules} from '../store/rules.js';
5+
import getRuleQuestionConfig from './getRuleQuestionConfig.js';
56

67
// let rules = {};
78

@commitlint/cz-commitlint/src/store/prompts.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {jest} from '@jest/globals';
2-
31
import * as prompts from './prompts.js';
42

53
let getPromptQuestions: typeof prompts.getPromptQuestions;
@@ -8,7 +6,7 @@ let getPromptSettings: typeof prompts.getPromptSettings;
86
let setPromptConfig: typeof prompts.setPromptConfig;
97

108
beforeEach(async () => {
11-
jest.resetModules();
9+
vi.resetModules();
1210
({getPromptQuestions, getPromptMessages, getPromptSettings, setPromptConfig} =
1311
await import('./prompts.js'));
1412
});
@@ -118,7 +116,7 @@ describe('setPromptConfig', () => {
118116
});
119117
expect(getPromptSettings()['scopeEnumSeparator']).toEqual('/');
120118

121-
const processExit = jest
119+
const processExit = vi
122120
.spyOn(process, 'exit')
123121
.mockImplementation(() => undefined as never);
124122
setPromptConfig({

@commitlint/cz-commitlint/src/store/rules.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {QualifiedRules, RuleConfigSeverity} from '@commitlint/types';
2-
import {GetRuleMethod, SetRulesMethod} from './rules';
2+
3+
import {GetRuleMethod, SetRulesMethod} from './rules.js';
34

45
let getRule: GetRuleMethod;
56
let setRules: SetRulesMethod;
67

78
beforeEach(async () => {
8-
jest.resetModules();
9+
vi.resetModules();
910
({getRule, setRules} = await import('./rules.js'));
1011
});
1112

@commitlint/cz-commitlint/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"outDir": "./lib"
77
},
88
"include": ["./src"],
9-
"exclude": ["./src/**/*.test.ts", "./lib/**/*"],
9+
"exclude": ["./src/**/*.test.ts", "./src/**/*-test.ts", "./lib/**/*"],
1010
"references": [{"path": "../cli"}]
1111
}

0 commit comments

Comments
 (0)