-
Notifications
You must be signed in to change notification settings - Fork 915
/
Copy pathsigned-off-by.test.ts
111 lines (95 loc) · 3.2 KB
/
signed-off-by.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
import {test, expect} from 'vitest';
import parse from '@commitlint/parse';
import {signedOffBy} from './signed-off-by.js';
const messages = {
empty: 'test:\n',
with: `test: subject\nbody\nfooter\nSigned-off-by:\n\n`,
without: `test: subject\nbody\nfooter\n\n`,
inSubject: `test: subject Signed-off-by:\nbody\nfooter\n\n`,
inBody: `test: subject\nbody Signed-off-by:\nfooter\n\n`,
withSignoffAndComments: `test: subject
message body
Signed-off-by:
# 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),
withSignoffAndComments: parse(messages.withSignoffAndComments),
};
test('empty against "always signed-off-by" should fail', async () => {
const [actual] = signedOffBy(await parsed.empty, 'always', 'Signed-off-by:');
const expected = false;
expect(actual).toEqual(expected);
});
test('empty against "never signed-off-by" should succeed', async () => {
const [actual] = signedOffBy(await parsed.empty, 'never', 'Signed-off-by:');
const expected = true;
expect(actual).toEqual(expected);
});
test('with against "always signed-off-by" should succeed', async () => {
const [actual] = signedOffBy(await parsed.with, 'always', 'Signed-off-by:');
const expected = true;
expect(actual).toEqual(expected);
});
test('with against "never signed-off-by" should fail', async () => {
const [actual] = signedOffBy(await parsed.with, 'never', 'Signed-off-by:');
const expected = false;
expect(actual).toEqual(expected);
});
test('without against "always signed-off-by" should fail', async () => {
const [actual] = signedOffBy(
await parsed.without,
'always',
'Signed-off-by:'
);
const expected = false;
expect(actual).toEqual(expected);
});
test('without against "never signed-off-by" should succeed', async () => {
const [actual] = signedOffBy(await parsed.without, 'never', 'Signed-off-by:');
const expected = true;
expect(actual).toEqual(expected);
});
test('trailing comments should be ignored', async () => {
const [actual] = signedOffBy(
await parsed.withSignoffAndComments,
'always',
'Signed-off-by:'
);
const expected = true;
expect(actual).toEqual(expected);
});
test('inSubject against "always signed-off-by" should fail', async () => {
const [actual] = signedOffBy(
await parsed.inSubject,
'always',
'Signed-off-by:'
);
const expected = false;
expect(actual).toEqual(expected);
});
test('inSubject against "never signed-off-by" should succeed', async () => {
const [actual] = signedOffBy(
await parsed.inSubject,
'never',
'Signed-off-by:'
);
const expected = true;
expect(actual).toEqual(expected);
});
test('inBody against "always signed-off-by" should fail', async () => {
const [actual] = signedOffBy(await parsed.inBody, 'always', 'Signed-off-by:');
const expected = false;
expect(actual).toEqual(expected);
});
test('inBody against "never signed-off-by" should succeed', async () => {
const [actual] = signedOffBy(await parsed.inBody, 'never', 'Signed-off-by:');
const expected = true;
expect(actual).toEqual(expected);
});