forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
35 lines (30 loc) · 936 Bytes
/
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
import path from 'path';
import glob from 'glob';
import camelCase from 'lodash.camelcase';
import * as ensure from '.';
test('exports all checkers', async () => {
const ignore = ['types'];
const expected = _glob('*.ts')
.map((f) => camelCase(f))
.sort()
.filter((item) => !ignore.includes(item));
const actual = Object.keys(ensure).sort();
expect(actual).toEqual(expected);
});
test('rules export functions', () => {
const actual = Object.values(ensure);
expect(actual.every((rule) => typeof rule === 'function')).toBe(true);
});
function _glob(pattern: string): string[] {
const files = glob.sync(pattern, {
ignore: ['**/index.ts', '**/*.test.ts'],
cwd: __dirname,
});
return files.map(relative).map(toExport);
}
function relative(filePath: string): string {
return path.relative(__dirname, filePath);
}
function toExport(fileName: string): string {
return path.basename(fileName, path.extname(fileName));
}