|
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]; |
3 | 4 |
|
4 | 5 | const commitLint = async (message) => { |
5 | 6 | const preset = await require(parserPreset)(); |
@@ -40,8 +41,7 @@ const messages = { |
40 | 41 | const errors = { |
41 | 42 | typeEnum: { |
42 | 43 | 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(', ')}]`, |
45 | 45 | name: 'type-enum', |
46 | 46 | valid: false, |
47 | 47 | }, |
@@ -112,11 +112,25 @@ const warnings = { |
112 | 112 | }, |
113 | 113 | }; |
114 | 114 |
|
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 | + }); |
117 | 127 |
|
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 | + }); |
120 | 134 | }); |
121 | 135 |
|
122 | 136 | test('type-case', async () => { |
|
0 commit comments