@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
|
@@ -25,8 +25,8 @@ describe('push', () => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it('pushes definition', async () => {
|
|
28
|
-
await handlePush(
|
|
29
|
-
{
|
|
28
|
+
await handlePush({
|
|
29
|
+
argv: {
|
|
30
30
|
upsert: true,
|
|
31
31
|
api: 'spec.json',
|
|
32
32
|
destination: '@org/my-api@1.0.0',
|
|
@@ -35,8 +35,9 @@ describe('push', () => {
|
|
|
35
35
|
'job-id': '123',
|
|
36
36
|
'batch-size': 2,
|
|
37
37
|
},
|
|
38
|
-
ConfigFixture as any
|
|
39
|
-
|
|
38
|
+
config: ConfigFixture as any,
|
|
39
|
+
version: 'cli-version',
|
|
40
|
+
});
|
|
40
41
|
|
|
41
42
|
expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(1);
|
|
42
43
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
@@ -55,8 +56,8 @@ describe('push', () => {
|
|
|
55
56
|
});
|
|
56
57
|
|
|
57
58
|
it('fails if jobId value is an empty string', async () => {
|
|
58
|
-
await handlePush(
|
|
59
|
-
{
|
|
59
|
+
await handlePush({
|
|
60
|
+
argv: {
|
|
60
61
|
upsert: true,
|
|
61
62
|
api: 'spec.json',
|
|
62
63
|
destination: '@org/my-api@1.0.0',
|
|
@@ -65,15 +66,16 @@ describe('push', () => {
|
|
|
65
66
|
'job-id': ' ',
|
|
66
67
|
'batch-size': 2,
|
|
67
68
|
},
|
|
68
|
-
ConfigFixture as any
|
|
69
|
-
|
|
69
|
+
config: ConfigFixture as any,
|
|
70
|
+
version: 'cli-version',
|
|
71
|
+
});
|
|
70
72
|
|
|
71
73
|
expect(exitWithError).toBeCalledTimes(1);
|
|
72
74
|
});
|
|
73
75
|
|
|
74
76
|
it('fails if batchSize value is less than 2', async () => {
|
|
75
|
-
await handlePush(
|
|
76
|
-
{
|
|
77
|
+
await handlePush({
|
|
78
|
+
argv: {
|
|
77
79
|
upsert: true,
|
|
78
80
|
api: 'spec.json',
|
|
79
81
|
destination: '@org/my-api@1.0.0',
|
|
@@ -82,8 +84,9 @@ describe('push', () => {
|
|
|
82
84
|
'job-id': '123',
|
|
83
85
|
'batch-size': 1,
|
|
84
86
|
},
|
|
85
|
-
ConfigFixture as any
|
|
86
|
-
|
|
87
|
+
config: ConfigFixture as any,
|
|
88
|
+
version: 'cli-version',
|
|
89
|
+
});
|
|
87
90
|
|
|
88
91
|
expect(exitWithError).toBeCalledTimes(1);
|
|
89
92
|
});
|
|
@@ -95,16 +98,17 @@ describe('push', () => {
|
|
|
95
98
|
return { isDirectory: () => false, size: 10 };
|
|
96
99
|
});
|
|
97
100
|
|
|
98
|
-
await handlePush(
|
|
99
|
-
{
|
|
101
|
+
await handlePush({
|
|
102
|
+
argv: {
|
|
100
103
|
upsert: true,
|
|
101
104
|
api: 'spec.json',
|
|
102
105
|
destination: '@org/my-api@1.0.0',
|
|
103
106
|
public: true,
|
|
104
107
|
files: ['./resouces/1.md', './resouces/2.md'],
|
|
105
108
|
},
|
|
106
|
-
mockConfig
|
|
107
|
-
|
|
109
|
+
config: mockConfig,
|
|
110
|
+
version: 'cli-version',
|
|
111
|
+
});
|
|
108
112
|
|
|
109
113
|
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
110
114
|
filePaths: ['filePath', 'filePath', 'filePath'],
|
|
@@ -119,8 +123,8 @@ describe('push', () => {
|
|
|
119
123
|
});
|
|
120
124
|
|
|
121
125
|
it('push should fail if organization not provided', async () => {
|
|
122
|
-
await handlePush(
|
|
123
|
-
{
|
|
126
|
+
await handlePush({
|
|
127
|
+
argv: {
|
|
124
128
|
upsert: true,
|
|
125
129
|
api: 'spec.json',
|
|
126
130
|
destination: 'test@v1',
|
|
@@ -129,8 +133,9 @@ describe('push', () => {
|
|
|
129
133
|
'job-id': '123',
|
|
130
134
|
'batch-size': 2,
|
|
131
135
|
},
|
|
132
|
-
ConfigFixture as any
|
|
133
|
-
|
|
136
|
+
config: ConfigFixture as any,
|
|
137
|
+
version: 'cli-version',
|
|
138
|
+
});
|
|
134
139
|
|
|
135
140
|
expect(exitWithError).toBeCalledTimes(1);
|
|
136
141
|
expect(exitWithError).toBeCalledWith(
|
|
@@ -140,8 +145,8 @@ describe('push', () => {
|
|
|
140
145
|
|
|
141
146
|
it('push should work with organization in config', async () => {
|
|
142
147
|
const mockConfig = { ...ConfigFixture, organization: 'test_org' } as any;
|
|
143
|
-
await handlePush(
|
|
144
|
-
{
|
|
148
|
+
await handlePush({
|
|
149
|
+
argv: {
|
|
145
150
|
upsert: true,
|
|
146
151
|
api: 'spec.json',
|
|
147
152
|
destination: 'my-api@1.0.0',
|
|
@@ -150,8 +155,9 @@ describe('push', () => {
|
|
|
150
155
|
'job-id': '123',
|
|
151
156
|
'batch-size': 2,
|
|
152
157
|
},
|
|
153
|
-
mockConfig
|
|
154
|
-
|
|
158
|
+
config: mockConfig,
|
|
159
|
+
version: 'cli-version',
|
|
160
|
+
});
|
|
155
161
|
|
|
156
162
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
157
163
|
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
@@ -175,16 +181,17 @@ describe('push', () => {
|
|
|
175
181
|
apis: { 'my-api@1.0.0': { root: 'path' } },
|
|
176
182
|
} as any;
|
|
177
183
|
|
|
178
|
-
await handlePush(
|
|
179
|
-
{
|
|
184
|
+
await handlePush({
|
|
185
|
+
argv: {
|
|
180
186
|
upsert: true,
|
|
181
187
|
branchName: 'test',
|
|
182
188
|
public: true,
|
|
183
189
|
'job-id': '123',
|
|
184
190
|
'batch-size': 2,
|
|
185
191
|
},
|
|
186
|
-
mockConfig
|
|
187
|
-
|
|
192
|
+
config: mockConfig,
|
|
193
|
+
version: 'cli-version',
|
|
194
|
+
});
|
|
188
195
|
|
|
189
196
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
190
197
|
});
|
|
@@ -192,16 +199,17 @@ describe('push', () => {
|
|
|
192
199
|
it('push should fail if apis not provided', async () => {
|
|
193
200
|
const mockConfig = { organization: 'test_org', apis: {} } as any;
|
|
194
201
|
|
|
195
|
-
await handlePush(
|
|
196
|
-
{
|
|
202
|
+
await handlePush({
|
|
203
|
+
argv: {
|
|
197
204
|
upsert: true,
|
|
198
205
|
branchName: 'test',
|
|
199
206
|
public: true,
|
|
200
207
|
'job-id': '123',
|
|
201
208
|
'batch-size': 2,
|
|
202
209
|
},
|
|
203
|
-
mockConfig
|
|
204
|
-
|
|
210
|
+
config: mockConfig,
|
|
211
|
+
version: 'cli-version',
|
|
212
|
+
});
|
|
205
213
|
|
|
206
214
|
expect(exitWithError).toBeCalledTimes(1);
|
|
207
215
|
expect(exitWithError).toHaveBeenLastCalledWith(
|
|
@@ -212,8 +220,8 @@ describe('push', () => {
|
|
|
212
220
|
it('push should fail if destination not provided', async () => {
|
|
213
221
|
const mockConfig = { organization: 'test_org', apis: {} } as any;
|
|
214
222
|
|
|
215
|
-
await handlePush(
|
|
216
|
-
{
|
|
223
|
+
await handlePush({
|
|
224
|
+
argv: {
|
|
217
225
|
upsert: true,
|
|
218
226
|
api: 'api.yaml',
|
|
219
227
|
branchName: 'test',
|
|
@@ -221,8 +229,9 @@ describe('push', () => {
|
|
|
221
229
|
'job-id': '123',
|
|
222
230
|
'batch-size': 2,
|
|
223
231
|
},
|
|
224
|
-
mockConfig
|
|
225
|
-
|
|
232
|
+
config: mockConfig,
|
|
233
|
+
version: 'cli-version',
|
|
234
|
+
});
|
|
226
235
|
|
|
227
236
|
expect(exitWithError).toBeCalledTimes(1);
|
|
228
237
|
expect(exitWithError).toHaveBeenLastCalledWith(
|
|
@@ -233,8 +242,8 @@ describe('push', () => {
|
|
|
233
242
|
it('push should fail if destination format is not valid', async () => {
|
|
234
243
|
const mockConfig = { organization: 'test_org', apis: {} } as any;
|
|
235
244
|
|
|
236
|
-
await handlePush(
|
|
237
|
-
{
|
|
245
|
+
await handlePush({
|
|
246
|
+
argv: {
|
|
238
247
|
upsert: true,
|
|
239
248
|
destination: 'name/v1',
|
|
240
249
|
branchName: 'test',
|
|
@@ -242,8 +251,9 @@ describe('push', () => {
|
|
|
242
251
|
'job-id': '123',
|
|
243
252
|
'batch-size': 2,
|
|
244
253
|
},
|
|
245
|
-
mockConfig
|
|
246
|
-
|
|
254
|
+
config: mockConfig,
|
|
255
|
+
version: 'cli-version',
|
|
256
|
+
});
|
|
247
257
|
|
|
248
258
|
expect(exitWithError).toHaveBeenCalledWith(
|
|
249
259
|
`Destination argument value is not valid, please use the right format: ${yellow(
|
|
@@ -261,8 +271,8 @@ describe('push', () => {
|
|
|
261
271
|
apis: { 'my test api@v1': { root: 'path' } },
|
|
262
272
|
} as any;
|
|
263
273
|
|
|
264
|
-
await handlePush(
|
|
265
|
-
{
|
|
274
|
+
await handlePush({
|
|
275
|
+
argv: {
|
|
266
276
|
upsert: true,
|
|
267
277
|
destination: 'my test api@v1',
|
|
268
278
|
branchName: 'test',
|
|
@@ -270,8 +280,9 @@ describe('push', () => {
|
|
|
270
280
|
'job-id': '123',
|
|
271
281
|
'batch-size': 2,
|
|
272
282
|
},
|
|
273
|
-
mockConfig
|
|
274
|
-
|
|
283
|
+
config: mockConfig,
|
|
284
|
+
version: 'cli-version',
|
|
285
|
+
});
|
|
275
286
|
|
|
276
287
|
expect(encodeURIComponentSpy).toHaveReturnedWith('my%20test%20api');
|
|
277
288
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
@@ -281,130 +292,144 @@ describe('push', () => {
|
|
|
281
292
|
describe('transformPush', () => {
|
|
282
293
|
it('should adapt the existing syntax', () => {
|
|
283
294
|
const cb = jest.fn();
|
|
284
|
-
transformPush(cb)(
|
|
285
|
-
{
|
|
295
|
+
transformPush(cb)({
|
|
296
|
+
argv: {
|
|
286
297
|
apis: ['openapi.yaml', '@testing_org/main@v1'],
|
|
287
298
|
},
|
|
288
|
-
{} as any
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
299
|
+
config: {} as any,
|
|
300
|
+
version: 'cli-version',
|
|
301
|
+
});
|
|
302
|
+
expect(cb).toBeCalledWith({
|
|
303
|
+
argv: {
|
|
292
304
|
api: 'openapi.yaml',
|
|
293
305
|
destination: '@testing_org/main@v1',
|
|
294
306
|
},
|
|
295
|
-
{}
|
|
296
|
-
|
|
307
|
+
config: {},
|
|
308
|
+
version: 'cli-version',
|
|
309
|
+
});
|
|
297
310
|
});
|
|
298
311
|
it('should adapt the existing syntax (including branchName)', () => {
|
|
299
312
|
const cb = jest.fn();
|
|
300
|
-
transformPush(cb)(
|
|
301
|
-
{
|
|
313
|
+
transformPush(cb)({
|
|
314
|
+
argv: {
|
|
302
315
|
apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
|
|
303
316
|
},
|
|
304
|
-
{} as any
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
317
|
+
config: {} as any,
|
|
318
|
+
version: 'cli-version',
|
|
319
|
+
});
|
|
320
|
+
expect(cb).toBeCalledWith({
|
|
321
|
+
argv: {
|
|
308
322
|
api: 'openapi.yaml',
|
|
309
323
|
destination: '@testing_org/main@v1',
|
|
310
324
|
branchName: 'other',
|
|
311
325
|
},
|
|
312
|
-
{}
|
|
313
|
-
|
|
326
|
+
config: {},
|
|
327
|
+
version: 'cli-version',
|
|
328
|
+
});
|
|
314
329
|
});
|
|
315
330
|
it('should use --branch option firstly', () => {
|
|
316
331
|
const cb = jest.fn();
|
|
317
|
-
transformPush(cb)(
|
|
318
|
-
{
|
|
332
|
+
transformPush(cb)({
|
|
333
|
+
argv: {
|
|
319
334
|
apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
|
|
320
335
|
branch: 'priority-branch',
|
|
321
336
|
},
|
|
322
|
-
{} as any
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
337
|
+
config: {} as any,
|
|
338
|
+
version: 'cli-version',
|
|
339
|
+
});
|
|
340
|
+
expect(cb).toBeCalledWith({
|
|
341
|
+
argv: {
|
|
326
342
|
api: 'openapi.yaml',
|
|
327
343
|
destination: '@testing_org/main@v1',
|
|
328
344
|
branchName: 'priority-branch',
|
|
329
345
|
},
|
|
330
|
-
{}
|
|
331
|
-
|
|
346
|
+
config: {},
|
|
347
|
+
version: 'cli-version',
|
|
348
|
+
});
|
|
332
349
|
});
|
|
333
350
|
it('should work for a destination only', () => {
|
|
334
351
|
const cb = jest.fn();
|
|
335
|
-
transformPush(cb)(
|
|
336
|
-
{
|
|
352
|
+
transformPush(cb)({
|
|
353
|
+
argv: {
|
|
337
354
|
apis: ['main@v1'],
|
|
338
355
|
},
|
|
339
|
-
{} as any
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
356
|
+
config: {} as any,
|
|
357
|
+
version: 'cli-version',
|
|
358
|
+
});
|
|
359
|
+
expect(cb).toBeCalledWith({
|
|
360
|
+
argv: {
|
|
343
361
|
destination: 'main@v1',
|
|
344
362
|
},
|
|
345
|
-
{}
|
|
346
|
-
|
|
363
|
+
config: {},
|
|
364
|
+
version: 'cli-version',
|
|
365
|
+
});
|
|
347
366
|
});
|
|
348
367
|
it('should work for a api only', () => {
|
|
349
368
|
const cb = jest.fn();
|
|
350
|
-
transformPush(cb)(
|
|
351
|
-
{
|
|
369
|
+
transformPush(cb)({
|
|
370
|
+
argv: {
|
|
352
371
|
apis: ['test.yaml'],
|
|
353
372
|
},
|
|
354
|
-
{} as any
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
373
|
+
config: {} as any,
|
|
374
|
+
version: 'cli-version',
|
|
375
|
+
});
|
|
376
|
+
expect(cb).toBeCalledWith({
|
|
377
|
+
argv: {
|
|
358
378
|
api: 'test.yaml',
|
|
359
379
|
},
|
|
360
|
-
{}
|
|
361
|
-
|
|
380
|
+
config: {},
|
|
381
|
+
version: 'cli-version',
|
|
382
|
+
});
|
|
362
383
|
});
|
|
363
384
|
|
|
364
385
|
it('should use destination from option', () => {
|
|
365
386
|
const cb = jest.fn();
|
|
366
|
-
transformPush(cb)(
|
|
367
|
-
{
|
|
387
|
+
transformPush(cb)({
|
|
388
|
+
argv: {
|
|
368
389
|
apis: ['test.yaml', 'test@v1'],
|
|
369
390
|
destination: 'main@v1',
|
|
370
391
|
},
|
|
371
|
-
{} as any
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
392
|
+
config: {} as any,
|
|
393
|
+
version: 'cli-version',
|
|
394
|
+
});
|
|
395
|
+
expect(cb).toBeCalledWith({
|
|
396
|
+
argv: {
|
|
375
397
|
destination: 'main@v1',
|
|
376
398
|
api: 'test.yaml',
|
|
377
399
|
},
|
|
378
|
-
{}
|
|
379
|
-
|
|
400
|
+
config: {},
|
|
401
|
+
version: 'cli-version',
|
|
402
|
+
});
|
|
380
403
|
});
|
|
381
404
|
|
|
382
405
|
it('should use --job-id option firstly', () => {
|
|
383
406
|
const cb = jest.fn();
|
|
384
|
-
transformPush(cb)(
|
|
385
|
-
{
|
|
407
|
+
transformPush(cb)({
|
|
408
|
+
argv: {
|
|
386
409
|
'batch-id': 'b-123',
|
|
387
410
|
'job-id': 'j-123',
|
|
388
411
|
apis: ['test'],
|
|
389
412
|
branch: 'test',
|
|
390
413
|
destination: 'main@v1',
|
|
391
414
|
},
|
|
392
|
-
{} as any
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
415
|
+
config: {} as any,
|
|
416
|
+
version: 'cli-version',
|
|
417
|
+
});
|
|
418
|
+
expect(cb).toBeCalledWith({
|
|
419
|
+
argv: {
|
|
396
420
|
'job-id': 'j-123',
|
|
397
421
|
api: 'test',
|
|
398
422
|
branchName: 'test',
|
|
399
423
|
destination: 'main@v1',
|
|
400
424
|
},
|
|
401
|
-
{}
|
|
402
|
-
|
|
425
|
+
config: {},
|
|
426
|
+
version: 'cli-version',
|
|
427
|
+
});
|
|
403
428
|
});
|
|
404
429
|
it('should accept no arguments at all', () => {
|
|
405
430
|
const cb = jest.fn();
|
|
406
|
-
transformPush(cb)({}, {} as any);
|
|
407
|
-
expect(cb).toBeCalledWith({}, {});
|
|
431
|
+
transformPush(cb)({ argv: {}, config: {} as any, version: 'cli-version' });
|
|
432
|
+
expect(cb).toBeCalledWith({ argv: {}, config: {}, version: 'cli-version' });
|
|
408
433
|
});
|
|
409
434
|
});
|
|
410
435
|
|
|
@@ -4,6 +4,7 @@ import { commandWrapper } from '../wrapper';
|
|
|
4
4
|
import { handleLint } from '../commands/lint';
|
|
5
5
|
import { Arguments } from 'yargs';
|
|
6
6
|
import { handlePush, PushOptions } from '../commands/push';
|
|
7
|
+
import { detectSpec } from '@redocly/openapi-core';
|
|
7
8
|
|
|
8
9
|
jest.mock('node-fetch');
|
|
9
10
|
jest.mock('../utils/miscellaneous', () => ({
|
|
@@ -11,7 +12,9 @@ jest.mock('../utils/miscellaneous', () => ({
|
|
|
11
12
|
loadConfigAndHandleErrors: jest.fn(),
|
|
12
13
|
}));
|
|
13
14
|
jest.mock('../commands/lint', () => ({
|
|
14
|
-
handleLint: jest.fn()
|
|
15
|
+
handleLint: jest.fn().mockImplementation(({ collectSpecData }) => {
|
|
16
|
+
collectSpecData({ openapi: '3.1.0' });
|
|
17
|
+
}),
|
|
15
18
|
lintConfigCallback: jest.fn(),
|
|
16
19
|
}));
|
|
17
20
|
|
|
@@ -20,13 +23,32 @@ describe('commandWrapper', () => {
|
|
|
20
23
|
(loadConfigAndHandleErrors as jest.Mock).mockImplementation(() => {
|
|
21
24
|
return { telemetry: 'on', styleguide: { recommendedFallback: true } };
|
|
22
25
|
});
|
|
26
|
+
(detectSpec as jest.Mock).mockImplementationOnce(() => {
|
|
27
|
+
return 'oas3_1';
|
|
28
|
+
});
|
|
29
|
+
process.env.REDOCLY_TELEMETRY = 'on';
|
|
30
|
+
|
|
31
|
+
const wrappedHandler = commandWrapper(handleLint);
|
|
32
|
+
await wrappedHandler({} as any);
|
|
33
|
+
expect(handleLint).toHaveBeenCalledTimes(1);
|
|
34
|
+
expect(sendTelemetry).toHaveBeenCalledTimes(1);
|
|
35
|
+
expect(sendTelemetry).toHaveBeenCalledWith({}, 0, false, 'oas3_1', 'openapi', '3.1.0');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should not collect spec version if the file is not parsed to json', async () => {
|
|
39
|
+
(loadConfigAndHandleErrors as jest.Mock).mockImplementation(() => {
|
|
40
|
+
return { telemetry: 'on', styleguide: { recommendedFallback: true } };
|
|
41
|
+
});
|
|
42
|
+
(handleLint as jest.Mock).mockImplementation(({ collectSpecData }) => {
|
|
43
|
+
collectSpecData();
|
|
44
|
+
});
|
|
23
45
|
process.env.REDOCLY_TELEMETRY = 'on';
|
|
24
46
|
|
|
25
47
|
const wrappedHandler = commandWrapper(handleLint);
|
|
26
48
|
await wrappedHandler({} as any);
|
|
27
49
|
expect(handleLint).toHaveBeenCalledTimes(1);
|
|
28
50
|
expect(sendTelemetry).toHaveBeenCalledTimes(1);
|
|
29
|
-
expect(sendTelemetry).toHaveBeenCalledWith({}, 0, false);
|
|
51
|
+
expect(sendTelemetry).toHaveBeenCalledWith({}, 0, false, undefined, undefined, undefined);
|
|
30
52
|
});
|
|
31
53
|
|
|
32
54
|
it('should NOT send telemetry if there is "telemetry: off" in the config', async () => {
|