generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.test.ts
186 lines (161 loc) · 5.92 KB
/
utils.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import {
filterArray,
shouldSkipBranchLint,
getHotfixLabel,
getPivotalId,
getPodLabel,
LABELS,
shouldUpdatePRDescription,
getPrDescription,
StoryResponse,
} from '../src/utils';
import { HIDDEN_MARKER } from '../src/constants';
jest.spyOn(console, 'log').mockImplementation(); // avoid actual console.log in test output
describe('shouldSkipBranchLint()', () => {
it('should recognize bot PRs', () => {
expect(shouldSkipBranchLint('dependabot')).toBeTruthy();
});
it.only('should handle custom ignore patterns', () => {
expect(shouldSkipBranchLint('bar', '^bar')).toBeTruthy();
expect(shouldSkipBranchLint('foobar', '^bar')).toBeFalsy();
expect(shouldSkipBranchLint('bar', '[0-9]{2}')).toBeFalsy();
expect(shouldSkipBranchLint('bar', '')).toBeFalsy();
expect(shouldSkipBranchLint('foo', '[0-9]{2}')).toBeFalsy();
expect(shouldSkipBranchLint('f00', '[0-9]{2}')).toBeTruthy();
const customBranchRegex = '^(production-release|master|release\/v\\d+)$';
expect(shouldSkipBranchLint('production-release', customBranchRegex)).toBeTruthy();
expect(shouldSkipBranchLint('master', customBranchRegex)).toBeTruthy();
expect(shouldSkipBranchLint('release/v77', customBranchRegex)).toBeTruthy();
expect(shouldSkipBranchLint('release/very-important-feature', customBranchRegex)).toBeFalsy();
expect(shouldSkipBranchLint('masterful', customBranchRegex)).toBeFalsy();
expect(shouldSkipBranchLint('productionish', customBranchRegex)).toBeFalsy();
expect(shouldSkipBranchLint('fix/production-issue', customBranchRegex)).toBeFalsy();
expect(shouldSkipBranchLint('chore/rebase-with-master', customBranchRegex)).toBeFalsy();
expect(shouldSkipBranchLint('chore/rebase-with-release', customBranchRegex)).toBeFalsy();
expect(shouldSkipBranchLint('chore/rebase-with-release/v77', customBranchRegex)).toBeFalsy();
});
it('should return false with empty input', () => {
expect(shouldSkipBranchLint('')).toBeFalsy();
});
it('should return false for other branches', () => {
expect(shouldSkipBranchLint('feature/awesomeNewFeature')).toBeFalsy();
});
});
describe('filterArray()', () => {
it('should return a valid array', () => {
expect(filterArray(['123', '', ' '])).toEqual(['123']);
});
it('should return a empty array with empty input', () => {
expect(filterArray([])).toEqual([]);
});
});
describe('getHotFixLabel()', () => {
it('should return empty string for master branch', () => {
expect(getHotfixLabel('master')).toEqual('');
});
it('should return HOTFIX-PROD for production branch', () => {
expect(getHotfixLabel('production-release')).toEqual(LABELS.HOTFIX_PROD);
});
it('should return HOTFIX-PRE-PROD for release branch', () => {
expect(getHotfixLabel('release/v')).toEqual(LABELS.HOTFIX_PRE_PROD);
});
it('should return empty string with no input', () => {
expect(getHotfixLabel('')).toEqual('');
});
});
describe('getPivotalId()', () => {
it('should return 9 digit pivotal id', () => {
expect(getPivotalId('feature/newFeature_123456789')).toEqual('123456789');
});
it('should return an empty string with invaid input branch', () => {
expect(getPivotalId('feature/newFeature')).toEqual('');
});
it('should return an empty string with no input', () => {
expect(getPivotalId('')).toEqual('');
});
});
describe('getPodLabel()', () => {
it('should return a single word from a multi word board name', () => {
expect(getPodLabel('Jarvis POD')).toEqual('Jarvis');
});
it('should return an empty string', () => {
expect(getPodLabel('')).toEqual('');
});
});
describe('shouldUpdatePRDescription()', () => {
it('should return false when the hidden marker is present', () => {
expect(shouldUpdatePRDescription(HIDDEN_MARKER)).toBeFalsy();
expect(shouldUpdatePRDescription(`
<h2><a href="https://www.pivotaltracker.com/story/show/999999999" target="_blank">Story #999999999</a></h2>
<details open>
<summary> <strong>Pivotal Summary</strong></summary>
<br />
<table>
<tr>
<th>Name</th>
<th>Details</th>
</tr>
<tr>
<td>ID</td>
<td><a href="https://www.pivotaltracker.com/story/show/999999999" target="_blank">#999999999</a></td>
</tr>
<tr>
<td>Type</td>
<td>⭐️ feature</td>
</tr>
<tr>
<td>Points</td>
<td>2</td>
</tr>
<tr>
<td>Labels</td>
<td>fe tech goodness, gst 2.0</td>
</tr>
</table>
</details>
<br />
<details>
<summary> <strong>Pivotal Description</strong></summary>
<br />
<p>Oops, the story creator did not add any description.</p>
<br />
</details>
<!--
do not remove this marker as it will break PR-lint's functionality.
${HIDDEN_MARKER}
-->
some actual content'
`)).toBeFalsy();
});
it('should return true when the hidden marker is NOT present', () =>{
expect(shouldUpdatePRDescription('')).toBeTruthy();
expect(shouldUpdatePRDescription('added_by')).toBeTruthy();
expect(shouldUpdatePRDescription('added_by_something_else')).toBeTruthy();
expect(shouldUpdatePRDescription(`
## Checklist
- [ ] PR is up-to-date with a description of changes and screenshots (if applicable).
- [ ] All files are lint-free.
- [ ] Added tests for the core-changes (as applicable).
- [ ] Tested locally for regressions & all test cases are passing.
`)).toBeTruthy();
});
});
describe('getPrDescription()', () => {
it('should include the hidden marker when getting PR description', () => {
const labels = [{ name: 'abc' }];
const story: Partial<StoryResponse> = {
project_id: 1234,
id: 'id',
url: 'url',
story_type: 'feature',
estimate: 1,
labels,
name: 'name',
};
const description = getPrDescription('some_body', story as any);
expect(shouldUpdatePRDescription(description)).toBeFalsy();
expect(description).toContain(story.id);
expect(description).toContain(story.estimate);
expect(description).toContain(labels[0].name);
});
});