1 | "use strict";
|
2 | var __assign = (this && this.__assign) || function () {
|
3 | __assign = Object.assign || function(t) {
|
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5 | s = arguments[i];
|
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7 | t[p] = s[p];
|
8 | }
|
9 | return t;
|
10 | };
|
11 | return __assign.apply(this, arguments);
|
12 | };
|
13 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
14 | return new (P || (P = Promise))(function (resolve, reject) {
|
15 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
16 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
17 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
18 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
19 | });
|
20 | };
|
21 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
22 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
23 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
24 | function verb(n) { return function (v) { return step([n, v]); }; }
|
25 | function step(op) {
|
26 | if (f) throw new TypeError("Generator is already executing.");
|
27 | while (_) try {
|
28 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
29 | if (y = 0, t) op = [op[0] & 2, t.value];
|
30 | switch (op[0]) {
|
31 | case 0: case 1: t = op; break;
|
32 | case 4: _.label++; return { value: op[1], done: false };
|
33 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
34 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
35 | default:
|
36 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
37 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
38 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
39 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
40 | if (t[2]) _.ops.pop();
|
41 | _.trys.pop(); continue;
|
42 | }
|
43 | op = body.call(thisArg, _);
|
44 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
45 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
46 | }
|
47 | };
|
48 | var __read = (this && this.__read) || function (o, n) {
|
49 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
50 | if (!m) return o;
|
51 | var i = m.call(o), r, ar = [], e;
|
52 | try {
|
53 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
54 | }
|
55 | catch (error) { e = { error: error }; }
|
56 | finally {
|
57 | try {
|
58 | if (r && !r.done && (m = i["return"])) m.call(i);
|
59 | }
|
60 | finally { if (e) throw e.error; }
|
61 | }
|
62 | return ar;
|
63 | };
|
64 | var __spread = (this && this.__spread) || function () {
|
65 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
66 | return ar;
|
67 | };
|
68 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
69 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
70 | };
|
71 | var _this = this;
|
72 | Object.defineProperty(exports, "__esModule", { value: true });
|
73 | var auto_1 = __importDefault(require("../auto"));
|
74 | var semver_1 = __importDefault(require("../semver"));
|
75 | var logger_1 = require("../utils/logger");
|
76 | var make_commit_from_msg_1 = __importDefault(require("./make-commit-from-msg"));
|
77 | var importMock = jest.fn();
|
78 | jest.mock('import-cwd', function () { return function (path) { return importMock(path); }; });
|
79 | jest.mock('env-ci', function () { return function () { return ({ isCi: false, branch: 'master' }); }; });
|
80 | var defaults = {
|
81 | owner: 'foo',
|
82 | repo: 'bar',
|
83 | token: 'XXXX'
|
84 | };
|
85 | var labels = {
|
86 | major: 'Version: Major',
|
87 | patch: 'Version: Patch',
|
88 | minor: 'Version: Minor'
|
89 | };
|
90 | var search = jest.fn();
|
91 | jest.mock('cosmiconfig', function () { return function () { return ({
|
92 | search: search
|
93 | }); }; });
|
94 | jest.mock('@octokit/rest', function () {
|
95 | var instance = function () { return ({
|
96 | authenticate: function () { return undefined; },
|
97 | search: {
|
98 | issuesAndPullRequests: function () { return ({ data: { items: [] } }); }
|
99 | },
|
100 | hook: {
|
101 | error: function () { return undefined; }
|
102 | }
|
103 | }); };
|
104 | instance.plugin = function () { return instance; };
|
105 | return instance;
|
106 | });
|
107 |
|
108 | jest.mock('gitlog', function () { return function (a, cb) {
|
109 | cb(undefined, [
|
110 | {
|
111 | rawBody: 'foo'
|
112 | },
|
113 | {
|
114 | rawBody: 'foo'
|
115 | }
|
116 | ]);
|
117 | }; });
|
118 | describe('Auto', function () {
|
119 | test('should use args', function () { return __awaiter(_this, void 0, void 0, function () {
|
120 | var auto;
|
121 | return __generator(this, function (_a) {
|
122 | switch (_a.label) {
|
123 | case 0:
|
124 | auto = new auto_1.default(defaults);
|
125 | auto.logger = logger_1.dummyLog();
|
126 | return [4 , auto.loadConfig()];
|
127 | case 1:
|
128 | _a.sent();
|
129 | expect(auto.release).toBeDefined();
|
130 | return [2 ];
|
131 | }
|
132 | });
|
133 | }); });
|
134 | test('should load config', function () { return __awaiter(_this, void 0, void 0, function () {
|
135 | var auto;
|
136 | return __generator(this, function (_a) {
|
137 | switch (_a.label) {
|
138 | case 0:
|
139 | search.mockReturnValueOnce({ config: defaults });
|
140 | auto = new auto_1.default();
|
141 | auto.logger = logger_1.dummyLog();
|
142 | return [4 , auto.loadConfig()];
|
143 | case 1:
|
144 | _a.sent();
|
145 | expect(auto.release).toBeDefined();
|
146 | return [2 ];
|
147 | }
|
148 | });
|
149 | }); });
|
150 | test('should throw if now GH_TOKEN set', function () { return __awaiter(_this, void 0, void 0, function () {
|
151 | var auto;
|
152 | return __generator(this, function (_a) {
|
153 | switch (_a.label) {
|
154 | case 0:
|
155 | auto = new auto_1.default();
|
156 | auto.logger = logger_1.dummyLog();
|
157 | process.env.GH_TOKEN = undefined;
|
158 | return [4 , expect(auto.loadConfig()).rejects.toBeInstanceOf(Error)];
|
159 | case 1:
|
160 | _a.sent();
|
161 | return [2 ];
|
162 | }
|
163 | });
|
164 | }); });
|
165 | test('should extend config', function () { return __awaiter(_this, void 0, void 0, function () {
|
166 | var auto;
|
167 | return __generator(this, function (_a) {
|
168 | switch (_a.label) {
|
169 | case 0:
|
170 | search.mockReturnValueOnce({ config: __assign({}, defaults, { extends: '@artsy' }) });
|
171 | importMock.mockImplementation(function (path) {
|
172 | return path === '@artsy/auto-config/package.json'
|
173 | ? { auto: { onlyPublishWithReleaseLabel: true } }
|
174 | : undefined;
|
175 | });
|
176 | auto = new auto_1.default();
|
177 | auto.logger = logger_1.dummyLog();
|
178 | return [4 , auto.loadConfig()];
|
179 | case 1:
|
180 | _a.sent();
|
181 | expect(auto.release.options).toMatchSnapshot();
|
182 | return [2 ];
|
183 | }
|
184 | });
|
185 | }); });
|
186 | test('should extend local config', function () { return __awaiter(_this, void 0, void 0, function () {
|
187 | var orig, auto;
|
188 | return __generator(this, function (_a) {
|
189 | switch (_a.label) {
|
190 | case 0:
|
191 | orig = process.cwd;
|
192 | process.cwd = function () { return '/foo/'; };
|
193 | search.mockReturnValueOnce({
|
194 | config: __assign({}, defaults, { extends: './fake.json' })
|
195 | });
|
196 | importMock.mockImplementation(function (path) {
|
197 | return path === '/foo/fake.json' ? { bar: 'foo' } : undefined;
|
198 | });
|
199 | auto = new auto_1.default();
|
200 | auto.logger = logger_1.dummyLog();
|
201 | return [4 , auto.loadConfig()];
|
202 | case 1:
|
203 | _a.sent();
|
204 | expect(auto.release.options).toMatchSnapshot();
|
205 | process.cwd = orig;
|
206 | return [2 ];
|
207 | }
|
208 | });
|
209 | }); });
|
210 | test('should use labels from config config', function () { return __awaiter(_this, void 0, void 0, function () {
|
211 | var auto;
|
212 | return __generator(this, function (_a) {
|
213 | switch (_a.label) {
|
214 | case 0:
|
215 | search.mockReturnValueOnce({
|
216 | config: __assign({}, defaults, { labels: labels })
|
217 | });
|
218 | auto = new auto_1.default();
|
219 | auto.logger = logger_1.dummyLog();
|
220 | return [4 , auto.loadConfig()];
|
221 | case 1:
|
222 | _a.sent();
|
223 | expect(__spread(auto.semVerLabels.values())).toEqual([
|
224 | 'Version: Major',
|
225 | 'Version: Minor',
|
226 | 'Version: Patch',
|
227 | 'skip-release',
|
228 | 'release',
|
229 | 'prerelease'
|
230 | ]);
|
231 | return [2 ];
|
232 | }
|
233 | });
|
234 | }); });
|
235 | test('should add extra skip label', function () { return __awaiter(_this, void 0, void 0, function () {
|
236 | var auto;
|
237 | return __generator(this, function (_a) {
|
238 | switch (_a.label) {
|
239 | case 0:
|
240 | search.mockReturnValueOnce({
|
241 | config: __assign({}, defaults, { labels: {
|
242 | 'skip-release': 'NOPE'
|
243 | } })
|
244 | });
|
245 | auto = new auto_1.default();
|
246 | auto.logger = logger_1.dummyLog();
|
247 | return [4 , auto.loadConfig()];
|
248 | case 1:
|
249 | _a.sent();
|
250 | expect(auto.release.options.skipReleaseLabels).toEqual(['NOPE']);
|
251 | return [2 ];
|
252 | }
|
253 | });
|
254 | }); });
|
255 | test('should be able to add label as string', function () { return __awaiter(_this, void 0, void 0, function () {
|
256 | var auto;
|
257 | return __generator(this, function (_a) {
|
258 | switch (_a.label) {
|
259 | case 0:
|
260 | search.mockReturnValueOnce({
|
261 | config: __assign({}, defaults, { labels: {
|
262 | minor: 'feature'
|
263 | } })
|
264 | });
|
265 | auto = new auto_1.default();
|
266 | auto.logger = logger_1.dummyLog();
|
267 | return [4 , auto.loadConfig()];
|
268 | case 1:
|
269 | _a.sent();
|
270 | expect(auto.release.options.labels.minor).toEqual({
|
271 | description: 'Increment the minor version when merged',
|
272 | name: 'feature',
|
273 | title: '🚀 Enhancement'
|
274 | });
|
275 | return [2 ];
|
276 | }
|
277 | });
|
278 | }); });
|
279 | test('should be able to omit properties from label definition', function () { return __awaiter(_this, void 0, void 0, function () {
|
280 | var auto;
|
281 | return __generator(this, function (_a) {
|
282 | switch (_a.label) {
|
283 | case 0:
|
284 | search.mockReturnValueOnce({
|
285 | config: __assign({}, defaults, { labels: {
|
286 | minor: {
|
287 | description: 'This is a test'
|
288 | }
|
289 | } })
|
290 | });
|
291 | auto = new auto_1.default();
|
292 | auto.logger = logger_1.dummyLog();
|
293 | return [4 , auto.loadConfig()];
|
294 | case 1:
|
295 | _a.sent();
|
296 | expect(auto.release.options.labels.minor).toEqual({
|
297 | description: 'This is a test',
|
298 | name: 'minor',
|
299 | title: '🚀 Enhancement'
|
300 | });
|
301 | return [2 ];
|
302 | }
|
303 | });
|
304 | }); });
|
305 | test('arbitrary labels should be able to omit name', function () { return __awaiter(_this, void 0, void 0, function () {
|
306 | var auto;
|
307 | return __generator(this, function (_a) {
|
308 | switch (_a.label) {
|
309 | case 0:
|
310 | search.mockReturnValueOnce({
|
311 | config: __assign({}, defaults, { labels: {
|
312 | fooBar: {
|
313 | description: 'This is a test'
|
314 | }
|
315 | } })
|
316 | });
|
317 | auto = new auto_1.default();
|
318 | auto.logger = logger_1.dummyLog();
|
319 | return [4 , auto.loadConfig()];
|
320 | case 1:
|
321 | _a.sent();
|
322 | expect(auto.release.options.labels.fooBar).toEqual({
|
323 | description: 'This is a test',
|
324 | name: 'fooBar'
|
325 | });
|
326 | return [2 ];
|
327 | }
|
328 | });
|
329 | }); });
|
330 | describe('createLabels', function () {
|
331 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
332 | var auto;
|
333 | return __generator(this, function (_a) {
|
334 | search.mockReturnValueOnce({
|
335 | config: __assign({}, defaults, { labels: labels })
|
336 | });
|
337 | auto = new auto_1.default();
|
338 | auto.logger = logger_1.dummyLog();
|
339 | expect(auto.createLabels()).rejects.toBeTruthy();
|
340 | return [2 ];
|
341 | });
|
342 | }); });
|
343 | test('should create the labels', function () { return __awaiter(_this, void 0, void 0, function () {
|
344 | var auto;
|
345 | return __generator(this, function (_a) {
|
346 | switch (_a.label) {
|
347 | case 0:
|
348 | search.mockReturnValueOnce({
|
349 | config: __assign({}, defaults, { labels: labels })
|
350 | });
|
351 | auto = new auto_1.default();
|
352 | auto.logger = logger_1.dummyLog();
|
353 | return [4 , auto.loadConfig()];
|
354 | case 1:
|
355 | _a.sent();
|
356 | auto.release.addLabelsToProject = jest.fn();
|
357 | return [4 , auto.createLabels()];
|
358 | case 2:
|
359 | _a.sent();
|
360 | expect(auto.release.addLabelsToProject).toMatchSnapshot();
|
361 | return [2 ];
|
362 | }
|
363 | });
|
364 | }); });
|
365 | });
|
366 | describe('label', function () {
|
367 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
368 | var auto;
|
369 | return __generator(this, function (_a) {
|
370 | search.mockReturnValueOnce({
|
371 | config: __assign({}, defaults, { labels: labels })
|
372 | });
|
373 | auto = new auto_1.default();
|
374 | auto.logger = logger_1.dummyLog();
|
375 | expect(auto.label({ pr: 13 })).rejects.toBeTruthy();
|
376 | return [2 ];
|
377 | });
|
378 | }); });
|
379 | test('should get labels', function () { return __awaiter(_this, void 0, void 0, function () {
|
380 | var auto, getLabels;
|
381 | return __generator(this, function (_a) {
|
382 | switch (_a.label) {
|
383 | case 0:
|
384 | auto = new auto_1.default(defaults);
|
385 | auto.logger = logger_1.dummyLog();
|
386 | return [4 , auto.loadConfig()];
|
387 | case 1:
|
388 | _a.sent();
|
389 | getLabels = jest.fn();
|
390 | auto.git.getLabels = getLabels;
|
391 | getLabels.mockReturnValueOnce(['foo']);
|
392 | console.log = jest.fn();
|
393 | return [4 , auto.label({ pr: 13 })];
|
394 | case 2:
|
395 | _a.sent();
|
396 | expect(console.log).toHaveBeenCalledWith('foo');
|
397 | return [2 ];
|
398 | }
|
399 | });
|
400 | }); });
|
401 | test('should get labels for last merged PR', function () { return __awaiter(_this, void 0, void 0, function () {
|
402 | var auto, getPullRequests;
|
403 | return __generator(this, function (_a) {
|
404 | switch (_a.label) {
|
405 | case 0:
|
406 | auto = new auto_1.default(defaults);
|
407 | auto.logger = logger_1.dummyLog();
|
408 | return [4 , auto.loadConfig()];
|
409 | case 1:
|
410 | _a.sent();
|
411 | getPullRequests = jest.fn();
|
412 | auto.git.getPullRequests = getPullRequests;
|
413 | getPullRequests.mockReturnValueOnce([
|
414 | {
|
415 | merged_at: '2019-01-08T03:45:33.000Z',
|
416 | labels: [{ name: 'wubbalublub' }]
|
417 | },
|
418 | {
|
419 | merged_at: '2019-01-10T03:45:33.000Z',
|
420 | labels: [{ name: 'foo' }, { name: 'bar' }]
|
421 | }
|
422 | ]);
|
423 | console.log = jest.fn();
|
424 | return [4 , auto.label()];
|
425 | case 2:
|
426 | _a.sent();
|
427 | expect(console.log).toHaveBeenCalledWith('foo\nbar');
|
428 | return [2 ];
|
429 | }
|
430 | });
|
431 | }); });
|
432 | test('should do nothing when no last merge found', function () { return __awaiter(_this, void 0, void 0, function () {
|
433 | var auto, getPullRequests;
|
434 | return __generator(this, function (_a) {
|
435 | switch (_a.label) {
|
436 | case 0:
|
437 | auto = new auto_1.default(defaults);
|
438 | auto.logger = logger_1.dummyLog();
|
439 | return [4 , auto.loadConfig()];
|
440 | case 1:
|
441 | _a.sent();
|
442 | getPullRequests = jest.fn();
|
443 | auto.git.getPullRequests = getPullRequests;
|
444 | getPullRequests.mockReturnValueOnce([]);
|
445 | console.log = jest.fn();
|
446 | return [4 , auto.label()];
|
447 | case 2:
|
448 | _a.sent();
|
449 | expect(console.log).not.toHaveBeenCalled();
|
450 | return [2 ];
|
451 | }
|
452 | });
|
453 | }); });
|
454 | });
|
455 | describe('pr', function () {
|
456 | var createStatus;
|
457 | beforeEach(function () {
|
458 | createStatus = jest.fn();
|
459 | });
|
460 | var required = {
|
461 | url: 'https://google.com',
|
462 | state: 'pending',
|
463 | description: 'foo',
|
464 | context: 'bar'
|
465 | };
|
466 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
467 | var auto;
|
468 | return __generator(this, function (_a) {
|
469 | auto = new auto_1.default(defaults);
|
470 | auto.logger = logger_1.dummyLog();
|
471 | expect(auto.prStatus(required)).rejects.toBeTruthy();
|
472 | return [2 ];
|
473 | });
|
474 | }); });
|
475 | test('should catch exceptions when status fails to post', function () { return __awaiter(_this, void 0, void 0, function () {
|
476 | var auto;
|
477 | return __generator(this, function (_a) {
|
478 | switch (_a.label) {
|
479 | case 0:
|
480 | auto = new auto_1.default(defaults);
|
481 | auto.logger = logger_1.dummyLog();
|
482 | return [4 , auto.loadConfig()];
|
483 | case 1:
|
484 | _a.sent();
|
485 | auto.git.createStatus = createStatus;
|
486 | createStatus.mockRejectedValueOnce({ status: 400 });
|
487 | return [4 , expect(auto.prStatus(__assign({}, required, { sha: '1234' }))).rejects.toBeInstanceOf(Error)];
|
488 | case 2:
|
489 | _a.sent();
|
490 | expect(createStatus).toHaveBeenCalled();
|
491 | return [2 ];
|
492 | }
|
493 | });
|
494 | }); });
|
495 | test('should do nothing ', function () { return __awaiter(_this, void 0, void 0, function () {
|
496 | var auto;
|
497 | return __generator(this, function (_a) {
|
498 | switch (_a.label) {
|
499 | case 0:
|
500 | auto = new auto_1.default(defaults);
|
501 | auto.logger = logger_1.dummyLog();
|
502 | return [4 , auto.loadConfig()];
|
503 | case 1:
|
504 | _a.sent();
|
505 | return [4 , auto.prStatus(__assign({}, required, { sha: '1234', dryRun: true }))];
|
506 | case 2:
|
507 | _a.sent();
|
508 | expect(createStatus).not.toHaveBeenCalled();
|
509 | return [2 ];
|
510 | }
|
511 | });
|
512 | }); });
|
513 | test('should use provided SHA', function () { return __awaiter(_this, void 0, void 0, function () {
|
514 | var auto;
|
515 | return __generator(this, function (_a) {
|
516 | switch (_a.label) {
|
517 | case 0:
|
518 | auto = new auto_1.default(defaults);
|
519 | auto.logger = logger_1.dummyLog();
|
520 | return [4 , auto.loadConfig()];
|
521 | case 1:
|
522 | _a.sent();
|
523 | auto.git.createStatus = createStatus;
|
524 | return [4 , auto.prStatus(__assign({}, required, { sha: '1234' }))];
|
525 | case 2:
|
526 | _a.sent();
|
527 | expect(createStatus).toHaveBeenCalledWith(expect.objectContaining({
|
528 | sha: '1234'
|
529 | }));
|
530 | return [2 ];
|
531 | }
|
532 | });
|
533 | }); });
|
534 | test('should use HEAD SHA', function () { return __awaiter(_this, void 0, void 0, function () {
|
535 | var auto, getSha;
|
536 | return __generator(this, function (_a) {
|
537 | switch (_a.label) {
|
538 | case 0:
|
539 | auto = new auto_1.default(defaults);
|
540 | auto.logger = logger_1.dummyLog();
|
541 | return [4 , auto.loadConfig()];
|
542 | case 1:
|
543 | _a.sent();
|
544 | auto.git.createStatus = createStatus;
|
545 | getSha = jest.fn();
|
546 | auto.git.getSha = getSha;
|
547 | getSha.mockReturnValueOnce('abc');
|
548 | return [4 , auto.prStatus(__assign({}, required))];
|
549 | case 2:
|
550 | _a.sent();
|
551 | expect(createStatus).toHaveBeenCalledWith(expect.objectContaining({
|
552 | sha: 'abc'
|
553 | }));
|
554 | return [2 ];
|
555 | }
|
556 | });
|
557 | }); });
|
558 | test('should use lookup SHA for PR', function () { return __awaiter(_this, void 0, void 0, function () {
|
559 | var auto, getPullRequest;
|
560 | return __generator(this, function (_a) {
|
561 | switch (_a.label) {
|
562 | case 0:
|
563 | auto = new auto_1.default(defaults);
|
564 | auto.logger = logger_1.dummyLog();
|
565 | return [4 , auto.loadConfig()];
|
566 | case 1:
|
567 | _a.sent();
|
568 | auto.git.createStatus = createStatus;
|
569 | getPullRequest = jest.fn();
|
570 | auto.git.getPullRequest = getPullRequest;
|
571 | getPullRequest.mockReturnValueOnce({ data: { head: { sha: 'deep' } } });
|
572 | return [4 , auto.prStatus(__assign({}, required, { pr: 14 }))];
|
573 | case 2:
|
574 | _a.sent();
|
575 | expect(createStatus).toHaveBeenCalledWith(expect.objectContaining({
|
576 | sha: 'deep'
|
577 | }));
|
578 | return [2 ];
|
579 | }
|
580 | });
|
581 | }); });
|
582 | });
|
583 | describe('pr-check', function () {
|
584 | jest.setTimeout(10 * 1000);
|
585 | var createStatus;
|
586 | beforeEach(function () {
|
587 | createStatus = jest.fn();
|
588 | });
|
589 | var required = {
|
590 | url: 'https://google.com'
|
591 | };
|
592 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
593 | var auto;
|
594 | return __generator(this, function (_a) {
|
595 | auto = new auto_1.default(defaults);
|
596 | auto.logger = logger_1.dummyLog();
|
597 | expect(auto.prCheck(__assign({ pr: 13 }, required))).rejects.toBeTruthy();
|
598 | return [2 ];
|
599 | });
|
600 | }); });
|
601 | test('should do nothing with dryRun', function () { return __awaiter(_this, void 0, void 0, function () {
|
602 | var auto;
|
603 | return __generator(this, function (_a) {
|
604 | switch (_a.label) {
|
605 | case 0:
|
606 | auto = new auto_1.default(defaults);
|
607 | auto.logger = logger_1.dummyLog();
|
608 | return [4 , auto.loadConfig()];
|
609 | case 1:
|
610 | _a.sent();
|
611 | return [4 , auto.prCheck(__assign({}, required, { pr: 13, dryRun: true }))];
|
612 | case 2:
|
613 | _a.sent();
|
614 | expect(createStatus).not.toHaveBeenCalled();
|
615 | return [2 ];
|
616 | }
|
617 | });
|
618 | }); });
|
619 | test('should catch errors', function () { return __awaiter(_this, void 0, void 0, function () {
|
620 | var auto;
|
621 | return __generator(this, function (_a) {
|
622 | switch (_a.label) {
|
623 | case 0:
|
624 | auto = new auto_1.default(defaults);
|
625 | auto.logger = logger_1.dummyLog();
|
626 | return [4 , auto.loadConfig()];
|
627 | case 1:
|
628 | _a.sent();
|
629 | auto.git.createStatus = createStatus;
|
630 | return [4 , auto.prCheck(__assign({}, required, { pr: 13 }))];
|
631 | case 2:
|
632 | _a.sent();
|
633 | expect(createStatus).toHaveBeenCalledWith(expect.objectContaining({
|
634 | state: 'error'
|
635 | }));
|
636 | return [2 ];
|
637 | }
|
638 | });
|
639 | }); });
|
640 | test('should catch status errors', function () { return __awaiter(_this, void 0, void 0, function () {
|
641 | var auto;
|
642 | return __generator(this, function (_a) {
|
643 | switch (_a.label) {
|
644 | case 0:
|
645 | auto = new auto_1.default(defaults);
|
646 | auto.logger = logger_1.dummyLog();
|
647 | return [4 , auto.loadConfig()];
|
648 | case 1:
|
649 | _a.sent();
|
650 | auto.git.createStatus = createStatus;
|
651 | createStatus.mockRejectedValueOnce({ status: 123 });
|
652 | return [4 , expect(auto.prCheck(__assign({}, required, { pr: 13 }))).rejects.toBeInstanceOf(Error)];
|
653 | case 2:
|
654 | _a.sent();
|
655 | expect(createStatus).toHaveBeenCalled();
|
656 | return [2 ];
|
657 | }
|
658 | });
|
659 | }); });
|
660 | test('should error with no label', function () { return __awaiter(_this, void 0, void 0, function () {
|
661 | var auto, getPullRequest, getLabels;
|
662 | return __generator(this, function (_a) {
|
663 | switch (_a.label) {
|
664 | case 0:
|
665 | auto = new auto_1.default(defaults);
|
666 | auto.logger = logger_1.dummyLog();
|
667 | return [4 , auto.loadConfig()];
|
668 | case 1:
|
669 | _a.sent();
|
670 | auto.git.createStatus = createStatus;
|
671 | getPullRequest = jest.fn();
|
672 | auto.git.getPullRequest = getPullRequest;
|
673 | getPullRequest.mockReturnValueOnce({ data: { head: { sha: 'sha' } } });
|
674 | getLabels = jest.fn();
|
675 | auto.git.getLabels = getLabels;
|
676 | getLabels.mockReturnValueOnce([]);
|
677 | return [4 , auto.prCheck(__assign({}, required, { pr: 13 }))];
|
678 | case 2:
|
679 | _a.sent();
|
680 | expect(createStatus).toHaveBeenCalledWith(expect.objectContaining({
|
681 | description: 'No semver label!'
|
682 | }));
|
683 | return [2 ];
|
684 | }
|
685 | });
|
686 | }); });
|
687 | test('should pass with semver label', function () { return __awaiter(_this, void 0, void 0, function () {
|
688 | var auto, getPullRequest, getLabels;
|
689 | return __generator(this, function (_a) {
|
690 | switch (_a.label) {
|
691 | case 0:
|
692 | auto = new auto_1.default(defaults);
|
693 | auto.logger = logger_1.dummyLog();
|
694 | return [4 , auto.loadConfig()];
|
695 | case 1:
|
696 | _a.sent();
|
697 | auto.git.createStatus = createStatus;
|
698 | getPullRequest = jest.fn();
|
699 | auto.git.getPullRequest = getPullRequest;
|
700 | getPullRequest.mockReturnValueOnce({ data: { head: { sha: 'sha' } } });
|
701 | getLabels = jest.fn();
|
702 | auto.git.getLabels = getLabels;
|
703 | getLabels.mockReturnValueOnce(['major']);
|
704 | return [4 , auto.prCheck(__assign({}, required, { pr: 13 }))];
|
705 | case 2:
|
706 | _a.sent();
|
707 | expect(createStatus).toHaveBeenCalledWith(expect.objectContaining({
|
708 | description: 'CI - major'
|
709 | }));
|
710 | return [2 ];
|
711 | }
|
712 | });
|
713 | }); });
|
714 | test('should pass with skip release label', function () { return __awaiter(_this, void 0, void 0, function () {
|
715 | var auto, getPullRequest, getLabels;
|
716 | return __generator(this, function (_a) {
|
717 | switch (_a.label) {
|
718 | case 0:
|
719 | auto = new auto_1.default(defaults);
|
720 | auto.logger = logger_1.dummyLog();
|
721 | return [4 , auto.loadConfig()];
|
722 | case 1:
|
723 | _a.sent();
|
724 | auto.git.createStatus = createStatus;
|
725 | getPullRequest = jest.fn();
|
726 | auto.git.getPullRequest = getPullRequest;
|
727 | getPullRequest.mockReturnValueOnce({ data: { head: { sha: 'sha' } } });
|
728 | getLabels = jest.fn();
|
729 | auto.git.getLabels = getLabels;
|
730 | getLabels.mockReturnValueOnce(['major', 'skip-release']);
|
731 | return [4 , auto.prCheck(__assign({}, required, { pr: 13 }))];
|
732 | case 2:
|
733 | _a.sent();
|
734 | expect(createStatus).toHaveBeenCalledWith(expect.objectContaining({
|
735 | description: 'PR will not create a release'
|
736 | }));
|
737 | return [2 ];
|
738 | }
|
739 | });
|
740 | }); });
|
741 | test('should pass with skip release label', function () { return __awaiter(_this, void 0, void 0, function () {
|
742 | var auto, getPullRequest, getLabels;
|
743 | return __generator(this, function (_a) {
|
744 | switch (_a.label) {
|
745 | case 0:
|
746 | auto = new auto_1.default(defaults);
|
747 | auto.logger = logger_1.dummyLog();
|
748 | return [4 , auto.loadConfig()];
|
749 | case 1:
|
750 | _a.sent();
|
751 | auto.git.createStatus = createStatus;
|
752 | getPullRequest = jest.fn();
|
753 | auto.git.getPullRequest = getPullRequest;
|
754 | getPullRequest.mockReturnValueOnce({ data: { head: { sha: 'sha' } } });
|
755 | getLabels = jest.fn();
|
756 | auto.git.getLabels = getLabels;
|
757 | getLabels.mockReturnValueOnce(['major', 'release']);
|
758 | return [4 , auto.prCheck(__assign({}, required, { pr: 13 }))];
|
759 | case 2:
|
760 | _a.sent();
|
761 | expect(createStatus).toHaveBeenCalledWith(expect.objectContaining({
|
762 | description: 'PR will create release once merged - major'
|
763 | }));
|
764 | return [2 ];
|
765 | }
|
766 | });
|
767 | }); });
|
768 | });
|
769 | describe('comment', function () {
|
770 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
771 | var auto;
|
772 | return __generator(this, function (_a) {
|
773 | switch (_a.label) {
|
774 | case 0:
|
775 | auto = new auto_1.default(defaults);
|
776 | auto.logger = logger_1.dummyLog();
|
777 | return [4 , expect(auto.comment({ pr: 10, message: 'foo' })).rejects.toBeTruthy()];
|
778 | case 1:
|
779 | _a.sent();
|
780 | return [2 ];
|
781 | }
|
782 | });
|
783 | }); });
|
784 | test('should make a comment', function () { return __awaiter(_this, void 0, void 0, function () {
|
785 | var auto, createComment;
|
786 | return __generator(this, function (_a) {
|
787 | switch (_a.label) {
|
788 | case 0:
|
789 | auto = new auto_1.default(defaults);
|
790 | auto.logger = logger_1.dummyLog();
|
791 | return [4 , auto.loadConfig()];
|
792 | case 1:
|
793 | _a.sent();
|
794 | createComment = jest.fn();
|
795 | auto.git.createComment = createComment;
|
796 | return [4 , auto.comment({ pr: 10, message: 'foo' })];
|
797 | case 2:
|
798 | _a.sent();
|
799 | expect(createComment).toHaveBeenCalled();
|
800 | return [2 ];
|
801 | }
|
802 | });
|
803 | }); });
|
804 | test('should delete a comment', function () { return __awaiter(_this, void 0, void 0, function () {
|
805 | var auto, deleteComment;
|
806 | return __generator(this, function (_a) {
|
807 | switch (_a.label) {
|
808 | case 0:
|
809 | auto = new auto_1.default(defaults);
|
810 | auto.logger = logger_1.dummyLog();
|
811 | return [4 , auto.loadConfig()];
|
812 | case 1:
|
813 | _a.sent();
|
814 | deleteComment = jest.fn();
|
815 | auto.git.deleteComment = deleteComment;
|
816 | return [4 , auto.comment({ pr: 10, delete: true })];
|
817 | case 2:
|
818 | _a.sent();
|
819 | expect(deleteComment).toHaveBeenCalled();
|
820 | return [2 ];
|
821 | }
|
822 | });
|
823 | }); });
|
824 | test('should not delete a comment in dry run mode', function () { return __awaiter(_this, void 0, void 0, function () {
|
825 | var auto, deleteComment;
|
826 | return __generator(this, function (_a) {
|
827 | switch (_a.label) {
|
828 | case 0:
|
829 | auto = new auto_1.default(defaults);
|
830 | auto.logger = logger_1.dummyLog();
|
831 | return [4 , auto.loadConfig()];
|
832 | case 1:
|
833 | _a.sent();
|
834 | deleteComment = jest.fn();
|
835 | auto.git.deleteComment = deleteComment;
|
836 | return [4 , auto.comment({ pr: 10, message: 'foo bar', dryRun: true })];
|
837 | case 2:
|
838 | _a.sent();
|
839 | expect(deleteComment).not.toHaveBeenCalled();
|
840 | return [4 , auto.comment({ pr: 10, delete: true, dryRun: true })];
|
841 | case 3:
|
842 | _a.sent();
|
843 | expect(deleteComment).not.toHaveBeenCalled();
|
844 | return [2 ];
|
845 | }
|
846 | });
|
847 | }); });
|
848 | });
|
849 | describe('prBody', function () {
|
850 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
851 | var auto;
|
852 | return __generator(this, function (_a) {
|
853 | switch (_a.label) {
|
854 | case 0:
|
855 | auto = new auto_1.default(defaults);
|
856 | auto.logger = logger_1.dummyLog();
|
857 | return [4 , expect(auto.prBody({ pr: 10, message: 'foo' })).rejects.toBeTruthy()];
|
858 | case 1:
|
859 | _a.sent();
|
860 | return [2 ];
|
861 | }
|
862 | });
|
863 | }); });
|
864 | test('should make a pr body update', function () { return __awaiter(_this, void 0, void 0, function () {
|
865 | var auto, addToPrBody;
|
866 | return __generator(this, function (_a) {
|
867 | switch (_a.label) {
|
868 | case 0:
|
869 | auto = new auto_1.default(defaults);
|
870 | auto.logger = logger_1.dummyLog();
|
871 | return [4 , auto.loadConfig()];
|
872 | case 1:
|
873 | _a.sent();
|
874 | addToPrBody = jest.fn();
|
875 | auto.git.addToPrBody = addToPrBody;
|
876 | return [4 , auto.prBody({ pr: 10, message: 'foo' })];
|
877 | case 2:
|
878 | _a.sent();
|
879 | expect(addToPrBody).toHaveBeenCalled();
|
880 | return [2 ];
|
881 | }
|
882 | });
|
883 | }); });
|
884 | test('should delete old pr body update', function () { return __awaiter(_this, void 0, void 0, function () {
|
885 | var auto, addToPrBody;
|
886 | return __generator(this, function (_a) {
|
887 | switch (_a.label) {
|
888 | case 0:
|
889 | auto = new auto_1.default(defaults);
|
890 | auto.logger = logger_1.dummyLog();
|
891 | return [4 , auto.loadConfig()];
|
892 | case 1:
|
893 | _a.sent();
|
894 | addToPrBody = jest.fn();
|
895 | auto.git.addToPrBody = addToPrBody;
|
896 | return [4 , auto.prBody({ pr: 10, delete: true })];
|
897 | case 2:
|
898 | _a.sent();
|
899 | expect(addToPrBody).toHaveBeenCalledWith('', 10, 'default');
|
900 | return [2 ];
|
901 | }
|
902 | });
|
903 | }); });
|
904 | test('should not update pr body a dry run mode', function () { return __awaiter(_this, void 0, void 0, function () {
|
905 | var auto, addToPrBody;
|
906 | return __generator(this, function (_a) {
|
907 | switch (_a.label) {
|
908 | case 0:
|
909 | auto = new auto_1.default(defaults);
|
910 | auto.logger = logger_1.dummyLog();
|
911 | return [4 , auto.loadConfig()];
|
912 | case 1:
|
913 | _a.sent();
|
914 | addToPrBody = jest.fn();
|
915 | auto.git.addToPrBody = addToPrBody;
|
916 | return [4 , auto.prBody({ pr: 10, message: 'foo bar', dryRun: true })];
|
917 | case 2:
|
918 | _a.sent();
|
919 | expect(addToPrBody).not.toHaveBeenCalled();
|
920 | return [4 , auto.prBody({ pr: 10, delete: true, dryRun: true })];
|
921 | case 3:
|
922 | _a.sent();
|
923 | expect(addToPrBody).not.toHaveBeenCalled();
|
924 | return [2 ];
|
925 | }
|
926 | });
|
927 | }); });
|
928 | });
|
929 | describe('version', function () {
|
930 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
931 | var auto;
|
932 | return __generator(this, function (_a) {
|
933 | auto = new auto_1.default(defaults);
|
934 | auto.logger = logger_1.dummyLog();
|
935 | expect(auto.version()).rejects.toBeTruthy();
|
936 | return [2 ];
|
937 | });
|
938 | }); });
|
939 | test('should make a comment', function () { return __awaiter(_this, void 0, void 0, function () {
|
940 | var auto, getSemverBump;
|
941 | return __generator(this, function (_a) {
|
942 | switch (_a.label) {
|
943 | case 0:
|
944 | auto = new auto_1.default(defaults);
|
945 | auto.logger = logger_1.dummyLog();
|
946 | return [4 , auto.loadConfig()];
|
947 | case 1:
|
948 | _a.sent();
|
949 | getSemverBump = jest.fn();
|
950 | auto.git.getLatestRelease = jest.fn();
|
951 | auto.release.getSemverBump = getSemverBump;
|
952 | getSemverBump.mockReturnValueOnce('patch');
|
953 | console.log = jest.fn();
|
954 | return [4 , auto.version()];
|
955 | case 2:
|
956 | _a.sent();
|
957 | expect(console.log).toHaveBeenCalledWith('patch');
|
958 | return [2 ];
|
959 | }
|
960 | });
|
961 | }); });
|
962 | });
|
963 | describe('changelog', function () {
|
964 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
965 | var auto;
|
966 | return __generator(this, function (_a) {
|
967 | auto = new auto_1.default(defaults);
|
968 | auto.logger = logger_1.dummyLog();
|
969 | expect(auto.changelog()).rejects.toBeTruthy();
|
970 | return [2 ];
|
971 | });
|
972 | }); });
|
973 | test('should do nothing on a dryRun', function () { return __awaiter(_this, void 0, void 0, function () {
|
974 | var auto, addToChangelog;
|
975 | return __generator(this, function (_a) {
|
976 | switch (_a.label) {
|
977 | case 0:
|
978 | auto = new auto_1.default(defaults);
|
979 | auto.logger = logger_1.dummyLog();
|
980 | return [4 , auto.loadConfig()];
|
981 | case 1:
|
982 | _a.sent();
|
983 | addToChangelog = jest.fn();
|
984 | auto.release.addToChangelog = addToChangelog;
|
985 | auto.release.generateReleaseNotes = jest.fn();
|
986 | return [4 , auto.changelog({ from: 'v1.0.0', dryRun: true })];
|
987 | case 2:
|
988 | _a.sent();
|
989 | expect(addToChangelog).not.toHaveBeenCalled();
|
990 | return [2 ];
|
991 | }
|
992 | });
|
993 | }); });
|
994 | test('should add to changelog', function () { return __awaiter(_this, void 0, void 0, function () {
|
995 | var auto, addToChangelog;
|
996 | return __generator(this, function (_a) {
|
997 | switch (_a.label) {
|
998 | case 0:
|
999 | auto = new auto_1.default(__assign({ plugins: [] }, defaults));
|
1000 | auto.logger = logger_1.dummyLog();
|
1001 | auto.hooks.getRepository.tap('test', function () { return ({ token: '1234' }); });
|
1002 | return [4 , auto.loadConfig()];
|
1003 | case 1:
|
1004 | _a.sent();
|
1005 | addToChangelog = jest.fn();
|
1006 | auto.release.addToChangelog = addToChangelog;
|
1007 | auto.release.generateReleaseNotes = jest.fn();
|
1008 | return [4 , auto.changelog({ from: 'v1.0.0' })];
|
1009 | case 2:
|
1010 | _a.sent();
|
1011 | expect(addToChangelog).toHaveBeenCalled();
|
1012 | return [2 ];
|
1013 | }
|
1014 | });
|
1015 | }); });
|
1016 | test('should skip getRepository hook if passed in via cli', function () { return __awaiter(_this, void 0, void 0, function () {
|
1017 | var auto, hookFn;
|
1018 | return __generator(this, function (_a) {
|
1019 | switch (_a.label) {
|
1020 | case 0:
|
1021 | process.env.GH_TOKEN = 'XXXX';
|
1022 | auto = new auto_1.default({
|
1023 | repo: 'test',
|
1024 | owner: 'adierkens'
|
1025 | });
|
1026 | auto.logger = logger_1.dummyLog();
|
1027 | hookFn = jest.fn();
|
1028 | auto.hooks.getRepository.tap('test', hookFn);
|
1029 | return [4 , auto.loadConfig()];
|
1030 | case 1:
|
1031 | _a.sent();
|
1032 | return [4 , auto.prStatus({
|
1033 | url: 'foo.bar',
|
1034 | state: 'pending',
|
1035 | description: 'Waiting for stuffs',
|
1036 | context: 'tests',
|
1037 | dryRun: true
|
1038 | })];
|
1039 | case 2:
|
1040 | _a.sent();
|
1041 | expect(hookFn).not.toBeCalled();
|
1042 | return [2 ];
|
1043 | }
|
1044 | });
|
1045 | }); });
|
1046 | });
|
1047 | describe('release', function () {
|
1048 | test("doesn't try to overwrite releases", function () { return __awaiter(_this, void 0, void 0, function () {
|
1049 | var auto, afterRelease;
|
1050 | return __generator(this, function (_a) {
|
1051 | switch (_a.label) {
|
1052 | case 0:
|
1053 | auto = new auto_1.default(__assign({}, defaults, { plugins: [] }));
|
1054 | auto.logger = logger_1.dummyLog();
|
1055 | return [4 , auto.loadConfig()];
|
1056 | case 1:
|
1057 | _a.sent();
|
1058 | auto.git.getLatestRelease = function () { return Promise.resolve('1.2.3'); };
|
1059 | auto.release.generateReleaseNotes = jest.fn();
|
1060 | auto.release.getCommitsInRelease = function () {
|
1061 | return Promise.resolve([make_commit_from_msg_1.default('Test Commit')]);
|
1062 | };
|
1063 | auto.hooks.getPreviousVersion.tap('test', function () { return '1.2.3'; });
|
1064 | afterRelease = jest.fn();
|
1065 | auto.hooks.afterRelease.tap('test', afterRelease);
|
1066 | auto.release.getCommits = jest.fn();
|
1067 | return [4 , auto.runRelease()];
|
1068 | case 2:
|
1069 | _a.sent();
|
1070 | expect(afterRelease).not.toHaveBeenCalled();
|
1071 | return [2 ];
|
1072 | }
|
1073 | });
|
1074 | }); });
|
1075 | });
|
1076 | describe('canary', function () {
|
1077 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
1078 | var auto;
|
1079 | return __generator(this, function (_a) {
|
1080 | auto = new auto_1.default(defaults);
|
1081 | auto.logger = logger_1.dummyLog();
|
1082 | expect(auto.canary()).rejects.toBeTruthy();
|
1083 | return [2 ];
|
1084 | });
|
1085 | }); });
|
1086 | test('does not call canary hook in dry-run', function () { return __awaiter(_this, void 0, void 0, function () {
|
1087 | var auto, canary;
|
1088 | return __generator(this, function (_a) {
|
1089 | switch (_a.label) {
|
1090 | case 0:
|
1091 | auto = new auto_1.default(defaults);
|
1092 | auto.logger = logger_1.dummyLog();
|
1093 | return [4 , auto.loadConfig()];
|
1094 | case 1:
|
1095 | _a.sent();
|
1096 | auto.git.getLatestRelease = function () { return Promise.resolve('1.2.3'); };
|
1097 | auto.release.getCommitsInRelease = function () {
|
1098 | return Promise.resolve([make_commit_from_msg_1.default('Test Commit')]);
|
1099 | };
|
1100 | canary = jest.fn();
|
1101 | auto.hooks.canary.tap('test', canary);
|
1102 | auto.release.getCommits = jest.fn();
|
1103 | return [4 , auto.canary({ pr: 123, build: 1, dryRun: true })];
|
1104 | case 2:
|
1105 | _a.sent();
|
1106 | expect(canary).not.toHaveBeenCalled();
|
1107 | return [2 ];
|
1108 | }
|
1109 | });
|
1110 | }); });
|
1111 | test('calls the canary hook with the pr info', function () { return __awaiter(_this, void 0, void 0, function () {
|
1112 | var auto, canary;
|
1113 | return __generator(this, function (_a) {
|
1114 | switch (_a.label) {
|
1115 | case 0:
|
1116 | auto = new auto_1.default(__assign({}, defaults, { plugins: [] }));
|
1117 | auto.logger = logger_1.dummyLog();
|
1118 | return [4 , auto.loadConfig()];
|
1119 | case 1:
|
1120 | _a.sent();
|
1121 | auto.git.getLatestRelease = function () { return Promise.resolve('1.2.3'); };
|
1122 | auto.git.getSha = function () { return Promise.resolve('abc'); };
|
1123 | auto.git.addToPrBody = jest.fn();
|
1124 | auto.release.getCommitsInRelease = function () {
|
1125 | return Promise.resolve([make_commit_from_msg_1.default('Test Commit')]);
|
1126 | };
|
1127 | canary = jest.fn();
|
1128 | auto.hooks.canary.tap('test', canary);
|
1129 | auto.release.getCommits = jest.fn();
|
1130 | return [4 , auto.canary({ pr: 123, build: 1 })];
|
1131 | case 2:
|
1132 | _a.sent();
|
1133 | expect(canary).toHaveBeenCalledWith(semver_1.default.patch, '.123.1.abc');
|
1134 | expect(auto.git.addToPrBody).toHaveBeenCalled();
|
1135 | return [2 ];
|
1136 | }
|
1137 | });
|
1138 | }); });
|
1139 | test("doesn't comment if there is an error", function () { return __awaiter(_this, void 0, void 0, function () {
|
1140 | var auto, canary;
|
1141 | return __generator(this, function (_a) {
|
1142 | switch (_a.label) {
|
1143 | case 0:
|
1144 | auto = new auto_1.default(__assign({}, defaults, { plugins: [] }));
|
1145 | auto.logger = logger_1.dummyLog();
|
1146 | return [4 , auto.loadConfig()];
|
1147 | case 1:
|
1148 | _a.sent();
|
1149 | auto.prBody = jest.fn();
|
1150 | auto.git.getLatestRelease = function () { return Promise.resolve('1.2.3'); };
|
1151 | auto.git.getSha = function () { return Promise.resolve('abc'); };
|
1152 | auto.release.getCommitsInRelease = function () {
|
1153 | return Promise.resolve([make_commit_from_msg_1.default('Test Commit')]);
|
1154 | };
|
1155 | canary = jest.fn();
|
1156 | canary.mockReturnValue({ error: 'ooops' });
|
1157 | auto.hooks.canary.tap('test', canary);
|
1158 | auto.release.getCommits = jest.fn();
|
1159 | return [4 , auto.canary({ pr: 123, build: 1 })];
|
1160 | case 2:
|
1161 | _a.sent();
|
1162 | expect(auto.prBody).not.toHaveBeenCalled();
|
1163 | return [2 ];
|
1164 | }
|
1165 | });
|
1166 | }); });
|
1167 | test('defaults to sha when run locally', function () { return __awaiter(_this, void 0, void 0, function () {
|
1168 | var auto, canary;
|
1169 | return __generator(this, function (_a) {
|
1170 | switch (_a.label) {
|
1171 | case 0:
|
1172 | auto = new auto_1.default(__assign({}, defaults, { plugins: [] }));
|
1173 | auto.logger = logger_1.dummyLog();
|
1174 | return [4 , auto.loadConfig()];
|
1175 | case 1:
|
1176 | _a.sent();
|
1177 | auto.git.getSha = function () { return Promise.resolve('abcd'); };
|
1178 | auto.git.getLatestRelease = function () { return Promise.resolve('1.2.3'); };
|
1179 | auto.release.getCommitsInRelease = function () {
|
1180 | return Promise.resolve([make_commit_from_msg_1.default('Test Commit')]);
|
1181 | };
|
1182 | canary = jest.fn();
|
1183 | auto.hooks.canary.tap('test', canary);
|
1184 | return [4 , auto.canary()];
|
1185 | case 2:
|
1186 | _a.sent();
|
1187 | expect(canary).toHaveBeenCalledWith(semver_1.default.patch, '.abcd');
|
1188 | return [2 ];
|
1189 | }
|
1190 | });
|
1191 | }); });
|
1192 | test('works when PR has "skip-release" label', function () { return __awaiter(_this, void 0, void 0, function () {
|
1193 | var auto, canary;
|
1194 | return __generator(this, function (_a) {
|
1195 | switch (_a.label) {
|
1196 | case 0:
|
1197 | auto = new auto_1.default(__assign({}, defaults, { plugins: [] }));
|
1198 | auto.logger = logger_1.dummyLog();
|
1199 | return [4 , auto.loadConfig()];
|
1200 | case 1:
|
1201 | _a.sent();
|
1202 | auto.git.getSha = function () { return Promise.resolve('abcd'); };
|
1203 | auto.git.getLatestRelease = function () { return Promise.resolve('1.2.3'); };
|
1204 | auto.release.getCommitsInRelease = function () {
|
1205 | return Promise.resolve([
|
1206 | make_commit_from_msg_1.default('Test Commit', {
|
1207 | labels: ['skip-release']
|
1208 | })
|
1209 | ]);
|
1210 | };
|
1211 | canary = jest.fn();
|
1212 | auto.hooks.canary.tap('test', canary);
|
1213 | return [4 , auto.canary()];
|
1214 | case 2:
|
1215 | _a.sent();
|
1216 | expect(canary).toHaveBeenCalledWith(semver_1.default.patch, '.abcd');
|
1217 | return [2 ];
|
1218 | }
|
1219 | });
|
1220 | }); });
|
1221 | });
|
1222 | describe('shipit', function () {
|
1223 | test('should throw when not initialized', function () { return __awaiter(_this, void 0, void 0, function () {
|
1224 | var auto;
|
1225 | return __generator(this, function (_a) {
|
1226 | auto = new auto_1.default(defaults);
|
1227 | auto.logger = logger_1.dummyLog();
|
1228 | expect(auto.shipit()).rejects.toBeTruthy();
|
1229 | return [2 ];
|
1230 | });
|
1231 | }); });
|
1232 | test('should not publish when no latest version found', function () { return __awaiter(_this, void 0, void 0, function () {
|
1233 | var auto, afterShipIt;
|
1234 | return __generator(this, function (_a) {
|
1235 | switch (_a.label) {
|
1236 | case 0:
|
1237 | auto = new auto_1.default(__assign({}, defaults, { plugins: [] }));
|
1238 | auto.logger = logger_1.dummyLog();
|
1239 | return [4 , auto.loadConfig()];
|
1240 | case 1:
|
1241 | _a.sent();
|
1242 | auto.git.getLatestRelease = function () { return Promise.resolve(''); };
|
1243 | auto.release.getSemverBump = function () { return Promise.resolve(semver_1.default.noVersion); };
|
1244 | afterShipIt = jest.fn();
|
1245 | auto.hooks.afterShipIt.tap('test', afterShipIt);
|
1246 | return [4 , auto.shipit()];
|
1247 | case 2:
|
1248 | _a.sent();
|
1249 | expect(afterShipIt).not.toHaveBeenCalled();
|
1250 | return [2 ];
|
1251 | }
|
1252 | });
|
1253 | }); });
|
1254 | test('should publish to latest on base branch', function () { return __awaiter(_this, void 0, void 0, function () {
|
1255 | var auto, afterShipIt;
|
1256 | return __generator(this, function (_a) {
|
1257 | switch (_a.label) {
|
1258 | case 0:
|
1259 | auto = new auto_1.default(__assign({}, defaults, { plugins: [] }));
|
1260 | auto.logger = logger_1.dummyLog();
|
1261 | return [4 , auto.loadConfig()];
|
1262 | case 1:
|
1263 | _a.sent();
|
1264 | auto.git.getLatestRelease = function () { return Promise.resolve('1.2.3'); };
|
1265 | auto.git.publish = jest.fn();
|
1266 | auto.release.getCommitsInRelease = jest.fn();
|
1267 | auto.release.generateReleaseNotes = jest.fn();
|
1268 | auto.release.addToChangelog = jest.fn();
|
1269 | afterShipIt = jest.fn();
|
1270 | auto.hooks.afterShipIt.tap('test', afterShipIt);
|
1271 | return [4 , auto.shipit()];
|
1272 | case 2:
|
1273 | _a.sent();
|
1274 | expect(afterShipIt).toHaveBeenCalled();
|
1275 | return [2 ];
|
1276 | }
|
1277 | });
|
1278 | }); });
|
1279 | test('should skip publish in dry run', function () { return __awaiter(_this, void 0, void 0, function () {
|
1280 | var auto, version;
|
1281 | return __generator(this, function (_a) {
|
1282 | switch (_a.label) {
|
1283 | case 0:
|
1284 | auto = new auto_1.default(__assign({}, defaults, { plugins: [] }));
|
1285 | auto.logger = logger_1.dummyLog();
|
1286 | return [4 , auto.loadConfig()];
|
1287 | case 1:
|
1288 | _a.sent();
|
1289 | auto.git.getLatestRelease = function () { return Promise.resolve('1.2.3'); };
|
1290 | auto.git.publish = jest.fn();
|
1291 | auto.release.getCommitsInRelease = jest.fn();
|
1292 | auto.release.generateReleaseNotes = jest.fn();
|
1293 | auto.release.addToChangelog = jest.fn();
|
1294 | version = jest.fn();
|
1295 | auto.hooks.version.tap('test', version);
|
1296 | return [4 , auto.shipit({ dryRun: true })];
|
1297 | case 2:
|
1298 | _a.sent();
|
1299 | expect(version).not.toHaveBeenCalled();
|
1300 | return [2 ];
|
1301 | }
|
1302 | });
|
1303 | }); });
|
1304 | });
|
1305 | });
|
1306 | describe('hooks', function () {
|
1307 | test('should be able to modifyConfig', function () { return __awaiter(_this, void 0, void 0, function () {
|
1308 | var auto;
|
1309 | return __generator(this, function (_a) {
|
1310 | switch (_a.label) {
|
1311 | case 0:
|
1312 | auto = new auto_1.default(defaults);
|
1313 | auto.logger = logger_1.dummyLog();
|
1314 | auto.hooks.modifyConfig.tap('test', function (testConfig) {
|
1315 | testConfig.labels.released = {
|
1316 | name: 'released',
|
1317 | description: 'This issue/pull request has been released'
|
1318 | };
|
1319 | return testConfig;
|
1320 | });
|
1321 | return [4 , auto.loadConfig()];
|
1322 | case 1:
|
1323 | _a.sent();
|
1324 | expect(auto.labels.released).toEqual({
|
1325 | description: 'This issue/pull request has been released',
|
1326 | name: 'released'
|
1327 | });
|
1328 | return [2 ];
|
1329 | }
|
1330 | });
|
1331 | }); });
|
1332 | describe('logParse', function () {
|
1333 | test('should be able to tap parseCommit', function () { return __awaiter(_this, void 0, void 0, function () {
|
1334 | var auto;
|
1335 | var _this = this;
|
1336 | return __generator(this, function (_a) {
|
1337 | switch (_a.label) {
|
1338 | case 0:
|
1339 | auto = new auto_1.default(defaults);
|
1340 | auto.logger = logger_1.dummyLog();
|
1341 | auto.hooks.onCreateLogParse.tap('test', function (logParse) {
|
1342 | logParse.hooks.parseCommit.tap('test parse', function (commit) {
|
1343 | commit.labels = [auto.semVerLabels.get(semver_1.default.major)];
|
1344 | return commit;
|
1345 | });
|
1346 | });
|
1347 | return [4 , auto.loadConfig()];
|
1348 | case 1:
|
1349 | _a.sent();
|
1350 | auto.git.getLatestRelease = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
1351 | return [2 , Promise.resolve('1.0.0')];
|
1352 | }); }); };
|
1353 | console.log = jest.fn();
|
1354 | return [4 , auto.version()];
|
1355 | case 2:
|
1356 | _a.sent();
|
1357 | expect(console.log).toHaveBeenCalledWith('major');
|
1358 | return [2 ];
|
1359 | }
|
1360 | });
|
1361 | }); });
|
1362 | test('should be able to tap omitCommit', function () { return __awaiter(_this, void 0, void 0, function () {
|
1363 | var auto;
|
1364 | var _this = this;
|
1365 | return __generator(this, function (_a) {
|
1366 | switch (_a.label) {
|
1367 | case 0:
|
1368 | auto = new auto_1.default(defaults);
|
1369 | auto.logger = logger_1.dummyLog();
|
1370 | auto.hooks.onCreateLogParse.tap('test', function (logParse) {
|
1371 | logParse.hooks.parseCommit.tap('test parse', function (commit) {
|
1372 | commit.labels = [auto.semVerLabels.get(semver_1.default.major)];
|
1373 | return commit;
|
1374 | });
|
1375 | });
|
1376 | auto.hooks.onCreateLogParse.tap('test', function (logParse) {
|
1377 | logParse.hooks.omitCommit.tap('test omit', function (commit) {
|
1378 | if (commit.labels.includes('major')) {
|
1379 | return true;
|
1380 | }
|
1381 | });
|
1382 | });
|
1383 | return [4 , auto.loadConfig()];
|
1384 | case 1:
|
1385 | _a.sent();
|
1386 | auto.git.getLatestRelease = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
1387 | return [2 , Promise.resolve('1.0.0')];
|
1388 | }); }); };
|
1389 | console.log = jest.fn();
|
1390 | return [4 , auto.version()];
|
1391 | case 2:
|
1392 | _a.sent();
|
1393 | expect(console.log).toHaveBeenCalledWith('patch');
|
1394 | return [2 ];
|
1395 | }
|
1396 | });
|
1397 | }); });
|
1398 | });
|
1399 | });
|
1400 |
|
\ | No newline at end of file |