@redocly/cli 1.18.1 → 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.
Files changed (91) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
  3. package/lib/__mocks__/@redocly/openapi-core.js +1 -0
  4. package/lib/__mocks__/fs.d.ts +0 -1
  5. package/lib/__mocks__/perf_hooks.d.ts +0 -1
  6. package/lib/__mocks__/redoc.d.ts +0 -1
  7. package/lib/__tests__/commands/build-docs.test.js +21 -23
  8. package/lib/__tests__/commands/bundle.test.js +21 -30
  9. package/lib/__tests__/commands/join.test.js +101 -70
  10. package/lib/__tests__/commands/lint.test.js +54 -54
  11. package/lib/__tests__/commands/push-region.test.js +24 -25
  12. package/lib/__tests__/commands/push.test.js +269 -170
  13. package/lib/__tests__/fetch-with-timeout.test.js +3 -12
  14. package/lib/__tests__/fixtures/config.d.ts +0 -1
  15. package/lib/__tests__/utils.test.js +32 -37
  16. package/lib/__tests__/wrapper.test.js +31 -20
  17. package/lib/cms/api/__tests__/api.client.test.js +29 -38
  18. package/lib/cms/api/api-client.d.ts +0 -2
  19. package/lib/cms/api/api-client.js +106 -127
  20. package/lib/cms/api/api-keys.js +1 -2
  21. package/lib/cms/api/domains.js +1 -2
  22. package/lib/cms/commands/__tests__/push-status.test.js +251 -162
  23. package/lib/cms/commands/__tests__/push.test.js +120 -102
  24. package/lib/cms/commands/__tests__/utils.test.js +12 -21
  25. package/lib/cms/commands/push-status.d.ts +3 -2
  26. package/lib/cms/commands/push-status.js +94 -106
  27. package/lib/cms/commands/push.d.ts +3 -2
  28. package/lib/cms/commands/push.js +66 -74
  29. package/lib/cms/commands/utils.js +20 -34
  30. package/lib/commands/build-docs/index.d.ts +2 -2
  31. package/lib/commands/build-docs/index.js +8 -17
  32. package/lib/commands/build-docs/utils.js +26 -38
  33. package/lib/commands/bundle.d.ts +2 -2
  34. package/lib/commands/bundle.js +70 -94
  35. package/lib/commands/join.d.ts +2 -2
  36. package/lib/commands/join.js +375 -388
  37. package/lib/commands/lint.d.ts +2 -2
  38. package/lib/commands/lint.js +64 -75
  39. package/lib/commands/login.d.ts +3 -2
  40. package/lib/commands/login.js +9 -21
  41. package/lib/commands/preview-docs/index.d.ts +2 -2
  42. package/lib/commands/preview-docs/index.js +92 -106
  43. package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
  44. package/lib/commands/preview-docs/preview-server/server.d.ts +0 -3
  45. package/lib/commands/preview-docs/preview-server/server.js +6 -6
  46. package/lib/commands/preview-project/index.d.ts +2 -1
  47. package/lib/commands/preview-project/index.js +5 -14
  48. package/lib/commands/push.d.ts +8 -11
  49. package/lib/commands/push.js +177 -195
  50. package/lib/commands/split/__tests__/index.test.js +31 -25
  51. package/lib/commands/split/index.d.ts +2 -1
  52. package/lib/commands/split/index.js +20 -33
  53. package/lib/commands/stats.d.ts +2 -2
  54. package/lib/commands/stats.js +34 -45
  55. package/lib/index.js +32 -46
  56. package/lib/types.d.ts +2 -2
  57. package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
  58. package/lib/utils/fetch-with-timeout.js +7 -12
  59. package/lib/utils/getCommandNameFromArgs.js +2 -4
  60. package/lib/utils/js-utils.js +6 -7
  61. package/lib/utils/miscellaneous.d.ts +4 -1
  62. package/lib/utils/miscellaneous.js +130 -152
  63. package/lib/utils/update-version-notifier.js +4 -13
  64. package/lib/wrapper.d.ts +9 -2
  65. package/lib/wrapper.js +27 -16
  66. package/package.json +3 -3
  67. package/src/__mocks__/@redocly/openapi-core.ts +1 -0
  68. package/src/__tests__/commands/build-docs.test.ts +5 -4
  69. package/src/__tests__/commands/join.test.ts +51 -51
  70. package/src/__tests__/commands/push-region.test.ts +10 -8
  71. package/src/__tests__/commands/push.test.ts +127 -102
  72. package/src/__tests__/utils.test.ts +1 -0
  73. package/src/__tests__/wrapper.test.ts +24 -2
  74. package/src/cms/commands/__tests__/push-status.test.ts +70 -56
  75. package/src/cms/commands/__tests__/push.test.ts +30 -24
  76. package/src/cms/commands/push-status.ts +8 -7
  77. package/src/cms/commands/push.ts +12 -9
  78. package/src/commands/build-docs/index.ts +10 -5
  79. package/src/commands/bundle.ts +14 -6
  80. package/src/commands/join.ts +6 -2
  81. package/src/commands/lint.ts +9 -3
  82. package/src/commands/login.ts +4 -2
  83. package/src/commands/preview-docs/index.ts +6 -1
  84. package/src/commands/preview-project/index.ts +5 -4
  85. package/src/commands/push.ts +13 -15
  86. package/src/commands/split/__tests__/index.test.ts +17 -6
  87. package/src/commands/split/index.ts +4 -2
  88. package/src/commands/stats.ts +4 -2
  89. package/src/utils/miscellaneous.ts +11 -1
  90. package/src/wrapper.ts +37 -11
  91. package/tsconfig.tsbuildinfo +1 -1
