Skip to content

Commit

Permalink
test: add end-to-end test
Browse files Browse the repository at this point in the history
This test uses the plugin with @commitlint/load to verify that the rules created in this plugin can be used with commitlint.
  • Loading branch information
jdbruijn committed Sep 16, 2020
1 parent d4f8c32 commit 3de942c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
coverageDirectory: 'coverage',
coverageReporters: ['cobertura', 'lcov', 'text'],
preset: 'ts-jest',
roots: ['<rootDir>/src'],
roots: ['<rootDir>/src', '<rootDir>/test'],
};
45 changes: 45 additions & 0 deletions test/end-to-end.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as plugin from '../src';
import { Plugin, RuleOutcome, RulesConfig } from '@commitlint/types';
import { describe, expect, it } from '@jest/globals';
import lint from '@commitlint/lint';
import load from '@commitlint/load';

describe('commitlint plugin function rules', () => {
it('provides rules that can be used with commitlint', async () => {
for await (const rule of Object.keys(plugin.rules)) {
const results: RuleOutcome[] = [
[true],
[false, `error message from ${rule}`],
];
for await (const result of results) {
const rules: Partial<RulesConfig> = {};
rules[rule] = [
2,
'always',
() => {
return result;
},
];

const config = await load({
plugins: [plugin as Plugin],
rules,
});

const report = await lint('chore: basic commit message', config.rules, {
plugins: {
'function-rules': plugin as Plugin,
},
});

expect(report.valid).toEqual(result[0]);
if (result[1] !== undefined) {
expect(report.warnings).toHaveLength(0);
expect(report.errors).toHaveLength(1);
expect(report.errors[0].name).toEqual(rule);
expect(report.errors[0].message).toEqual(result[1]);
}
}
}
});
});
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"strict": true,
"target": "ES2020"
},
"exclude": ["node_modules", "**/*.test.ts"],
"include": ["src/**/*.ts"]
"exclude": ["node_modules"],
"include": ["src/**/*.ts", "test/**/*.ts"]
}

0 comments on commit 3de942c

Please sign in to comment.