Skip to content

Commit 89709d5

Browse files
committed
test: enable and improve tests
1 parent 046c0c5 commit 89709d5

File tree

3 files changed

+4229
-43
lines changed

3 files changed

+4229
-43
lines changed

index.test.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import lint from '@commitlint/lint';
2-
import {rules, parserPreset} from '.';
1+
const lint = require('@commitlint/lint').default;
2+
const { parserPreset, rules } = require('.');
3+
const types = rules['type-enum'][2];
34

45
const commitLint = async (message) => {
56
const preset = await require(parserPreset)();
@@ -40,8 +41,7 @@ const messages = {
4041
const errors = {
4142
typeEnum: {
4243
level: 2,
43-
message:
44-
'type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]',
44+
message: `type must be one of [${types.join(', ')}]`,
4545
name: 'type-enum',
4646
valid: false,
4747
},
@@ -112,11 +112,25 @@ const warnings = {
112112
},
113113
};
114114

115-
test('type-enum', async () => {
116-
const result = await commitLint(messages.invalidTypeEnum);
115+
describe('type-enum', () => {
116+
it('should accept valid commit types', async () => {
117+
const validInputs = await Promise.all(
118+
types.map((type) => commitLint(`${type}: some message`))
119+
);
120+
121+
validInputs.forEach((result) => {
122+
expect(result.valid).toBe(true);
123+
expect(result.errors).toEqual([]);
124+
expect(result.warnings).toEqual([]);
125+
});
126+
});
117127

118-
expect(result.valid).toBe(false);
119-
expect(result.errors).toEqual([errors.typeEnum]);
128+
it('should reject invalid commit types', async () => {
129+
const invalidInput = await commitLint(messages.invalidTypeEnum);
130+
131+
expect(invalidInput.valid).toBe(false);
132+
expect(invalidInput.errors).toEqual([errors.typeEnum]);
133+
});
120134
});
121135

122136
test('type-case', async () => {

0 commit comments

Comments
 (0)