@redocly/cli 1.18.0 → 1.19.0
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.
- package/CHANGELOG.md +22 -0
- package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
- package/lib/__mocks__/@redocly/openapi-core.js +1 -0
- package/lib/__mocks__/fs.d.ts +0 -1
- package/lib/__mocks__/perf_hooks.d.ts +0 -1
- package/lib/__mocks__/redoc.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +21 -23
- package/lib/__tests__/commands/bundle.test.js +21 -30
- package/lib/__tests__/commands/join.test.js +101 -70
- package/lib/__tests__/commands/lint.test.js +54 -54
- package/lib/__tests__/commands/push-region.test.js +24 -25
- package/lib/__tests__/commands/push.test.js +269 -170
- package/lib/__tests__/fetch-with-timeout.test.js +3 -12
- package/lib/__tests__/fixtures/config.d.ts +0 -1
- package/lib/__tests__/utils.test.js +32 -37
- package/lib/__tests__/wrapper.test.js +31 -20
- package/lib/cms/api/__tests__/api.client.test.js +29 -38
- package/lib/cms/api/api-client.d.ts +0 -2
- package/lib/cms/api/api-client.js +106 -127
- package/lib/cms/api/api-keys.js +1 -2
- package/lib/cms/api/domains.js +1 -2
- package/lib/cms/commands/__tests__/push-status.test.js +251 -162
- package/lib/cms/commands/__tests__/push.test.js +120 -102
- package/lib/cms/commands/__tests__/utils.test.js +12 -21
- package/lib/cms/commands/push-status.d.ts +3 -2
- package/lib/cms/commands/push-status.js +94 -106
- package/lib/cms/commands/push.d.ts +3 -2
- package/lib/cms/commands/push.js +66 -75
- package/lib/cms/commands/utils.js +20 -34
- package/lib/commands/build-docs/index.d.ts +2 -2
- package/lib/commands/build-docs/index.js +8 -17
- package/lib/commands/build-docs/utils.js +26 -38
- package/lib/commands/bundle.d.ts +2 -2
- package/lib/commands/bundle.js +70 -94
- package/lib/commands/join.d.ts +2 -2
- package/lib/commands/join.js +377 -390
- package/lib/commands/lint.d.ts +2 -2
- package/lib/commands/lint.js +70 -78
- package/lib/commands/login.d.ts +3 -2
- package/lib/commands/login.js +9 -21
- package/lib/commands/preview-docs/index.d.ts +2 -2
- package/lib/commands/preview-docs/index.js +92 -106
- package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
- package/lib/commands/preview-docs/preview-server/server.d.ts +0 -3
- package/lib/commands/preview-docs/preview-server/server.js +6 -6
- package/lib/commands/preview-project/index.d.ts +2 -1
- package/lib/commands/preview-project/index.js +5 -14
- package/lib/commands/push.d.ts +8 -11
- package/lib/commands/push.js +177 -195
- package/lib/commands/split/__tests__/index.test.js +31 -25
- package/lib/commands/split/index.d.ts +2 -1
- package/lib/commands/split/index.js +22 -35
- package/lib/commands/stats.d.ts +2 -2
- package/lib/commands/stats.js +34 -45
- package/lib/index.js +32 -46
- package/lib/types.d.ts +2 -2
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
- package/lib/utils/fetch-with-timeout.js +7 -12
- package/lib/utils/getCommandNameFromArgs.js +2 -4
- package/lib/utils/js-utils.js +6 -7
- package/lib/utils/miscellaneous.d.ts +9 -5
- package/lib/utils/miscellaneous.js +150 -160
- package/lib/utils/update-version-notifier.js +4 -13
- package/lib/wrapper.d.ts +9 -2
- package/lib/wrapper.js +27 -16
- package/package.json +5 -3
- package/src/__mocks__/@redocly/openapi-core.ts +1 -0
- package/src/__tests__/commands/build-docs.test.ts +5 -4
- package/src/__tests__/commands/join.test.ts +51 -51
- package/src/__tests__/commands/push-region.test.ts +10 -8
- package/src/__tests__/commands/push.test.ts +127 -102
- package/src/__tests__/utils.test.ts +1 -0
- package/src/__tests__/wrapper.test.ts +24 -2
- package/src/cms/commands/__tests__/push-status.test.ts +70 -56
- package/src/cms/commands/__tests__/push.test.ts +30 -24
- package/src/cms/commands/push-status.ts +8 -7
- package/src/cms/commands/push.ts +19 -13
- package/src/commands/build-docs/index.ts +10 -5
- package/src/commands/bundle.ts +14 -6
- package/src/commands/join.ts +10 -6
- package/src/commands/lint.ts +20 -9
- package/src/commands/login.ts +4 -2
- package/src/commands/preview-docs/index.ts +6 -1
- package/src/commands/preview-project/index.ts +5 -4
- package/src/commands/push.ts +14 -16
- package/src/commands/split/__tests__/index.test.ts +17 -6
- package/src/commands/split/index.ts +6 -4
- package/src/commands/stats.ts +4 -2
- package/src/utils/miscellaneous.ts +55 -26
- package/src/wrapper.ts +37 -11
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const push_status_1 = require("../push-status");
|
|
13
4
|
const remotes = {
|
|
@@ -22,9 +13,12 @@ jest.mock('colorette', () => ({
|
|
|
22
13
|
magenta: (str) => str,
|
|
23
14
|
cyan: (str) => str,
|
|
24
15
|
}));
|
|
25
|
-
jest.mock('../../api', () => (
|
|
16
|
+
jest.mock('../../api', () => ({
|
|
17
|
+
...jest.requireActual('../../api'),
|
|
18
|
+
ReuniteApiClient: jest.fn().mockImplementation(function (...args) {
|
|
26
19
|
this.remotes = remotes;
|
|
27
|
-
})
|
|
20
|
+
}),
|
|
21
|
+
}));
|
|
28
22
|
jest.mock('@redocly/openapi-core', () => ({
|
|
29
23
|
pause: jest.requireActual('@redocly/openapi-core').pause,
|
|
30
24
|
}));
|
|
@@ -80,42 +74,54 @@ describe('handlePushStatus()', () => {
|
|
|
80
74
|
afterEach(() => {
|
|
81
75
|
jest.clearAllMocks();
|
|
82
76
|
});
|
|
83
|
-
it('should throw error if organization not provided', () =>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
77
|
+
it('should throw error if organization not provided', async () => {
|
|
78
|
+
await expect((0, push_status_1.handlePushStatus)({
|
|
79
|
+
argv: {
|
|
80
|
+
domain: 'test-domain',
|
|
81
|
+
organization: '',
|
|
82
|
+
project: 'test-project',
|
|
83
|
+
pushId: 'test-push-id',
|
|
84
|
+
},
|
|
85
|
+
config: mockConfig,
|
|
86
|
+
version: 'cli-version',
|
|
87
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`"No organization provided, please use --organization option or specify the 'organization' field in the config file."`);
|
|
90
88
|
expect(process.stderr.write).toHaveBeenCalledWith(`No organization provided, please use --organization option or specify the 'organization' field in the config file.` +
|
|
91
89
|
'\n\n');
|
|
92
|
-
})
|
|
93
|
-
it('should print success push status for preview-build', () =>
|
|
90
|
+
});
|
|
91
|
+
it('should print success push status for preview-build', async () => {
|
|
94
92
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
95
93
|
remotes.getPush.mockResolvedValueOnce(pushResponseStub);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
await (0, push_status_1.handlePushStatus)({
|
|
95
|
+
argv: {
|
|
96
|
+
domain: 'test-domain',
|
|
97
|
+
organization: 'test-org',
|
|
98
|
+
project: 'test-project',
|
|
99
|
+
pushId: 'test-push-id',
|
|
100
|
+
},
|
|
101
|
+
config: mockConfig,
|
|
102
|
+
version: 'cli-version',
|
|
103
|
+
});
|
|
102
104
|
expect(process.stdout.write).toHaveBeenCalledTimes(1);
|
|
103
105
|
expect(process.stdout.write).toHaveBeenCalledWith('🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n');
|
|
104
|
-
})
|
|
105
|
-
it('should print success push status for preview and production builds', () =>
|
|
106
|
+
});
|
|
107
|
+
it('should print success push status for preview and production builds', async () => {
|
|
106
108
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
107
|
-
remotes.getPush.mockResolvedValue(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: true });
|
|
110
|
+
await (0, push_status_1.handlePushStatus)({
|
|
111
|
+
argv: {
|
|
112
|
+
domain: 'test-domain',
|
|
113
|
+
organization: 'test-org',
|
|
114
|
+
project: 'test-project',
|
|
115
|
+
pushId: 'test-push-id',
|
|
116
|
+
},
|
|
117
|
+
config: mockConfig,
|
|
118
|
+
version: 'cli-version',
|
|
119
|
+
});
|
|
114
120
|
expect(process.stdout.write).toHaveBeenCalledTimes(2);
|
|
115
121
|
expect(process.stdout.write).toHaveBeenCalledWith('🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n');
|
|
116
122
|
expect(process.stdout.write).toHaveBeenCalledWith('🚀 Production deploy success.\nProduction URL: https://production-test-url\n');
|
|
117
|
-
})
|
|
118
|
-
it('should print failed push status for preview build', () =>
|
|
123
|
+
});
|
|
124
|
+
it('should print failed push status for preview build', async () => {
|
|
119
125
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
120
126
|
remotes.getPush.mockResolvedValue({
|
|
121
127
|
isOutdated: false,
|
|
@@ -124,18 +130,22 @@ describe('handlePushStatus()', () => {
|
|
|
124
130
|
preview: { deploy: { status: 'failed', url: 'https://preview-test-url' }, scorecard: [] },
|
|
125
131
|
},
|
|
126
132
|
});
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
await expect((0, push_status_1.handlePushStatus)({
|
|
134
|
+
argv: {
|
|
135
|
+
domain: 'test-domain',
|
|
136
|
+
organization: 'test-org',
|
|
137
|
+
project: 'test-project',
|
|
138
|
+
pushId: 'test-push-id',
|
|
139
|
+
},
|
|
140
|
+
config: mockConfig,
|
|
141
|
+
version: 'cli-version',
|
|
142
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
133
143
|
"❌ Preview deploy fail.
|
|
134
144
|
Preview URL: https://preview-test-url"
|
|
135
145
|
`);
|
|
136
146
|
expect(process.stderr.write).toHaveBeenCalledWith('❌ Preview deploy fail.\nPreview URL: https://preview-test-url' + '\n\n');
|
|
137
|
-
})
|
|
138
|
-
it('should print success push status for preview build and print scorecards', () =>
|
|
147
|
+
});
|
|
148
|
+
it('should print success push status for preview build and print scorecards', async () => {
|
|
139
149
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
140
150
|
remotes.getPush.mockResolvedValue({
|
|
141
151
|
isOutdated: false,
|
|
@@ -154,19 +164,23 @@ describe('handlePushStatus()', () => {
|
|
|
154
164
|
},
|
|
155
165
|
},
|
|
156
166
|
});
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
167
|
+
await (0, push_status_1.handlePushStatus)({
|
|
168
|
+
argv: {
|
|
169
|
+
domain: 'test-domain',
|
|
170
|
+
organization: 'test-org',
|
|
171
|
+
project: 'test-project',
|
|
172
|
+
pushId: 'test-push-id',
|
|
173
|
+
},
|
|
174
|
+
config: mockConfig,
|
|
175
|
+
version: 'cli-version',
|
|
176
|
+
});
|
|
163
177
|
expect(process.stdout.write).toHaveBeenCalledTimes(4);
|
|
164
178
|
expect(process.stdout.write).toHaveBeenCalledWith('🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n');
|
|
165
179
|
expect(process.stdout.write).toHaveBeenCalledWith('\nScorecard:');
|
|
166
180
|
expect(process.stdout.write).toHaveBeenCalledWith('\n Name: test-name\n Status: success\n URL: test-url\n Description: test-description\n');
|
|
167
181
|
expect(process.stdout.write).toHaveBeenCalledWith('\n');
|
|
168
|
-
})
|
|
169
|
-
it('should print message if there is no changes', () =>
|
|
182
|
+
});
|
|
183
|
+
it('should print message if there is no changes', async () => {
|
|
170
184
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
171
185
|
remotes.getPush.mockResolvedValueOnce({
|
|
172
186
|
isOutdated: false,
|
|
@@ -179,25 +193,33 @@ describe('handlePushStatus()', () => {
|
|
|
179
193
|
},
|
|
180
194
|
},
|
|
181
195
|
});
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
organization: 'test-org',
|
|
185
|
-
project: 'test-project',
|
|
186
|
-
pushId: 'test-push-id',
|
|
187
|
-
wait: true,
|
|
188
|
-
}, mockConfig);
|
|
189
|
-
expect(process.stderr.write).toHaveBeenCalledWith('Files not added to your project. Reason: no changes.\n');
|
|
190
|
-
}));
|
|
191
|
-
describe('return value', () => {
|
|
192
|
-
it('should return preview deployment info', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
-
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
194
|
-
remotes.getPush.mockResolvedValue(Object.assign(Object.assign({}, pushResponseStub), { isMainBranch: false }));
|
|
195
|
-
const result = yield (0, push_status_1.handlePushStatus)({
|
|
196
|
+
await (0, push_status_1.handlePushStatus)({
|
|
197
|
+
argv: {
|
|
196
198
|
domain: 'test-domain',
|
|
197
199
|
organization: 'test-org',
|
|
198
200
|
project: 'test-project',
|
|
199
201
|
pushId: 'test-push-id',
|
|
200
|
-
|
|
202
|
+
wait: true,
|
|
203
|
+
},
|
|
204
|
+
config: mockConfig,
|
|
205
|
+
version: 'cli-version',
|
|
206
|
+
});
|
|
207
|
+
expect(process.stderr.write).toHaveBeenCalledWith('Files not added to your project. Reason: no changes.\n');
|
|
208
|
+
});
|
|
209
|
+
describe('return value', () => {
|
|
210
|
+
it('should return preview deployment info', async () => {
|
|
211
|
+
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
212
|
+
remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: false });
|
|
213
|
+
const result = await (0, push_status_1.handlePushStatus)({
|
|
214
|
+
argv: {
|
|
215
|
+
domain: 'test-domain',
|
|
216
|
+
organization: 'test-org',
|
|
217
|
+
project: 'test-project',
|
|
218
|
+
pushId: 'test-push-id',
|
|
219
|
+
},
|
|
220
|
+
config: mockConfig,
|
|
221
|
+
version: 'cli-version',
|
|
222
|
+
});
|
|
201
223
|
expect(result).toEqual({
|
|
202
224
|
preview: {
|
|
203
225
|
deploy: {
|
|
@@ -209,16 +231,20 @@ describe('handlePushStatus()', () => {
|
|
|
209
231
|
production: null,
|
|
210
232
|
commit: commitStub,
|
|
211
233
|
});
|
|
212
|
-
})
|
|
213
|
-
it('should return preview and production deployment info', () =>
|
|
234
|
+
});
|
|
235
|
+
it('should return preview and production deployment info', async () => {
|
|
214
236
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
215
|
-
remotes.getPush.mockResolvedValue(
|
|
216
|
-
const result =
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
237
|
+
remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: true });
|
|
238
|
+
const result = await (0, push_status_1.handlePushStatus)({
|
|
239
|
+
argv: {
|
|
240
|
+
domain: 'test-domain',
|
|
241
|
+
organization: 'test-org',
|
|
242
|
+
project: 'test-project',
|
|
243
|
+
pushId: 'test-push-id',
|
|
244
|
+
},
|
|
245
|
+
config: mockConfig,
|
|
246
|
+
version: 'cli-version',
|
|
247
|
+
});
|
|
222
248
|
expect(result).toEqual({
|
|
223
249
|
preview: {
|
|
224
250
|
deploy: {
|
|
@@ -236,37 +262,50 @@ describe('handlePushStatus()', () => {
|
|
|
236
262
|
},
|
|
237
263
|
commit: commitStub,
|
|
238
264
|
});
|
|
239
|
-
})
|
|
265
|
+
});
|
|
240
266
|
});
|
|
241
267
|
describe('"wait" option', () => {
|
|
242
|
-
it('should wait for preview "success" deployment status', () =>
|
|
268
|
+
it('should wait for preview "success" deployment status', async () => {
|
|
243
269
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
244
|
-
remotes.getPush.mockResolvedValueOnce(
|
|
270
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
271
|
+
...pushResponseStub,
|
|
272
|
+
status: {
|
|
245
273
|
preview: {
|
|
246
274
|
deploy: { status: 'pending', url: 'https://preview-test-url' },
|
|
247
275
|
scorecard: [],
|
|
248
276
|
},
|
|
249
|
-
}
|
|
250
|
-
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
280
|
+
...pushResponseStub,
|
|
281
|
+
status: {
|
|
251
282
|
preview: {
|
|
252
283
|
deploy: { status: 'running', url: 'https://preview-test-url' },
|
|
253
284
|
scorecard: [],
|
|
254
285
|
},
|
|
255
|
-
}
|
|
256
|
-
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
289
|
+
...pushResponseStub,
|
|
290
|
+
status: {
|
|
257
291
|
preview: {
|
|
258
292
|
deploy: { status: 'success', url: 'https://preview-test-url' },
|
|
259
293
|
scorecard: [],
|
|
260
294
|
},
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
const result = await (0, push_status_1.handlePushStatus)({
|
|
298
|
+
argv: {
|
|
299
|
+
domain: 'test-domain',
|
|
300
|
+
organization: 'test-org',
|
|
301
|
+
project: 'test-project',
|
|
302
|
+
pushId: 'test-push-id',
|
|
303
|
+
'retry-interval': 0.5, // 500 ms
|
|
304
|
+
wait: true,
|
|
305
|
+
},
|
|
306
|
+
config: mockConfig,
|
|
307
|
+
version: 'cli-version',
|
|
308
|
+
});
|
|
270
309
|
expect(result).toEqual({
|
|
271
310
|
preview: {
|
|
272
311
|
deploy: {
|
|
@@ -278,10 +317,13 @@ describe('handlePushStatus()', () => {
|
|
|
278
317
|
production: null,
|
|
279
318
|
commit: commitStub,
|
|
280
319
|
});
|
|
281
|
-
})
|
|
282
|
-
it('should wait for production "success" status after preview "success" status', () =>
|
|
320
|
+
});
|
|
321
|
+
it('should wait for production "success" status after preview "success" status', async () => {
|
|
283
322
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
284
|
-
remotes.getPush.mockResolvedValueOnce(
|
|
323
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
324
|
+
...pushResponseStub,
|
|
325
|
+
isMainBranch: true,
|
|
326
|
+
status: {
|
|
285
327
|
preview: {
|
|
286
328
|
deploy: { status: 'success', url: 'https://preview-test-url' },
|
|
287
329
|
scorecard: [],
|
|
@@ -290,8 +332,12 @@ describe('handlePushStatus()', () => {
|
|
|
290
332
|
deploy: { status: 'pending', url: 'https://production-test-url' },
|
|
291
333
|
scorecard: [],
|
|
292
334
|
},
|
|
293
|
-
}
|
|
294
|
-
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
338
|
+
...pushResponseStub,
|
|
339
|
+
isMainBranch: true,
|
|
340
|
+
status: {
|
|
295
341
|
preview: {
|
|
296
342
|
deploy: { status: 'success', url: 'https://preview-test-url' },
|
|
297
343
|
scorecard: [],
|
|
@@ -300,8 +346,12 @@ describe('handlePushStatus()', () => {
|
|
|
300
346
|
deploy: { status: 'running', url: 'https://production-test-url' },
|
|
301
347
|
scorecard: [],
|
|
302
348
|
},
|
|
303
|
-
}
|
|
304
|
-
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
352
|
+
...pushResponseStub,
|
|
353
|
+
isMainBranch: true,
|
|
354
|
+
status: {
|
|
305
355
|
preview: {
|
|
306
356
|
deploy: { status: 'success', url: 'https://preview-test-url' },
|
|
307
357
|
scorecard: [],
|
|
@@ -310,15 +360,20 @@ describe('handlePushStatus()', () => {
|
|
|
310
360
|
deploy: { status: 'success', url: 'https://production-test-url' },
|
|
311
361
|
scorecard: [],
|
|
312
362
|
},
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
const result = await (0, push_status_1.handlePushStatus)({
|
|
366
|
+
argv: {
|
|
367
|
+
domain: 'test-domain',
|
|
368
|
+
organization: 'test-org',
|
|
369
|
+
project: 'test-project',
|
|
370
|
+
pushId: 'test-push-id',
|
|
371
|
+
'retry-interval': 0.5, // 500 ms
|
|
372
|
+
wait: true,
|
|
373
|
+
},
|
|
374
|
+
config: mockConfig,
|
|
375
|
+
version: 'cli-version',
|
|
376
|
+
});
|
|
322
377
|
expect(result).toEqual({
|
|
323
378
|
preview: {
|
|
324
379
|
deploy: { status: 'success', url: 'https://preview-test-url' },
|
|
@@ -330,43 +385,57 @@ describe('handlePushStatus()', () => {
|
|
|
330
385
|
},
|
|
331
386
|
commit: commitStub,
|
|
332
387
|
});
|
|
333
|
-
})
|
|
388
|
+
});
|
|
334
389
|
});
|
|
335
390
|
describe('"continue-on-deploy-failures" option', () => {
|
|
336
|
-
it('should throw error if option value is false', () =>
|
|
391
|
+
it('should throw error if option value is false', async () => {
|
|
337
392
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
338
|
-
remotes.getPush.mockResolvedValueOnce(
|
|
393
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
394
|
+
...pushResponseStub,
|
|
395
|
+
status: {
|
|
339
396
|
preview: {
|
|
340
397
|
deploy: { status: 'failed', url: 'https://preview-test-url' },
|
|
341
398
|
scorecard: [],
|
|
342
399
|
},
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
await expect((0, push_status_1.handlePushStatus)({
|
|
403
|
+
argv: {
|
|
404
|
+
domain: 'test-domain',
|
|
405
|
+
organization: 'test-org',
|
|
406
|
+
project: 'test-project',
|
|
407
|
+
pushId: 'test-push-id',
|
|
408
|
+
'continue-on-deploy-failures': false,
|
|
409
|
+
},
|
|
410
|
+
config: mockConfig,
|
|
411
|
+
version: 'cli-version',
|
|
412
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
351
413
|
"❌ Preview deploy fail.
|
|
352
414
|
Preview URL: https://preview-test-url"
|
|
353
415
|
`);
|
|
354
|
-
})
|
|
355
|
-
it('should not throw error if option value is true', () =>
|
|
416
|
+
});
|
|
417
|
+
it('should not throw error if option value is true', async () => {
|
|
356
418
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
357
|
-
remotes.getPush.mockResolvedValueOnce(
|
|
419
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
420
|
+
...pushResponseStub,
|
|
421
|
+
status: {
|
|
358
422
|
preview: {
|
|
359
423
|
deploy: { status: 'failed', url: 'https://preview-test-url' },
|
|
360
424
|
scorecard: [],
|
|
361
425
|
},
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
await expect((0, push_status_1.handlePushStatus)({
|
|
429
|
+
argv: {
|
|
430
|
+
domain: 'test-domain',
|
|
431
|
+
organization: 'test-org',
|
|
432
|
+
project: 'test-project',
|
|
433
|
+
pushId: 'test-push-id',
|
|
434
|
+
'continue-on-deploy-failures': true,
|
|
435
|
+
},
|
|
436
|
+
config: mockConfig,
|
|
437
|
+
version: 'cli-version',
|
|
438
|
+
})).resolves.toStrictEqual({
|
|
370
439
|
preview: {
|
|
371
440
|
deploy: { status: 'failed', url: 'https://preview-test-url' },
|
|
372
441
|
scorecard: [],
|
|
@@ -374,39 +443,52 @@ describe('handlePushStatus()', () => {
|
|
|
374
443
|
production: null,
|
|
375
444
|
commit: commitStub,
|
|
376
445
|
});
|
|
377
|
-
})
|
|
446
|
+
});
|
|
378
447
|
});
|
|
379
448
|
describe('"onRetry" callback', () => {
|
|
380
|
-
it('should be called when command retries request to API in wait mode for preview deploy', () =>
|
|
449
|
+
it('should be called when command retries request to API in wait mode for preview deploy', async () => {
|
|
381
450
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
382
|
-
remotes.getPush.mockResolvedValueOnce(
|
|
451
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
452
|
+
...pushResponseStub,
|
|
453
|
+
status: {
|
|
383
454
|
preview: {
|
|
384
455
|
deploy: { status: 'pending', url: 'https://preview-test-url' },
|
|
385
456
|
scorecard: [],
|
|
386
457
|
},
|
|
387
|
-
}
|
|
388
|
-
|
|
458
|
+
},
|
|
459
|
+
});
|
|
460
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
461
|
+
...pushResponseStub,
|
|
462
|
+
status: {
|
|
389
463
|
preview: {
|
|
390
464
|
deploy: { status: 'running', url: 'https://preview-test-url' },
|
|
391
465
|
scorecard: [],
|
|
392
466
|
},
|
|
393
|
-
}
|
|
394
|
-
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
remotes.getPush.mockResolvedValueOnce({
|
|
470
|
+
...pushResponseStub,
|
|
471
|
+
status: {
|
|
395
472
|
preview: {
|
|
396
473
|
deploy: { status: 'success', url: 'https://preview-test-url' },
|
|
397
474
|
scorecard: [],
|
|
398
475
|
},
|
|
399
|
-
}
|
|
476
|
+
},
|
|
477
|
+
});
|
|
400
478
|
const onRetrySpy = jest.fn();
|
|
401
|
-
const result =
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
479
|
+
const result = await (0, push_status_1.handlePushStatus)({
|
|
480
|
+
argv: {
|
|
481
|
+
domain: 'test-domain',
|
|
482
|
+
organization: 'test-org',
|
|
483
|
+
project: 'test-project',
|
|
484
|
+
pushId: 'test-push-id',
|
|
485
|
+
wait: true,
|
|
486
|
+
'retry-interval': 0.5, // 500 ms
|
|
487
|
+
onRetry: onRetrySpy,
|
|
488
|
+
},
|
|
489
|
+
config: mockConfig,
|
|
490
|
+
version: 'cli-version',
|
|
491
|
+
});
|
|
410
492
|
expect(onRetrySpy).toBeCalledTimes(2);
|
|
411
493
|
// first retry
|
|
412
494
|
expect(onRetrySpy).toHaveBeenNthCalledWith(1, {
|
|
@@ -444,30 +526,37 @@ describe('handlePushStatus()', () => {
|
|
|
444
526
|
production: null,
|
|
445
527
|
commit: commitStub,
|
|
446
528
|
});
|
|
447
|
-
})
|
|
529
|
+
});
|
|
448
530
|
});
|
|
449
531
|
describe('"max-execution-time" option', () => {
|
|
450
|
-
it('should throw error in case "max-execution-time" was exceeded', () =>
|
|
532
|
+
it('should throw error in case "max-execution-time" was exceeded', async () => {
|
|
451
533
|
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
452
534
|
// Stuck deployment simulation
|
|
453
|
-
remotes.getPush.mockResolvedValue(
|
|
535
|
+
remotes.getPush.mockResolvedValue({
|
|
536
|
+
...pushResponseStub,
|
|
537
|
+
status: {
|
|
454
538
|
preview: {
|
|
455
539
|
deploy: { status: 'pending', url: 'https://preview-test-url' },
|
|
456
540
|
scorecard: [],
|
|
457
541
|
},
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
542
|
+
},
|
|
543
|
+
});
|
|
544
|
+
await expect((0, push_status_1.handlePushStatus)({
|
|
545
|
+
argv: {
|
|
546
|
+
domain: 'test-domain',
|
|
547
|
+
organization: 'test-org',
|
|
548
|
+
project: 'test-project',
|
|
549
|
+
pushId: 'test-push-id',
|
|
550
|
+
'retry-interval': 2, // seconds
|
|
551
|
+
'max-execution-time': 1, // seconds
|
|
552
|
+
wait: true,
|
|
553
|
+
},
|
|
554
|
+
config: mockConfig,
|
|
555
|
+
version: 'cli-version',
|
|
556
|
+
})).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
468
557
|
"✗ Failed to get push status. Reason: Timeout exceeded
|
|
469
558
|
"
|
|
470
559
|
`);
|
|
471
|
-
})
|
|
560
|
+
});
|
|
472
561
|
});
|
|
473
562
|
});
|