@redocly/cli 0.0.0-snapshot.1737554067

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +114 -0
  2. package/bin/cli.js +3 -0
  3. package/lib/__mocks__/@redocly/openapi-core.d.ts +99 -0
  4. package/lib/__mocks__/@redocly/openapi-core.js +84 -0
  5. package/lib/__mocks__/documents.d.ts +150 -0
  6. package/lib/__mocks__/documents.js +123 -0
  7. package/lib/__mocks__/fs.d.ts +8 -0
  8. package/lib/__mocks__/fs.js +9 -0
  9. package/lib/__mocks__/perf_hooks.d.ts +3 -0
  10. package/lib/__mocks__/perf_hooks.js +6 -0
  11. package/lib/__mocks__/redoc.d.ts +6 -0
  12. package/lib/__mocks__/redoc.js +5 -0
  13. package/lib/__tests__/commands/build-docs.test.d.ts +1 -0
  14. package/lib/__tests__/commands/build-docs.test.js +54 -0
  15. package/lib/__tests__/commands/bundle.test.d.ts +1 -0
  16. package/lib/__tests__/commands/bundle.test.js +235 -0
  17. package/lib/__tests__/commands/join.test.d.ts +1 -0
  18. package/lib/__tests__/commands/join.test.js +274 -0
  19. package/lib/__tests__/commands/lint.test.d.ts +1 -0
  20. package/lib/__tests__/commands/lint.test.js +149 -0
  21. package/lib/__tests__/commands/push-region.test.d.ts +1 -0
  22. package/lib/__tests__/commands/push-region.test.js +55 -0
  23. package/lib/__tests__/commands/push.test.d.ts +1 -0
  24. package/lib/__tests__/commands/push.test.js +463 -0
  25. package/lib/__tests__/fetch-with-timeout.test.d.ts +1 -0
  26. package/lib/__tests__/fetch-with-timeout.test.js +44 -0
  27. package/lib/__tests__/fixtures/config.d.ts +21 -0
  28. package/lib/__tests__/fixtures/config.js +24 -0
  29. package/lib/__tests__/spinner.test.d.ts +1 -0
  30. package/lib/__tests__/spinner.test.js +43 -0
  31. package/lib/__tests__/utils.test.d.ts +1 -0
  32. package/lib/__tests__/utils.test.js +593 -0
  33. package/lib/__tests__/wrapper.test.d.ts +1 -0
  34. package/lib/__tests__/wrapper.test.js +68 -0
  35. package/lib/cms/api/__tests__/api-keys.test.d.ts +1 -0
  36. package/lib/cms/api/__tests__/api-keys.test.js +26 -0
  37. package/lib/cms/api/__tests__/api.client.test.d.ts +1 -0
  38. package/lib/cms/api/__tests__/api.client.test.js +333 -0
  39. package/lib/cms/api/__tests__/domains.test.d.ts +1 -0
  40. package/lib/cms/api/__tests__/domains.test.js +13 -0
  41. package/lib/cms/api/api-client.d.ts +75 -0
  42. package/lib/cms/api/api-client.js +225 -0
  43. package/lib/cms/api/api-keys.d.ts +1 -0
  44. package/lib/cms/api/api-keys.js +23 -0
  45. package/lib/cms/api/domains.d.ts +1 -0
  46. package/lib/cms/api/domains.js +11 -0
  47. package/lib/cms/api/index.d.ts +3 -0
  48. package/lib/cms/api/index.js +19 -0
  49. package/lib/cms/api/types.d.ts +102 -0
  50. package/lib/cms/api/types.js +2 -0
  51. package/lib/cms/commands/__tests__/push-status.test.d.ts +1 -0
  52. package/lib/cms/commands/__tests__/push-status.test.js +563 -0
  53. package/lib/cms/commands/__tests__/push.test.d.ts +1 -0
  54. package/lib/cms/commands/__tests__/push.test.js +315 -0
  55. package/lib/cms/commands/__tests__/utils.test.d.ts +1 -0
  56. package/lib/cms/commands/__tests__/utils.test.js +51 -0
  57. package/lib/cms/commands/push-status.d.ts +23 -0
  58. package/lib/cms/commands/push-status.js +206 -0
  59. package/lib/cms/commands/push.d.ts +28 -0
  60. package/lib/cms/commands/push.js +142 -0
  61. package/lib/cms/commands/utils.d.ts +25 -0
  62. package/lib/cms/commands/utils.js +46 -0
  63. package/lib/cms/utils.d.ts +2 -0
  64. package/lib/cms/utils.js +6 -0
  65. package/lib/commands/build-docs/index.d.ts +3 -0
  66. package/lib/commands/build-docs/index.js +39 -0
  67. package/lib/commands/build-docs/template.hbs +23 -0
  68. package/lib/commands/build-docs/types.d.ts +23 -0
  69. package/lib/commands/build-docs/types.js +2 -0
  70. package/lib/commands/build-docs/utils.d.ts +7 -0
  71. package/lib/commands/build-docs/utils.js +87 -0
  72. package/lib/commands/bundle.d.ts +14 -0
  73. package/lib/commands/bundle.js +91 -0
  74. package/lib/commands/eject.d.ts +9 -0
  75. package/lib/commands/eject.js +28 -0
  76. package/lib/commands/join.d.ts +11 -0
  77. package/lib/commands/join.js +565 -0
  78. package/lib/commands/lint.d.ts +13 -0
  79. package/lib/commands/lint.js +108 -0
  80. package/lib/commands/login.d.ts +9 -0
  81. package/lib/commands/login.js +23 -0
  82. package/lib/commands/preview-docs/index.d.ts +12 -0
  83. package/lib/commands/preview-docs/index.js +127 -0
  84. package/lib/commands/preview-docs/preview-server/default.hbs +24 -0
  85. package/lib/commands/preview-docs/preview-server/hot.js +59 -0
  86. package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +21 -0
  87. package/lib/commands/preview-docs/preview-server/preview-server.d.ts +5 -0
  88. package/lib/commands/preview-docs/preview-server/preview-server.js +113 -0
  89. package/lib/commands/preview-docs/preview-server/server.d.ts +22 -0
  90. package/lib/commands/preview-docs/preview-server/server.js +85 -0
  91. package/lib/commands/preview-project/constants.d.ts +14 -0
  92. package/lib/commands/preview-project/constants.js +22 -0
  93. package/lib/commands/preview-project/index.d.ts +3 -0
  94. package/lib/commands/preview-project/index.js +56 -0
  95. package/lib/commands/preview-project/types.d.ts +10 -0
  96. package/lib/commands/preview-project/types.js +2 -0
  97. package/lib/commands/push.d.ts +44 -0
  98. package/lib/commands/push.js +295 -0
  99. package/lib/commands/split/__tests__/index.test.d.ts +1 -0
  100. package/lib/commands/split/__tests__/index.test.js +91 -0
  101. package/lib/commands/split/index.d.ts +13 -0
  102. package/lib/commands/split/index.js +259 -0
  103. package/lib/commands/split/types.d.ts +36 -0
  104. package/lib/commands/split/types.js +51 -0
  105. package/lib/commands/stats.d.ts +8 -0
  106. package/lib/commands/stats.js +96 -0
  107. package/lib/commands/translations.d.ts +7 -0
  108. package/lib/commands/translations.js +20 -0
  109. package/lib/index.d.ts +2 -0
  110. package/lib/index.js +733 -0
  111. package/lib/types.d.ts +43 -0
  112. package/lib/types.js +5 -0
  113. package/lib/utils/__mocks__/miscellaneous.d.ts +43 -0
  114. package/lib/utils/__mocks__/miscellaneous.js +24 -0
  115. package/lib/utils/assert-node-version.d.ts +1 -0
  116. package/lib/utils/assert-node-version.js +16 -0
  117. package/lib/utils/fetch-with-timeout.d.ts +7 -0
  118. package/lib/utils/fetch-with-timeout.js +26 -0
  119. package/lib/utils/getCommandNameFromArgs.d.ts +2 -0
  120. package/lib/utils/getCommandNameFromArgs.js +6 -0
  121. package/lib/utils/js-utils.d.ts +5 -0
  122. package/lib/utils/js-utils.js +28 -0
  123. package/lib/utils/miscellaneous.d.ts +81 -0
  124. package/lib/utils/miscellaneous.js +551 -0
  125. package/lib/utils/platform.d.ts +16 -0
  126. package/lib/utils/platform.js +34 -0
  127. package/lib/utils/spinner.d.ts +10 -0
  128. package/lib/utils/spinner.js +42 -0
  129. package/lib/utils/update-version-notifier.d.ts +3 -0
  130. package/lib/utils/update-version-notifier.js +102 -0
  131. package/lib/wrapper.d.ts +11 -0
  132. package/lib/wrapper.js +65 -0
  133. package/package.json +69 -0
