|
| 1 | +import lint from '@commitlint/lint'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +import cspellPlugin from '../src/index.js'; |
| 5 | + |
| 6 | +import type { CspellRuleName, PluginRulesConfig } from '../src/types.js'; |
| 7 | +import type { QualifiedRules } from '@commitlint/types'; |
| 8 | + |
| 9 | +// cspell:ignore speling |
| 10 | + |
| 11 | +describe('Plugin works with commitlint', () => { |
| 12 | + const rules = { |
| 13 | + 'cspell/type': [2, 'always'], |
| 14 | + 'cspell/scope': [2, 'always'], |
| 15 | + 'cspell/subject': [2, 'always'], |
| 16 | + 'cspell/header': [2, 'always'], |
| 17 | + 'cspell/body': [2, 'always'], |
| 18 | + 'cspell/footer': [2, 'always'], |
| 19 | + } satisfies Partial<PluginRulesConfig>; |
| 20 | + |
| 21 | + const getRules = (...keys: (keyof PluginRulesConfig)[]): Partial<QualifiedRules> => |
| 22 | + Object.fromEntries(keys.map((key) => [key, rules[key]])); |
| 23 | + |
| 24 | + it.each([ |
| 25 | + ['cspell/type', 'speling: Bad type'], |
| 26 | + ['cspell/scope', 'chore(speling): Bad scope'], |
| 27 | + ['cspell/subject', 'chore: Bad subject speling'], |
| 28 | + ['cspell/header', 'Bad header speling'], |
| 29 | + ['cspell/body', 'chore(scope): subject\nBad body speling'], |
| 30 | + ['cspell/footer', 'chore(scope): subject\nBody\nBREAKING CHANGE: Bad footer speling'], |
| 31 | + ] satisfies [rule: CspellRuleName, message: string][])('uses %s rule to lint %j', async (rule, message) => { |
| 32 | + const { valid, errors } = await lint(message, getRules(rule), { |
| 33 | + plugins: { |
| 34 | + cspell: cspellPlugin, |
| 35 | + }, |
| 36 | + }); |
| 37 | + |
| 38 | + expect(valid).toBe(false); |
| 39 | + expect(errors).toEqual( |
| 40 | + expect.arrayContaining([ |
| 41 | + expect.objectContaining({ |
| 42 | + message: expect.stringContaining('speling'), |
| 43 | + }), |
| 44 | + ]), |
| 45 | + ); |
| 46 | + }); |
| 47 | +}); |
0 commit comments