forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
31 lines (26 loc) · 875 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
import path from 'path';
import globby from 'globby';
import {camelCase, values} from 'lodash';
import * as ensure from '.';
test('exports all checkers', async () => {
const expected = (await glob('*.ts')).map(f => camelCase(f)).sort();
const actual = Object.keys(ensure).sort();
expect(actual).toEqual(expected);
});
test('rules export functions', () => {
const actual = values(ensure);
expect(actual.every(rule => typeof rule === 'function')).toBe(true);
});
async function glob(pattern: string): Promise<string[]> {
const files = await globby(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));
}