forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
50 lines (40 loc) · 1.28 KB
/
index.test.ts
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
import {test, expect} from 'vitest';
import fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';
import {globSync} from 'glob';
import rules from './index.js';
const __dirname = path.resolve(fileURLToPath(import.meta.url), '..');
test('exports all rules', () => {
const expected = _glob('*.ts').sort();
const actual = Object.keys(rules).sort();
expect(actual).toEqual(expected);
});
test('rules export functions', () => {
const actual = Object.values(rules);
expect(actual.every((rule) => typeof rule === 'function')).toBe(true);
});
test('all rules are present in documentation', () => {
const file = fs.readFileSync(
path.join(__dirname, '../../../docs/reference/rules.md'),
'utf-8'
);
const results = file
.split(/(\n|\r)/)
.filter((s) => s.startsWith('##') && !s.includes('`deprecated`'))
.map((s) => s.replace('## ', ''));
expect(Object.keys(rules)).toEqual(expect.arrayContaining(results));
});
function _glob(pattern: string) {
const files = globSync(pattern, {
ignore: ['**/index.ts', '**/*.test.ts'],
cwd: __dirname,
});
return files.map(relative).map(toExport);
}
function relative(filePath: string) {
return path.relative(__dirname, filePath);
}
function toExport(fileName: string) {
return path.basename(fileName, path.extname(fileName));
}