-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathtrailer-exists.test.ts
136 lines (112 loc) Β· 3.3 KB
/
trailer-exists.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import parse from '@commitlint/parse';
import {trailerExists} from './trailer-exists';
const messages = {
empty: 'test:\n',
with: `test: subject\n\nbody\n\nfooter\n\nSigned-off-by:\n\n`,
without: `test: subject\n\nbody\n\nfooter\n\n`,
inSubject: `test: subject Signed-off-by:\n\nbody\n\nfooter\n\n`,
inBody: `test: subject\n\nbody Signed-off-by:\n\nfooter\n\n`,
withSignoffAndNoise: `test: subject
message body
Arbitrary-trailer:
Signed-off-by:
Another-arbitrary-trailer:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
`,
};
const parsed = {
empty: parse(messages.empty),
with: parse(messages.with),
without: parse(messages.without),
inSubject: parse(messages.inSubject),
inBody: parse(messages.inBody),
withSignoffAndNoise: parse(messages.withSignoffAndNoise),
};
test('empty against "always trailer-exists" should fail', async () => {
const [actual] = trailerExists(
await parsed.empty,
'always',
'Signed-off-by:'
);
const expected = false;
expect(actual).toEqual(expected);
});
test('empty against "never trailer-exists" should succeed', async () => {
const [actual] = trailerExists(await parsed.empty, 'never', 'Signed-off-by:');
const expected = true;
expect(actual).toEqual(expected);
});
test('with against "always trailer-exists" should succeed', async () => {
const [actual] = trailerExists(await parsed.with, 'always', 'Signed-off-by:');
const expected = true;
expect(actual).toEqual(expected);
});
test('with against "never trailer-exists" should fail', async () => {
const [actual] = trailerExists(await parsed.with, 'never', 'Signed-off-by:');
const expected = false;
expect(actual).toEqual(expected);
});
test('without against "always trailer-exists" should fail', async () => {
const [actual] = trailerExists(
await parsed.without,
'always',
'Signed-off-by:'
);
const expected = false;
expect(actual).toEqual(expected);
});
test('without against "never trailer-exists" should succeed', async () => {
const [actual] = trailerExists(
await parsed.without,
'never',
'Signed-off-by:'
);
const expected = true;
expect(actual).toEqual(expected);
});
test('comments and other trailers should be ignored', async () => {
const [actual] = trailerExists(
await parsed.withSignoffAndNoise,
'always',
'Signed-off-by:'
);
const expected = true;
expect(actual).toEqual(expected);
});
test('inSubject against "always trailer-exists" should fail', async () => {
const [actual] = trailerExists(
await parsed.inSubject,
'always',
'Signed-off-by:'
);
const expected = false;
expect(actual).toEqual(expected);
});
test('inSubject against "never trailer-exists" should succeed', async () => {
const [actual] = trailerExists(
await parsed.inSubject,
'never',
'Signed-off-by:'
);
const expected = true;
expect(actual).toEqual(expected);
});
test('inBody against "always trailer-exists" should fail', async () => {
const [actual] = trailerExists(
await parsed.inBody,
'always',
'Signed-off-by:'
);
const expected = false;
expect(actual).toEqual(expected);
});
test('inBody against "never trailer-exists" should succeed', async () => {
const [actual] = trailerExists(
await parsed.inBody,
'never',
'Signed-off-by:'
);
const expected = true;
expect(actual).toEqual(expected);
});