@@ -0,0 +1,563 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const push_status_1 = require("../push-status");
4
+ const remotes = {
5
+ getPush: jest.fn(),
6
+ getRemotesList: jest.fn(),
7
+ };
8
+ jest.mock('colorette', () => ({
9
+ green: (str) => str,
10
+ yellow: (str) => str,
11
+ red: (str) => str,
12
+ gray: (str) => str,
13
+ magenta: (str) => str,
14
+ cyan: (str) => str,
15
+ }));
16
+ jest.mock('../../api', () => ({
17
+ ...jest.requireActual('../../api'),
18
+ ReuniteApi: jest.fn().mockImplementation(function (...args) {
19
+ this.remotes = remotes;
20
+ this.reportSunsetWarnings = jest.fn();
21
+ }),
22
+ }));
23
+ jest.mock('@redocly/openapi-core', () => ({
24
+ pause: jest.requireActual('@redocly/openapi-core').pause,
25
+ }));
26
+ describe('handlePushStatus()', () => {
27
+ const mockConfig = { apis: {} };
28
+ const commitStub = {
29
+ message: 'test-commit-message',
30
+ branchName: 'test-branch-name',
31
+ sha: null,
32
+ url: null,
33
+ createdAt: null,
34
+ namespaceId: null,
35
+ repositoryId: null,
36
+ author: {
37
+ name: 'test-author-name',
38
+ email: 'test-author-email',
39
+ image: null,
40
+ },
41
+ statuses: [],
42
+ };
43
+ const pushResponseStub = {
44
+ id: 'test-push-id',
45
+ remoteId: 'test-remote-id',
46
+ replace: false,
47
+ scoutJobId: null,
48
+ uploadedFiles: [],
49
+ commit: commitStub,
50
+ remote: { commits: [] },
51
+ isOutdated: false,
52
+ isMainBranch: false,
53
+ hasChanges: true,
54
+ status: {
55
+ preview: {
56
+ scorecard: [],
57
+ deploy: {
58
+ url: 'https://preview-test-url',
59
+ status: 'success',
60
+ },
61
+ },
62
+ production: {
63
+ scorecard: [],
64
+ deploy: {
65
+ url: 'https://production-test-url',
66
+ status: 'success',
67
+ },
68
+ },
69
+ },
70
+ };
71
+ beforeEach(() => {
72
+ jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
73
+ jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
74
+ });
75
+ afterEach(() => {
76
+ jest.clearAllMocks();
77
+ });
78
+ it('should throw error if organization not provided', async () => {
79
+ await expect((0, push_status_1.handlePushStatus)({
80
+ argv: {
81
+ domain: 'test-domain',
82
+ organization: '',
83
+ project: 'test-project',
84
+ pushId: 'test-push-id',
85
+ },
86
+ config: mockConfig,
87
+ version: 'cli-version',
88
+ })).rejects.toThrowErrorMatchingInlineSnapshot(`"No organization provided, please use --organization option or specify the 'organization' field in the config file."`);
89
+ expect(process.stderr.write).toHaveBeenCalledWith(`No organization provided, please use --organization option or specify the 'organization' field in the config file.` +
90
+ '\n\n');
91
+ });
92
+ it('should print success push status for preview-build', async () => {
93
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
94
+ remotes.getPush.mockResolvedValueOnce(pushResponseStub);
95
+ await (0, push_status_1.handlePushStatus)({
96
+ argv: {
97
+ domain: 'test-domain',
98
+ organization: 'test-org',
99
+ project: 'test-project',
100
+ pushId: 'test-push-id',
101
+ },
102
+ config: mockConfig,
103
+ version: 'cli-version',
104
+ });
105
+ expect(process.stdout.write).toHaveBeenCalledTimes(1);
106
+ expect(process.stdout.write).toHaveBeenCalledWith('🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n');
107
+ });
108
+ it('should print success push status for preview and production builds', async () => {
109
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
110
+ remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: true });
111
+ await (0, push_status_1.handlePushStatus)({
112
+ argv: {
113
+ domain: 'test-domain',
114
+ organization: 'test-org',
115
+ project: 'test-project',
116
+ pushId: 'test-push-id',
117
+ },
118
+ config: mockConfig,
119
+ version: 'cli-version',
120
+ });
121
+ expect(process.stdout.write).toHaveBeenCalledTimes(2);
122
+ expect(process.stdout.write).toHaveBeenCalledWith('🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n');
123
+ expect(process.stdout.write).toHaveBeenCalledWith('🚀 Production deploy success.\nProduction URL: https://production-test-url\n');
124
+ });
125
+ it('should print failed push status for preview build', async () => {
126
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
127
+ remotes.getPush.mockResolvedValue({
128
+ isOutdated: false,
129
+ hasChanges: true,
130
+ status: {
131
+ preview: { deploy: { status: 'failed', url: 'https://preview-test-url' }, scorecard: [] },
132
+ },
133
+ });
134
+ await expect((0, push_status_1.handlePushStatus)({
135
+ argv: {
136
+ domain: 'test-domain',
137
+ organization: 'test-org',
138
+ project: 'test-project',
139
+ pushId: 'test-push-id',
140
+ },
141
+ config: mockConfig,
142
+ version: 'cli-version',
143
+ })).rejects.toThrowErrorMatchingInlineSnapshot(`
144
+ "❌ Preview deploy fail.
145
+ Preview URL: https://preview-test-url"
146
+ `);
147
+ expect(process.stderr.write).toHaveBeenCalledWith('❌ Preview deploy fail.\nPreview URL: https://preview-test-url' + '\n\n');
148
+ });
149
+ it('should print success push status for preview build and print scorecards', async () => {
150
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
151
+ remotes.getPush.mockResolvedValue({
152
+ isOutdated: false,
153
+ hasChanges: true,
154
+ status: {
155
+ preview: {
156
+ deploy: { status: 'success', url: 'https://preview-test-url' },
157
+ scorecard: [
158
+ {
159
+ name: 'test-name',
160
+ status: 'success',
161
+ description: 'test-description',
162
+ url: 'test-url',
163
+ },
164
+ ],
165
+ },
166
+ },
167
+ });
168
+ await (0, push_status_1.handlePushStatus)({
169
+ argv: {
170
+ domain: 'test-domain',
171
+ organization: 'test-org',
172
+ project: 'test-project',
173
+ pushId: 'test-push-id',
174
+ },
175
+ config: mockConfig,
176
+ version: 'cli-version',
177
+ });
178
+ expect(process.stdout.write).toHaveBeenCalledTimes(4);
179
+ expect(process.stdout.write).toHaveBeenCalledWith('🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n');
180
+ expect(process.stdout.write).toHaveBeenCalledWith('\nScorecard:');
181
+ expect(process.stdout.write).toHaveBeenCalledWith('\n Name: test-name\n Status: success\n URL: test-url\n Description: test-description\n');
182
+ expect(process.stdout.write).toHaveBeenCalledWith('\n');
183
+ });
184
+ it('should print message if there is no changes', async () => {
185
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
186
+ remotes.getPush.mockResolvedValueOnce({
187
+ isOutdated: false,
188
+ hasChanges: false,
189
+ status: {
190
+ preview: { deploy: { status: 'skipped', url: 'https://preview-test-url' }, scorecard: [] },
191
+ production: {
192
+ deploy: { status: 'skipped', url: null },
193
+ scorecard: [],
194
+ },
195
+ },
196
+ });
197
+ await (0, push_status_1.handlePushStatus)({
198
+ argv: {
199
+ domain: 'test-domain',
200
+ organization: 'test-org',
201
+ project: 'test-project',
202
+ pushId: 'test-push-id',
203
+ wait: true,
204
+ },
205
+ config: mockConfig,
206
+ version: 'cli-version',
207
+ });
208
+ expect(process.stderr.write).toHaveBeenCalledWith('Files not added to your project. Reason: no changes.\n');
209
+ });
210
+ describe('return value', () => {
211
+ it('should return preview deployment info', async () => {
212
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
213
+ remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: false });
214
+ const result = await (0, push_status_1.handlePushStatus)({
215
+ argv: {
216
+ domain: 'test-domain',
217
+ organization: 'test-org',
218
+ project: 'test-project',
219
+ pushId: 'test-push-id',
220
+ },
221
+ config: mockConfig,
222
+ version: 'cli-version',
223
+ });
224
+ expect(result).toEqual({
225
+ preview: {
226
+ deploy: {
227
+ status: 'success',
228
+ url: 'https://preview-test-url',
229
+ },
230
+ scorecard: [],
231
+ },
232
+ production: null,
233
+ commit: commitStub,
234
+ });
235
+ });
236
+ it('should return preview and production deployment info', async () => {
237
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
238
+ remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: true });
239
+ const result = await (0, push_status_1.handlePushStatus)({
240
+ argv: {
241
+ domain: 'test-domain',
242
+ organization: 'test-org',
243
+ project: 'test-project',
244
+ pushId: 'test-push-id',
245
+ },
246
+ config: mockConfig,
247
+ version: 'cli-version',
248
+ });
249
+ expect(result).toEqual({
250
+ preview: {
251
+ deploy: {
252
+ status: 'success',
253
+ url: 'https://preview-test-url',
254
+ },
255
+ scorecard: [],
256
+ },
257
+ production: {
258
+ deploy: {
259
+ status: 'success',
260
+ url: 'https://production-test-url',
261
+ },
262
+ scorecard: [],
263
+ },
264
+ commit: commitStub,
265
+ });
266
+ });
267
+ });
268
+ describe('"wait" option', () => {
269
+ it('should wait for preview "success" deployment status', async () => {
270
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
271
+ remotes.getPush.mockResolvedValueOnce({
272
+ ...pushResponseStub,
273
+ status: {
274
+ preview: {
275
+ deploy: { status: 'pending', url: 'https://preview-test-url' },
276
+ scorecard: [],
277
+ },
278
+ },
279
+ });
280
+ remotes.getPush.mockResolvedValueOnce({
281
+ ...pushResponseStub,
282
+ status: {
283
+ preview: {
284
+ deploy: { status: 'running', url: 'https://preview-test-url' },
285
+ scorecard: [],
286
+ },
287
+ },
288
+ });
289
+ remotes.getPush.mockResolvedValueOnce({
290
+ ...pushResponseStub,
291
+ status: {
292
+ preview: {
293
+ deploy: { status: 'success', url: 'https://preview-test-url' },
294
+ scorecard: [],
295
+ },
296
+ },
297
+ });
298
+ const result = await (0, push_status_1.handlePushStatus)({
299
+ argv: {
300
+ domain: 'test-domain',
301
+ organization: 'test-org',
302
+ project: 'test-project',
303
+ pushId: 'test-push-id',
304
+ 'retry-interval': 0.5, // 500 ms
305
+ wait: true,
306
+ },
307
+ config: mockConfig,
308
+ version: 'cli-version',
309
+ });
310
+ expect(result).toEqual({
311
+ preview: {
312
+ deploy: {
313
+ status: 'success',
314
+ url: 'https://preview-test-url',
315
+ },
316
+ scorecard: [],
317
+ },
318
+ production: null,
319
+ commit: commitStub,
320
+ });
321
+ });
322
+ it('should wait for production "success" status after preview "success" status', async () => {
323
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
324
+ remotes.getPush.mockResolvedValueOnce({
325
+ ...pushResponseStub,
326
+ isMainBranch: true,
327
+ status: {
328
+ preview: {
329
+ deploy: { status: 'success', url: 'https://preview-test-url' },
330
+ scorecard: [],
331
+ },
332
+ production: {
333
+ deploy: { status: 'pending', url: 'https://production-test-url' },
334
+ scorecard: [],
335
+ },
336
+ },
337
+ });
338
+ remotes.getPush.mockResolvedValueOnce({
339
+ ...pushResponseStub,
340
+ isMainBranch: true,
341
+ status: {
342
+ preview: {
343
+ deploy: { status: 'success', url: 'https://preview-test-url' },
344
+ scorecard: [],
345
+ },
346
+ production: {
347
+ deploy: { status: 'running', url: 'https://production-test-url' },
348
+ scorecard: [],
349
+ },
350
+ },
351
+ });
352
+ remotes.getPush.mockResolvedValueOnce({
353
+ ...pushResponseStub,
354
+ isMainBranch: true,
355
+ status: {
356
+ preview: {
357
+ deploy: { status: 'success', url: 'https://preview-test-url' },
358
+ scorecard: [],
359
+ },
360
+ production: {
361
+ deploy: { status: 'success', url: 'https://production-test-url' },
362
+ scorecard: [],
363
+ },
364
+ },
365
+ });
366
+ const result = await (0, push_status_1.handlePushStatus)({
367
+ argv: {
368
+ domain: 'test-domain',
369
+ organization: 'test-org',
370
+ project: 'test-project',
371
+ pushId: 'test-push-id',
372
+ 'retry-interval': 0.5, // 500 ms
373
+ wait: true,
374
+ },
375
+ config: mockConfig,
376
+ version: 'cli-version',
377
+ });
378
+ expect(result).toEqual({
379
+ preview: {
380
+ deploy: { status: 'success', url: 'https://preview-test-url' },
381
+ scorecard: [],
382
+ },
383
+ production: {
384
+ deploy: { status: 'success', url: 'https://production-test-url' },
385
+ scorecard: [],
386
+ },
387
+ commit: commitStub,
388
+ });
389
+ });
390
+ });
391
+ describe('"continue-on-deploy-failures" option', () => {
392
+ it('should throw error if option value is false', async () => {
393
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
394
+ remotes.getPush.mockResolvedValueOnce({
395
+ ...pushResponseStub,
396
+ status: {
397
+ preview: {
398
+ deploy: { status: 'failed', url: 'https://preview-test-url' },
399
+ scorecard: [],
400
+ },
401
+ },
402
+ });
403
+ await expect((0, push_status_1.handlePushStatus)({
404
+ argv: {
405
+ domain: 'test-domain',
406
+ organization: 'test-org',
407
+ project: 'test-project',
408
+ pushId: 'test-push-id',
409
+ 'continue-on-deploy-failures': false,
410
+ },
411
+ config: mockConfig,
412
+ version: 'cli-version',
413
+ })).rejects.toThrowErrorMatchingInlineSnapshot(`
414
+ "❌ Preview deploy fail.
415
+ Preview URL: https://preview-test-url"
416
+ `);
417
+ });
418
+ it('should not throw error if option value is true', async () => {
419
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
420
+ remotes.getPush.mockResolvedValueOnce({
421
+ ...pushResponseStub,
422
+ status: {
423
+ preview: {
424
+ deploy: { status: 'failed', url: 'https://preview-test-url' },
425
+ scorecard: [],
426
+ },
427
+ },
428
+ });
429
+ await expect((0, push_status_1.handlePushStatus)({
430
+ argv: {
431
+ domain: 'test-domain',
432
+ organization: 'test-org',
433
+ project: 'test-project',
434
+ pushId: 'test-push-id',
435
+ 'continue-on-deploy-failures': true,
436
+ },
437
+ config: mockConfig,
438
+ version: 'cli-version',
439
+ })).resolves.toStrictEqual({
440
+ preview: {
441
+ deploy: { status: 'failed', url: 'https://preview-test-url' },
442
+ scorecard: [],
443
+ },
444
+ production: null,
445
+ commit: commitStub,
446
+ });
447
+ });
448
+ });
449
+ describe('"onRetry" callback', () => {
450
+ it('should be called when command retries request to API in wait mode for preview deploy', async () => {
451
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
452
+ remotes.getPush.mockResolvedValueOnce({
453
+ ...pushResponseStub,
454
+ status: {
455
+ preview: {
456
+ deploy: { status: 'pending', url: 'https://preview-test-url' },
457
+ scorecard: [],
458
+ },
459
+ },
460
+ });
461
+ remotes.getPush.mockResolvedValueOnce({
462
+ ...pushResponseStub,
463
+ status: {
464
+ preview: {
465
+ deploy: { status: 'running', url: 'https://preview-test-url' },
466
+ scorecard: [],
467
+ },
468
+ },
469
+ });
470
+ remotes.getPush.mockResolvedValueOnce({
471
+ ...pushResponseStub,
472
+ status: {
473
+ preview: {
474
+ deploy: { status: 'success', url: 'https://preview-test-url' },
475
+ scorecard: [],
476
+ },
477
+ },
478
+ });
479
+ const onRetrySpy = jest.fn();
480
+ const result = await (0, push_status_1.handlePushStatus)({
481
+ argv: {
482
+ domain: 'test-domain',
483
+ organization: 'test-org',
484
+ project: 'test-project',
485
+ pushId: 'test-push-id',
486
+ wait: true,
487
+ 'retry-interval': 0.5, // 500 ms
488
+ onRetry: onRetrySpy,
489
+ },
490
+ config: mockConfig,
491
+ version: 'cli-version',
492
+ });
493
+ expect(onRetrySpy).toBeCalledTimes(2);
494
+ // first retry
495
+ expect(onRetrySpy).toHaveBeenNthCalledWith(1, {
496
+ preview: {
497
+ deploy: {
498
+ status: 'pending',
499
+ url: 'https://preview-test-url',
500
+ },
501
+ scorecard: [],
502
+ },
503
+ production: null,
504
+ commit: commitStub,
505
+ });
506
+ // second retry
507
+ expect(onRetrySpy).toHaveBeenNthCalledWith(2, {
508
+ preview: {
509
+ deploy: {
510
+ status: 'running',
511
+ url: 'https://preview-test-url',
512
+ },
513
+ scorecard: [],
514
+ },
515
+ production: null,
516
+ commit: commitStub,
517
+ });
518
+ // final result
519
+ expect(result).toEqual({
520
+ preview: {
521
+ deploy: {
522
+ status: 'success',
523
+ url: 'https://preview-test-url',
524
+ },
525
+ scorecard: [],
526
+ },
527
+ production: null,
528
+ commit: commitStub,
529
+ });
530
+ });
531
+ });
532
+ describe('"max-execution-time" option', () => {
533
+ it('should throw error in case "max-execution-time" was exceeded', async () => {
534
+ process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
535
+ // Stuck deployment simulation
536
+ remotes.getPush.mockResolvedValue({
537
+ ...pushResponseStub,
538
+ status: {
539
+ preview: {
540
+ deploy: { status: 'pending', url: 'https://preview-test-url' },
541
+ scorecard: [],
542
+ },
543
+ },
544
+ });
545
+ await expect((0, push_status_1.handlePushStatus)({
546
+ argv: {
547
+ domain: 'test-domain',
548
+ organization: 'test-org',
549
+ project: 'test-project',
550
+ pushId: 'test-push-id',
551
+ 'retry-interval': 2, // seconds
552
+ 'max-execution-time': 1, // seconds
553
+ wait: true,
554
+ },
555
+ config: mockConfig,
556
+ version: 'cli-version',
557
+ })).rejects.toThrowErrorMatchingInlineSnapshot(`
558
+ "✗ Failed to get push status. Reason: Timeout exceeded.
559
+ "
560
+ `);
561
+ });
562
+ });
563
+ });
@@ -0,0 +1 @@
1
+ export {};