|
| 1 | +// cSpell:ignore Speling |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +import { checkSpelling, makeMessage, makeRule } from '../src/utils.js'; |
| 5 | + |
| 6 | +import type { Commit } from '../src/types.js'; |
| 7 | + |
| 8 | +describe('checkSpelling()', () => { |
| 9 | + it('Returns spelling issues', async () => { |
| 10 | + await expect(checkSpelling('Speling')).resolves.toEqual([ |
| 11 | + expect.objectContaining({ |
| 12 | + text: 'Speling', |
| 13 | + }), |
| 14 | + ]); |
| 15 | + |
| 16 | + await expect(checkSpelling(null)).resolves.toHaveLength(0); |
| 17 | + await expect(checkSpelling(undefined)).resolves.toHaveLength(0); |
| 18 | + }); |
| 19 | +}); |
| 20 | + |
| 21 | +describe('makeMessage()', () => { |
| 22 | + it('Returns an error message or undefined', () => { |
| 23 | + expect(makeMessage('subject', [])).toBeUndefined(); |
| 24 | + |
| 25 | + expect( |
| 26 | + makeMessage('subject', [ |
| 27 | + { |
| 28 | + isFlagged: false, |
| 29 | + isFound: false, |
| 30 | + length: 7, |
| 31 | + line: { |
| 32 | + offset: 0, |
| 33 | + text: 'Speling', |
| 34 | + }, |
| 35 | + offset: 0, |
| 36 | + text: 'Speling', |
| 37 | + }, |
| 38 | + ]), |
| 39 | + ).toEqual(expect.stringContaining('Speling')); |
| 40 | + }); |
| 41 | +}); |
| 42 | + |
| 43 | +describe('makeRule()', () => { |
| 44 | + it('Returns a commitlint rule function', async () => { |
| 45 | + const ruleFn = makeRule('subject'); |
| 46 | + |
| 47 | + expect(ruleFn).instanceOf(Function); |
| 48 | + |
| 49 | + await expect( |
| 50 | + ruleFn({ |
| 51 | + merge: 'merge', |
| 52 | + header: 'header', |
| 53 | + body: 'body', |
| 54 | + footer: 'footer', |
| 55 | + revert: null, |
| 56 | + scope: 'testing', |
| 57 | + subject: 'subject', |
| 58 | + notes: [], |
| 59 | + references: [], |
| 60 | + mentions: [], |
| 61 | + } as unknown as Commit), |
| 62 | + ).resolves.toEqual([true, undefined]); |
| 63 | + |
| 64 | + await expect( |
| 65 | + ruleFn({ |
| 66 | + merge: 'merge', |
| 67 | + header: 'header', |
| 68 | + body: 'body', |
| 69 | + footer: 'footer', |
| 70 | + revert: null, |
| 71 | + scope: 'testing', |
| 72 | + subject: 'Speling', |
| 73 | + notes: [], |
| 74 | + references: [], |
| 75 | + mentions: [], |
| 76 | + } as unknown as Commit), |
| 77 | + ).resolves.toEqual([false, expect.stringContaining('Speling')]); |
| 78 | + }); |
| 79 | +}); |
0 commit comments