@@ -14,21 +14,21 @@ describe('handleJoin', () => {
14
14
  colloreteYellowMock.mockImplementation((string: string) => string);
15
15
 
16
16
  it('should call exitWithError because only one entrypoint', async () => {
17
- await handleJoin({ apis: ['first.yaml'] }, {} as any, 'cli-version');
17
+ await handleJoin({ argv: { apis: ['first.yaml'] }, config: {} as any, version: 'cli-version' });
18
18
  expect(exitWithError).toHaveBeenCalledWith(`At least 2 apis should be provided.`);
19
19
  });
20
20
 
21
21
  it('should call exitWithError because passed all 3 options for tags', async () => {
22
- await handleJoin(
23
- {
22
+ await handleJoin({
23
+ argv: {
24
24
  apis: ['first.yaml', 'second.yaml'],
25
25
  'prefix-tags-with-info-prop': 'something',
26
26
  'without-x-tag-groups': true,
27
27
  'prefix-tags-with-filename': true,
28
28
  },
29
- {} as any,
30
- 'cli-version'
31
- );
29
+ config: {} as any,
30
+ version: 'cli-version',
31
+ });
32
32
 
33
33
  expect(exitWithError).toHaveBeenCalledWith(
34
34
  `You use prefix-tags-with-filename, prefix-tags-with-info-prop, without-x-tag-groups together.\nPlease choose only one!`
@@ -36,15 +36,15 @@ describe('handleJoin', () => {
36
36
  });
37
37
 
38
38
  it('should call exitWithError because passed all 2 options for tags', async () => {
39
- await handleJoin(
40
- {
39
+ await handleJoin({
40
+ argv: {
41
41
  apis: ['first.yaml', 'second.yaml'],
42
42
  'without-x-tag-groups': true,
43
43
  'prefix-tags-with-filename': true,
44
44
  },
45
- {} as any,
46
- 'cli-version'
47
- );
45
+ config: {} as any,
46
+ version: 'cli-version',
47
+ });
48
48
 
49
49
  expect(exitWithError).toHaveBeenCalledWith(
50
50
  `You use prefix-tags-with-filename, without-x-tag-groups together.\nPlease choose only one!`
@@ -52,13 +52,13 @@ describe('handleJoin', () => {
52
52
  });
53
53
 
54
54
  it('should call exitWithError because Only OpenAPI 3.0 and OpenAPI 3.1 are supported', async () => {
55
- await handleJoin(
56
- {
55
+ await handleJoin({
56
+ argv: {
57
57
  apis: ['first.yaml', 'second.yaml'],
58
58
  },
59
- ConfigFixture as any,
60
- 'cli-version'
61
- );
59
+ config: ConfigFixture as any,
60
+ version: 'cli-version',
61
+ });
62
62
  expect(exitWithError).toHaveBeenCalledWith(
63
63
  'Only OpenAPI 3.0 and OpenAPI 3.1 are supported: undefined.'
64
64
  );
@@ -68,13 +68,13 @@ describe('handleJoin', () => {
68
68
  (detectSpec as jest.Mock)
69
69
  .mockImplementationOnce(() => 'oas3_0')
70
70
  .mockImplementationOnce(() => 'oas3_1');
71
- await handleJoin(
72
- {
71
+ await handleJoin({
72
+ argv: {
73
73
  apis: ['first.yaml', 'second.yaml'],
74
74
  },
75
- ConfigFixture as any,
76
- 'cli-version'
77
- );
75
+ config: ConfigFixture as any,
76
+ version: 'cli-version',
77
+ });
78
78
 
79
79
  expect(exitWithError).toHaveBeenCalledWith(
80
80
  'All APIs must use the same OpenAPI version: undefined.'
@@ -83,13 +83,13 @@ describe('handleJoin', () => {
83
83
 
84
84
  it('should call writeToFileByExtension function', async () => {
85
85
  (detectSpec as jest.Mock).mockReturnValue('oas3_0');
86
- await handleJoin(
87
- {
86
+ await handleJoin({
87
+ argv: {
88
88
  apis: ['first.yaml', 'second.yaml'],
89
89
  },
90
- ConfigFixture as any,
91
- 'cli-version'
92
- );
90
+ config: ConfigFixture as any,
91
+ version: 'cli-version',
92
+ });
93
93
 
94
94
  expect(writeToFileByExtension).toHaveBeenCalledWith(
95
95
  expect.any(Object),
@@ -100,13 +100,13 @@ describe('handleJoin', () => {
100
100
 
101
101
  it('should call writeToFileByExtension function for OpenAPI 3.1', async () => {
102
102
  (detectSpec as jest.Mock).mockReturnValue('oas3_1');
103
- await handleJoin(
104
- {
103
+ await handleJoin({
104
+ argv: {
105
105
  apis: ['first.yaml', 'second.yaml'],
106
106
  },
107
- ConfigFixture as any,
108
- 'cli-version'
109
- );
107
+ config: ConfigFixture as any,
108
+ version: 'cli-version',
109
+ });
110
110
 
111
111
  expect(writeToFileByExtension).toHaveBeenCalledWith(
112
112
  expect.any(Object),
@@ -117,14 +117,14 @@ describe('handleJoin', () => {
117
117
 
118
118
  it('should call writeToFileByExtension function with custom output file', async () => {
119
119
  (detectSpec as jest.Mock).mockReturnValue('oas3_0');
120
- await handleJoin(
121
- {
120
+ await handleJoin({
121
+ argv: {
122
122
  apis: ['first.yaml', 'second.yaml'],
123
123
  output: 'output.yml',
124
124
  },
125
- ConfigFixture as any,
126
- 'cli-version'
127
- );
125
+ config: ConfigFixture as any,
126
+ version: 'cli-version',
127
+ });
128
128
 
129
129
  expect(writeToFileByExtension).toHaveBeenCalledWith(
130
130
  expect.any(Object),
@@ -135,13 +135,13 @@ describe('handleJoin', () => {
135
135
 
136
136
  it('should call writeToFileByExtension function with json file extension', async () => {
137
137
  (detectSpec as jest.Mock).mockReturnValue('oas3_0');
138
- await handleJoin(
139
- {
138
+ await handleJoin({
139
+ argv: {
140
140
  apis: ['first.json', 'second.yaml'],
141
141
  },
142
- ConfigFixture as any,
143
- 'cli-version'
144
- );
142
+ config: ConfigFixture as any,
143
+ version: 'cli-version',
144
+ });
145
145
 
146
146
  expect(writeToFileByExtension).toHaveBeenCalledWith(
147
147
  expect.any(Object),
@@ -152,13 +152,13 @@ describe('handleJoin', () => {
152
152
 
153
153
  it('should call skipDecorators and skipPreprocessors', async () => {
154
154
  (detectSpec as jest.Mock).mockReturnValue('oas3_0');
155
- await handleJoin(
156
- {
155
+ await handleJoin({
156
+ argv: {
157
157
  apis: ['first.yaml', 'second.yaml'],
158
158
  },
159
- ConfigFixture as any,
160
- 'cli-version'
161
- );
159
+ config: ConfigFixture as any,
160
+ version: 'cli-version',
161
+ });
162
162
 
163
163
  const config = loadConfig();
164
164
  expect(config.styleguide.skipDecorators).toHaveBeenCalled();
@@ -168,15 +168,15 @@ describe('handleJoin', () => {
168
168
  it('should handle join with prefix-components-with-info-prop and null values', async () => {
169
169
  (detectSpec as jest.Mock).mockReturnValue('oas3_0');
170
170
 
171
- await handleJoin(
172
- {
171
+ await handleJoin({
172
+ argv: {
173
173
  apis: ['first.yaml', 'second.yaml', 'third.yaml'],
174
174
  'prefix-components-with-info-prop': 'title',
175
175
  output: 'join-result.yaml',
176
176
  },
177
- ConfigFixture as any,
178
- 'cli-version'
179
- );
177
+ config: ConfigFixture as any,
178
+ version: 'cli-version',
179
+ });
180
180
 
181
181
  expect(writeToFileByExtension).toHaveBeenCalledWith(
182
182
  {
@@ -28,30 +28,32 @@ describe('push-with-region', () => {
28
28
 
29
29
  it('should call login with default domain when region is US', async () => {
30
30
  redoclyClient.domain = 'redoc.ly';
31
- await handlePush(
32
- {
31
+ await handlePush({
32
+ argv: {
33
33
  upsert: true,
34
34
  api: 'spec.json',
35
35
  destination: '@org/my-api@1.0.0',
36
36
  branchName: 'test',
37
37
  },
38
- ConfigFixture as any
39
- );
38
+ config: ConfigFixture as any,
39
+ version: 'cli-version',
40
+ });
40
41
  expect(mockPromptClientToken).toBeCalledTimes(1);
41
42
  expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
42
43
  });
43
44
 
44
45
  it('should call login with EU domain when region is EU', async () => {
45
46
  redoclyClient.domain = 'eu.redocly.com';
46
- await handlePush(
47
- {
47
+ await handlePush({
48
+ argv: {
48
49
  upsert: true,
49
50
  api: 'spec.json',
50
51
  destination: '@org/my-api@1.0.0',
51
52
  branchName: 'test',
52
53
  },
53
- ConfigFixture as any
54
- );
54
+ config: ConfigFixture as any,
55
+ version: 'cli-version',
56
+ });
55
57
  expect(mockPromptClientToken).toBeCalledTimes(1);
56
58
  expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
57
59
  });
@@ -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
- expect(cb).toBeCalledWith(
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
- expect(cb).toBeCalledWith(
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
- expect(cb).toBeCalledWith(
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
- expect(cb).toBeCalledWith(
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
- expect(cb).toBeCalledWith(
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
- expect(cb).toBeCalledWith(
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
- expect(cb).toBeCalledWith(
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