forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-parser-opts.test.ts
55 lines (44 loc) · 1.28 KB
/
load-parser-opts.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
51
52
53
54
55
import {loadParserOpts} from './load-parser-opts';
test('handles a plain preset', async () => {
const preset = {
parserOpts: {},
};
expect(await loadParserOpts(preset)).toEqual(preset);
});
test('handles primitive values', async () => {
expect(await loadParserOpts('')).toEqual(undefined);
expect(await loadParserOpts(undefined)).toEqual(undefined);
});
test('handles an object without any parserOpts', async () => {
const preset = {};
expect(await loadParserOpts(preset)).toEqual(preset);
});
test('handles nested parserOpts', async () => {
const opts = {a: 4};
// plain nested parserOpts
let loaded = await loadParserOpts({
parserOpts: {
parserOpts: opts,
},
});
expect(loaded).toHaveProperty('parserOpts', opts);
// async nested parserOpts
loaded = await loadParserOpts({
parserOpts: Promise.resolve({
parserOpts: opts,
}),
});
expect(loaded).toHaveProperty('parserOpts', opts);
});
test('runs a sync function which returns the preset', async () => {
const preset = {};
const fn = () => preset;
const opts = await loadParserOpts(fn);
expect(opts).toEqual(preset);
});
test('runs an async function which returns the preset', async () => {
const preset = {};
const fn = async () => preset;
const opts = await loadParserOpts(fn);
expect(opts).toEqual(preset);
});