master
1import { describe, it, expect } from 'vitest'
2import { splitWithoutTooFrequentWords } from './favorite-word.js'
3
4describe('favorite-word', () => {
5 // prettier-ignore
6 describe('ignore conventional commit prefixes', () => {
7 const prefixes = [
8 'BREAKING CHANGE',
9 'build',
10 'chore',
11 'ci',
12 'docs',
13 'feat',
14 'fix',
15 'perf',
16 'refactor',
17 'revert',
18 'style',
19 'test',
20 ]
21 for (const prefix of prefixes) {
22 describe(`"${prefix}"`, () => {
23 it(`ignores "${prefix}" at the beginning of the message`, () => {
24 expect(splitWithoutTooFrequentWords(`${prefix}: hello world`)).toEqual(['hello', 'world'])
25 })
26 it(`ignores "${prefix}" without space after it`, () => {
27 expect(splitWithoutTooFrequentWords(`${prefix}:hello world`)).toEqual(['hello', 'world'])
28 })
29 it(`ignores "${prefix}" with exclamation mark`, () => {
30 expect(splitWithoutTooFrequentWords(`${prefix}!: hello world`)).toEqual(['hello', 'world'])
31 })
32 it(`ignores "${prefix}" with scope`, () => {
33 expect(splitWithoutTooFrequentWords(`${prefix}(world): hello`)).toEqual(['hello'])
34 })
35 it(`don't ignore "${prefix}" if not at the beginning`, () => {
36 const expectedPrefix = `${prefix}:`.toLowerCase().split(' ')
37 expectedPrefix.unshift('hello')
38 expect(splitWithoutTooFrequentWords(`hello ${prefix}:`)).toEqual(expectedPrefix)
39 })
40 })
41 }
42 it(`don't ignore fake prefix`, () => {
43 expect(splitWithoutTooFrequentWords(`fake: hello world`)).toEqual(['fake:', 'hello', 'world'])
44 })
45 })
46})