Skip to content

Commit 57b5baf

Browse files
committed
refactor(test/scope-maker): adapt with dependencies upgrade
1 parent 471df38 commit 57b5baf

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/prompts/scope-maker.test.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import { ListQuestion } from 'inquirer';
2-
import { Rule, Case, Level, Rules } from '@commitlint/load';
2+
import type { RuleConfig, RuleConfigQuality, RulesConfig, TargetCaseType } from '@commitlint/types';
3+
import { RuleConfigSeverity } from '@commitlint/types';
34
import { scopeMaker, filterFactory, validatorFactory, choicesFactory } from './scope-maker';
45

56
describe('scopeMaker', () => {
67
describe('validatorFactory', () => {
7-
test.each<[string, Rules, string | true]>([
8-
['', { 'scope-empty': [Level.Error, 'never', undefined] }, 'Scope cannot be empty'],
9-
['foo', { 'scope-empty': [Level.Error, 'never', undefined] }, true],
10-
['foo', { 'scope-max-length': [Level.Error, 'always', 72] }, true],
11-
['foo bar', { 'scope-max-length': [Level.Error, 'always', 3] }, 'Scope maximum length of 3 has been exceeded'],
12-
['foo', { 'scope-min-length': [Level.Error, 'always', 3] }, true],
13-
['f', { 'scope-min-length': [Level.Error, 'always', 3] }, 'Scope minimum length of 3 has not been met'],
14-
['foo', { 'scope-case': [Level.Error, 'always', 'lower-case'] }, true],
15-
['foo', { 'scope-case': [Level.Error, 'always', 'upper-case'] }, 'Scope must be in upper-case'],
16-
['foo', { 'scope-case': [Level.Error, 'never', 'lower-case'] }, 'Scope must not be in lower-case'],
17-
['foo', { 'scope-case': [Level.Error, 'never', 'upper-case'] }, true],
8+
test.each<[string, Partial<RulesConfig<RuleConfigQuality.Qualified>>, string | true]>([
9+
['', { 'scope-empty': [RuleConfigSeverity.Error, 'never'] }, 'Scope cannot be empty'],
10+
['foo', { 'scope-empty': [RuleConfigSeverity.Error, 'never'] }, true],
11+
['foo', { 'scope-max-length': [RuleConfigSeverity.Error, 'always', 72] }, true],
12+
[
13+
'foo bar',
14+
{ 'scope-max-length': [RuleConfigSeverity.Error, 'always', 3] },
15+
'Scope maximum length of 3 has been exceeded',
16+
],
17+
['foo', { 'scope-min-length': [RuleConfigSeverity.Error, 'always', 3] }, true],
18+
[
19+
'f',
20+
{ 'scope-min-length': [RuleConfigSeverity.Error, 'always', 3] },
21+
'Scope minimum length of 3 has not been met',
22+
],
23+
['foo', { 'scope-case': [RuleConfigSeverity.Error, 'always', 'lower-case'] }, true],
24+
['foo', { 'scope-case': [RuleConfigSeverity.Error, 'always', 'upper-case'] }, 'Scope must be in upper-case'],
25+
['foo', { 'scope-case': [RuleConfigSeverity.Error, 'never', 'lower-case'] }, 'Scope must not be in lower-case'],
26+
['foo', { 'scope-case': [RuleConfigSeverity.Error, 'never', 'upper-case'] }, true],
1827
])('value: %s, rule: %o, expected: %s', (value, rules, expected) => {
1928
const fixture = validatorFactory(rules);
2029

@@ -35,7 +44,7 @@ describe('scopeMaker', () => {
3544
});
3645

3746
test('should not prompt when scope-empty', () => {
38-
const scopeConfig = scopeMaker([], { 'scope-empty': [2, 'always', undefined] })[0];
47+
const scopeConfig = scopeMaker([], { 'scope-empty': [2, 'always'] })[0];
3948

4049
if (typeof scopeConfig.when == 'function') {
4150
const result = scopeConfig.when({});
@@ -79,15 +88,15 @@ describe('scopeMaker', () => {
7988
describe('choicesFactory', () => {
8089
it('should not allow non-empty scope when empty scope is required', () => {
8190
const scopeConfig = choicesFactory({
82-
'scope-empty': [2, 'always', undefined],
91+
'scope-empty': [2, 'always'],
8392
});
8493

8594
expect(scopeConfig).toEqual([{ name: ':skip', value: '' }]);
8695
});
8796

8897
it('should not allow skipping scope when is required', () => {
8998
const scopeConfig = choicesFactory({
90-
'scope-empty': [2, 'never', undefined],
99+
'scope-empty': [2, 'never'],
91100
});
92101

93102
expect(scopeConfig).not.toContainEqual({ name: ':skip', value: '' });
@@ -96,7 +105,7 @@ describe('scopeMaker', () => {
96105

97106
it('should allow skipping scope when "scope-empty" severity is "warn"', () => {
98107
const scopeConfig = choicesFactory({
99-
'scope-empty': [1, 'always', undefined],
108+
'scope-empty': [1, 'always'],
100109
});
101110

102111
expect(scopeConfig).toContainEqual({ name: ':skip', value: '' });
@@ -109,9 +118,9 @@ describe('scopeMaker', () => {
109118
});
110119

111120
describe('filterFactory', () => {
112-
test.each<[Rule<Case>, string, string]>([
113-
[[Level.Error, 'always', 'camel-case'], 'FOO_BAR', 'fooBar'],
114-
[[Level.Error, 'never', 'camel-case'], 'FOO_BAR', 'FOO_BAR'],
121+
test.each<[RuleConfig<RuleConfigQuality.Qualified, TargetCaseType>, string, string]>([
122+
[[RuleConfigSeverity.Error, 'always', 'camel-case'], 'FOO_BAR', 'fooBar'],
123+
[[RuleConfigSeverity.Error, 'never', 'camel-case'], 'FOO_BAR', 'FOO_BAR'],
115124
])('should return case filtered string rule: %s, value: %s, expected: %s', (rule, value, expected) => {
116125
const rules = { 'scope-case': rule };
117126
const fixture = filterFactory(rules);

0 commit comments

Comments
 (0)