forked from conventional-changelog/commitlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreferences-empty.test.ts
86 lines (73 loc) · 2.55 KB
/
references-empty.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
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
85
86
import parse from '@commitlint/parse';
import {referencesEmpty} from './references-empty';
const preset = require('conventional-changelog-angular');
const messages = {
plain: 'foo: bar',
comment: 'foo: baz\n#1 Comment',
reference: '#comment\nfoo: baz \nCloses #1',
references: '#comment\nfoo: bar \nCloses #1, #2, #3',
prefix: 'bar REF-1234',
};
const opts = (async () => {
const o = await preset();
o.parserOpts.commentChar = '#';
return o;
})();
const parsed = {
plain: (async () =>
parse(messages.plain, undefined, (await opts).parserOpts))(),
comment: (async () =>
parse(messages.comment, undefined, (await opts).parserOpts))(),
reference: (async () =>
parse(messages.reference, undefined, (await opts).parserOpts))(),
references: (async () =>
parse(messages.references, undefined, (await opts).parserOpts))(),
prefix: parse(messages.prefix, undefined, {
issuePrefixes: ['REF-'],
}),
};
test('defaults to never and fails for plain', async () => {
const [actual] = referencesEmpty(await parsed.plain);
const expected = false;
expect(actual).toEqual(expected);
});
test('defaults to never and succeeds for reference', async () => {
const [actual] = referencesEmpty(await parsed.reference);
const expected = true;
expect(actual).toEqual(expected);
});
test('fails for comment with never', async () => {
const [actual] = referencesEmpty(await parsed.comment, 'never');
const expected = false;
expect(actual).toEqual(expected);
});
test('succeeds for comment with always', async () => {
const [actual] = referencesEmpty(await parsed.comment, 'always');
const expected = true;
expect(actual).toEqual(expected);
});
test('succeeds for reference with never', async () => {
const [actual] = referencesEmpty(await parsed.reference, 'never');
const expected = true;
expect(actual).toEqual(expected);
});
test('fails for reference with always', async () => {
const [actual] = referencesEmpty(await parsed.reference, 'always');
const expected = false;
expect(actual).toEqual(expected);
});
test('succeeds for references with never', async () => {
const [actual] = referencesEmpty(await parsed.references, 'never');
const expected = true;
expect(actual).toEqual(expected);
});
test('fails for references with always', async () => {
const [actual] = referencesEmpty(await parsed.references, 'always');
const expected = false;
expect(actual).toEqual(expected);
});
test('succeeds for custom references with always', async () => {
const [actual] = referencesEmpty(await parsed.prefix, 'never');
const expected = true;
expect(actual).toEqual(expected);
});