Skip to content

test: add simple tests for configs #921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`rules type-enum empty 1`] = `
Array [
true,
"type must be one of [build, ci, docs, feat, fix, perf, refactor, revert, style, test]",
]
`;

exports[`rules type-enum filled 1`] = `
Array [
true,
"type must be one of [build, ci, docs, feat, fix, perf, refactor, revert, style, test]",
]
`;

exports[`rules type-enum simple 1`] = `
Array [
true,
"type must be one of [build, ci, docs, feat, fix, perf, refactor, revert, style, test]",
]
`;
26 changes: 26 additions & 0 deletions @commitlint/config-angular-type-enum/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import config from '.';
import rules from '@commitlint/rules';
import parse from '@commitlint/parse';

const messages = Object.entries({
simple: 'test: subject',
empty: 'test: subject\nbody',
filled: 'test: subject\nBREAKING CHANGE: something important'
});
const configRules = Object.entries(config.rules);

it('should have correct structure', () => {
expect(config).toMatchObject({
rules: expect.any(Object)
});
});

describe('rules', () => {
describe.each(configRules)('%s', (name, options) => {
it.each(messages)('%s', async (type, message) => {
expect(
rules[name](await parse(message), ...options.slice(1))
).toMatchSnapshot();
});
});
});
9 changes: 8 additions & 1 deletion @commitlint/config-angular-type-enum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
"url": "https://github.com/conventional-changelog/commitlint/issues"
},
"homepage": "https://github.com/conventional-changelog/commitlint#readme",
"babel": {
"presets": [
"babel-preset-commitlint"
]
},
"devDependencies": {
"@commitlint/utils": "^8.3.4"
"@commitlint/utils": "^8.3.4",
"@commitlint/rules": "^8.3.4",
"@commitlint/parse": "^8.3.4"
}
}
204 changes: 204 additions & 0 deletions @commitlint/config-angular/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`rules body-leading-blank empty 1`] = `
Array [
false,
"body must have leading blank line",
]
`;

exports[`rules body-leading-blank filled 1`] = `
Array [
true,
]
`;

exports[`rules body-leading-blank simple 1`] = `
Array [
true,
]
`;

exports[`rules footer-leading-blank empty 1`] = `
Array [
true,
]
`;

exports[`rules footer-leading-blank filled 1`] = `
Array [
false,
"footer must have leading blank line",
]
`;

exports[`rules footer-leading-blank simple 1`] = `
Array [
true,
]
`;

exports[`rules header-max-length empty 1`] = `
Array [
true,
"header must not be longer than 72 characters, current length is 13",
]
`;

exports[`rules header-max-length filled 1`] = `
Array [
true,
"header must not be longer than 72 characters, current length is 13",
]
`;

exports[`rules header-max-length simple 1`] = `
Array [
true,
"header must not be longer than 72 characters, current length is 13",
]
`;

exports[`rules scope-case empty 1`] = `
Array [
true,
]
`;

exports[`rules scope-case filled 1`] = `
Array [
true,
]
`;

exports[`rules scope-case simple 1`] = `
Array [
true,
]
`;

exports[`rules subject-case empty 1`] = `
Array [
true,
"subject must not be sentence-case, start-case, pascal-case, upper-case",
]
`;

exports[`rules subject-case filled 1`] = `
Array [
true,
"subject must not be sentence-case, start-case, pascal-case, upper-case",
]
`;

exports[`rules subject-case simple 1`] = `
Array [
true,
"subject must not be sentence-case, start-case, pascal-case, upper-case",
]
`;

exports[`rules subject-empty empty 1`] = `
Array [
true,
"subject may not be empty",
]
`;

exports[`rules subject-empty filled 1`] = `
Array [
true,
"subject may not be empty",
]
`;

exports[`rules subject-empty simple 1`] = `
Array [
true,
"subject may not be empty",
]
`;

exports[`rules subject-full-stop empty 1`] = `
Array [
true,
"subject may not end with full stop",
]
`;

exports[`rules subject-full-stop filled 1`] = `
Array [
true,
"subject may not end with full stop",
]
`;

exports[`rules subject-full-stop simple 1`] = `
Array [
true,
"subject may not end with full stop",
]
`;

exports[`rules type-case empty 1`] = `
Array [
true,
"type must be lower-case",
]
`;

exports[`rules type-case filled 1`] = `
Array [
true,
"type must be lower-case",
]
`;

exports[`rules type-case simple 1`] = `
Array [
true,
"type must be lower-case",
]
`;

exports[`rules type-empty empty 1`] = `
Array [
true,
"type may not be empty",
]
`;

exports[`rules type-empty filled 1`] = `
Array [
true,
"type may not be empty",
]
`;

exports[`rules type-empty simple 1`] = `
Array [
true,
"type may not be empty",
]
`;

exports[`rules type-enum empty 1`] = `
Array [
true,
"type must be one of [build, ci, docs, feat, fix, perf, refactor, revert, style, test]",
]
`;

exports[`rules type-enum filled 1`] = `
Array [
true,
"type must be one of [build, ci, docs, feat, fix, perf, refactor, revert, style, test]",
]
`;

exports[`rules type-enum simple 1`] = `
Array [
true,
"type must be one of [build, ci, docs, feat, fix, perf, refactor, revert, style, test]",
]
`;
26 changes: 26 additions & 0 deletions @commitlint/config-angular/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import config from '.';
import rules from '@commitlint/rules';
import parse from '@commitlint/parse';

const messages = Object.entries({
simple: 'test: subject',
empty: 'test: subject\nbody',
filled: 'test: subject\nBREAKING CHANGE: something important'
});
const configRules = Object.entries(config.rules);

it('should have correct structure', () => {
expect(config).toMatchObject({
rules: expect.any(Object)
});
});

describe('rules', () => {
describe.each(configRules)('%s', (name, options) => {
it.each(messages)('%s', async (type, message) => {
expect(
rules[name](await parse(message), ...options.slice(1))
).toMatchSnapshot();
});
});
});
9 changes: 8 additions & 1 deletion @commitlint/config-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@
"url": "https://github.com/conventional-changelog/commitlint/issues"
},
"homepage": "https://github.com/conventional-changelog/commitlint#readme",
"babel": {
"presets": [
"babel-preset-commitlint"
]
},
"devDependencies": {
"@commitlint/utils": "^8.3.4"
"@commitlint/utils": "^8.3.4",
"@commitlint/rules": "^8.3.4",
"@commitlint/parse": "^8.3.4"
},
"dependencies": {
"@commitlint/config-angular-type-enum": "^8.3.4"
Expand Down
Loading