Skip to content

Commit

Permalink
test: enable and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Jun 3, 2023
1 parent 046c0c5 commit 89709d5
Show file tree
Hide file tree
Showing 3 changed files with 4,229 additions and 43 deletions.
30 changes: 22 additions & 8 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import lint from '@commitlint/lint';
import {rules, parserPreset} from '.';
const lint = require('@commitlint/lint').default;
const { parserPreset, rules } = require('.');
const types = rules['type-enum'][2];

const commitLint = async (message) => {
const preset = await require(parserPreset)();
Expand Down Expand Up @@ -40,8 +41,7 @@ const messages = {
const errors = {
typeEnum: {
level: 2,
message:
'type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]',
message: `type must be one of [${types.join(', ')}]`,
name: 'type-enum',
valid: false,
},
Expand Down Expand Up @@ -112,11 +112,25 @@ const warnings = {
},
};

test('type-enum', async () => {
const result = await commitLint(messages.invalidTypeEnum);
describe('type-enum', () => {
it('should accept valid commit types', async () => {
const validInputs = await Promise.all(
types.map((type) => commitLint(`${type}: some message`))
);

validInputs.forEach((result) => {
expect(result.valid).toBe(true);
expect(result.errors).toEqual([]);
expect(result.warnings).toEqual([]);
});
});

expect(result.valid).toBe(false);
expect(result.errors).toEqual([errors.typeEnum]);
it('should reject invalid commit types', async () => {
const invalidInput = await commitLint(messages.invalidTypeEnum);

expect(invalidInput.valid).toBe(false);
expect(invalidInput.errors).toEqual([errors.typeEnum]);
});
});

test('type-case', async () => {
Expand Down
Loading

0 comments on commit 89709d5

Please sign in to comment.