Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { lint } from './utils'; | ||
|
||
describe('invalid commit', () => { | ||
it('$ chore(scope): test -> without gitmoji', async () => { | ||
const { valid, errors } = await lint('chore(scope): test'); | ||
|
||
expect(valid).toBeFalsy(); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].name).toBe('start-with-gitmoji'); | ||
}); | ||
|
||
it('$ :start: chore(scope): test -> invalid gitmoji', async () => { | ||
const { valid, errors } = await lint(':start: chore(scope): test'); | ||
|
||
expect(valid).toBeFalsy(); | ||
expect(errors).toHaveLength(1); | ||
expect(errors[0].name).toBe('start-with-gitmoji'); | ||
expect(errors[0].message).toBe( | ||
':start: is not in the correct gitmoji list, please check the emoji code on https://gitmoji.dev/.', | ||
); | ||
}); | ||
|
||
it('$ hello :test: test -> 3 error', async () => { | ||
const { valid, errors } = await lint('hello :test: test'); | ||
|
||
expect(valid).toBeFalsy(); | ||
expect(errors).toHaveLength(3); | ||
}); | ||
|
||
it('$ :start:test: test -> 3 error', async () => { | ||
const { valid, errors } = await lint(':start:test: test'); | ||
|
||
expect(valid).toBeFalsy(); | ||
expect(errors).toHaveLength(3); | ||
}); | ||
}); | ||
|
||
describe('valid commit', () => { | ||
it('$ :white_check_mark: test: test -> passed', async () => { | ||
const { valid } = await lint(':white_check_mark: test: test'); | ||
|
||
expect(valid).toBeTruthy(); | ||
}); | ||
|
||
it('$ :sparkles: feat(web): add new feat -> passed', async () => { | ||
const { valid } = await lint(':sparkles: feat(web): add new feat'); | ||
|
||
expect(valid).toBeTruthy(); | ||
}); | ||
|
||
it('$ :green_heart: ci: fix ci -> passed', async () => { | ||
const { valid } = await lint(':green_heart: ci: fix ci'); | ||
|
||
expect(valid).toBeTruthy(); | ||
}); | ||
|
||
it('$ :memo: docs: update document #123 -> passed', async () => { | ||
const { valid } = await lint(':memo: docs: update document #123'); | ||
|
||
expect(valid).toBeTruthy(); | ||
}); | ||
it('$ :memo: docs: update README.md -> passed', async () => { | ||
const { valid } = await lint(':memo: docs: update README.md'); | ||
|
||
expect(valid).toBeTruthy(); | ||
}); | ||
it('$ :lipstick: style(typography): 优化信息块和内联代码样式 -> passed', async () => { | ||
const { valid } = await lint(':lipstick: style(typography): 优化信息块和内联代码样式'); | ||
|
||
expect(valid).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { default as commitlint } from "@commitlint/lint"; | ||
import config from "../src"; | ||
|
||
export const lint = (input) => | ||
commitlint(input, config.rules, config.parserPreset); |