Skip to content

Commit

Permalink
🐛 fix(config-monorepo): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jan 24, 2021
1 parent a3569c9 commit fc4b85f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
72 changes: 72 additions & 0 deletions packages/config-monorepo/test/index.test.ts
@@ -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();
});
});
5 changes: 5 additions & 0 deletions packages/config-monorepo/test/utils.ts
@@ -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);

0 comments on commit fc4b85f

Please sign in to comment.