-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.spec.js
84 lines (71 loc) · 1.95 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const { default: load } = require('@commitlint/load');
const { default: lint } = require('@commitlint/lint');
const commitlintConfigFile = require('./commitlint.config');
let commitlintConfig = {};
async function lintMessage(message) {
return await lint(
message,
commitlintConfig.rawRulesConfig,
commitlintConfig.rawOpts,
);
}
beforeAll(async () => {
const result = await load(commitlintConfigFile);
commitlintConfig = {
rawRulesConfig: result.rules,
rawOpts: result.parserPreset ? { parserOpts: result.parserPreset.parserOpts } : {},
};
});
describe('Commitlint Configuration', () => {
test('Should correctly validate type', async () => {
const allowedTypes = [
'build',
'ci',
'chore',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
'bogusType',
];
const lintPromises = allowedTypes.map((type) => lintMessage(`${type}: some message`));
const lintResults = await Promise.all(lintPromises);
lintResults.forEach((lintResult, index) => {
if (index < lintResults.length - 1) {
expect(lintResult.valid).toBe(true);
} else {
expect(lintResult.valid).toBe(false);
}
});
});
test('Should correctly validate scope', async () => {
const allowedScopes = [
'scope',
'SomeScope',
'multiple/scopes',
];
const lintPromises = allowedScopes.map((scope) => lintMessage(`fix(${scope}): some message`));
const lintResults = await Promise.all(lintPromises);
lintResults.forEach((lintResult) => {
expect(lintResult.valid).toBe(true);
});
});
test('Should correctly validate subject', async () => {
const allowedSubjects = [
'Did some things',
'Word',
'herro',
'fixed that THING',
];
const lintPromises = allowedSubjects.map((subject) => lintMessage(`fix(scope): ${subject}`));
const lintResults = await Promise.all(lintPromises);
lintResults.forEach((lintResult) => {
console.log(lintResult);
expect(lintResult.valid).toBe(true);
})
});
})