Skip to content

Commit 3de942c

Browse files
committed
test: add end-to-end test
This test uses the plugin with @commitlint/load to verify that the rules created in this plugin can be used with commitlint.
1 parent d4f8c32 commit 3de942c

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ module.exports = {
44
coverageDirectory: 'coverage',
55
coverageReporters: ['cobertura', 'lcov', 'text'],
66
preset: 'ts-jest',
7-
roots: ['<rootDir>/src'],
7+
roots: ['<rootDir>/src', '<rootDir>/test'],
88
};

test/end-to-end.test.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as plugin from '../src';
2+
import { Plugin, RuleOutcome, RulesConfig } from '@commitlint/types';
3+
import { describe, expect, it } from '@jest/globals';
4+
import lint from '@commitlint/lint';
5+
import load from '@commitlint/load';
6+
7+
describe('commitlint plugin function rules', () => {
8+
it('provides rules that can be used with commitlint', async () => {
9+
for await (const rule of Object.keys(plugin.rules)) {
10+
const results: RuleOutcome[] = [
11+
[true],
12+
[false, `error message from ${rule}`],
13+
];
14+
for await (const result of results) {
15+
const rules: Partial<RulesConfig> = {};
16+
rules[rule] = [
17+
2,
18+
'always',
19+
() => {
20+
return result;
21+
},
22+
];
23+
24+
const config = await load({
25+
plugins: [plugin as Plugin],
26+
rules,
27+
});
28+
29+
const report = await lint('chore: basic commit message', config.rules, {
30+
plugins: {
31+
'function-rules': plugin as Plugin,
32+
},
33+
});
34+
35+
expect(report.valid).toEqual(result[0]);
36+
if (result[1] !== undefined) {
37+
expect(report.warnings).toHaveLength(0);
38+
expect(report.errors).toHaveLength(1);
39+
expect(report.errors[0].name).toEqual(rule);
40+
expect(report.errors[0].message).toEqual(result[1]);
41+
}
42+
}
43+
}
44+
});
45+
});

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"strict": true,
88
"target": "ES2020"
99
},
10-
"exclude": ["node_modules", "**/*.test.ts"],
11-
"include": ["src/**/*.ts"]
10+
"exclude": ["node_modules"],
11+
"include": ["src/**/*.ts", "test/**/*.ts"]
1212
}

0 commit comments

Comments
 (0)