@redocly/cli 1.34.4 → 2.0.0-next.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 (321) hide show
  1. package/README.md +34 -3
  2. package/bin/cli.js +1 -1
  3. package/lib/auth/device-flow.d.ts +1 -0
  4. package/lib/auth/device-flow.d.ts.map +1 -0
  5. package/lib/auth/device-flow.js +15 -17
  6. package/lib/auth/device-flow.js.map +1 -0
  7. package/lib/auth/oauth-client.d.ts +1 -0
  8. package/lib/auth/oauth-client.d.ts.map +1 -0
  9. package/lib/auth/oauth-client.js +21 -23
  10. package/lib/auth/oauth-client.js.map +1 -0
  11. package/lib/commands/auth.d.ts +3 -5
  12. package/lib/commands/auth.d.ts.map +1 -0
  13. package/lib/commands/auth.js +19 -44
  14. package/lib/commands/auth.js.map +1 -0
  15. package/lib/commands/build-docs/index.d.ts +4 -3
  16. package/lib/commands/build-docs/index.d.ts.map +1 -0
  17. package/lib/commands/build-docs/index.js +23 -24
  18. package/lib/commands/build-docs/index.js.map +1 -0
  19. package/lib/commands/build-docs/types.d.ts +2 -1
  20. package/lib/commands/build-docs/types.d.ts.map +1 -0
  21. package/lib/commands/build-docs/types.js +2 -2
  22. package/lib/commands/build-docs/types.js.map +1 -0
  23. package/lib/commands/build-docs/utils.d.ts +3 -2
  24. package/lib/commands/build-docs/utils.d.ts.map +1 -0
  25. package/lib/commands/build-docs/utils.js +35 -37
  26. package/lib/commands/build-docs/utils.js.map +1 -0
  27. package/lib/commands/bundle.d.ts +6 -3
  28. package/lib/commands/bundle.d.ts.map +1 -0
  29. package/lib/commands/bundle.js +34 -38
  30. package/lib/commands/bundle.js.map +1 -0
  31. package/lib/commands/eject.d.ts +3 -2
  32. package/lib/commands/eject.d.ts.map +1 -0
  33. package/lib/commands/eject.js +11 -13
  34. package/lib/commands/eject.js.map +1 -0
  35. package/lib/commands/join.d.ts +4 -3
  36. package/lib/commands/join.d.ts.map +1 -0
  37. package/lib/commands/join.js +79 -81
  38. package/lib/commands/join.js.map +1 -0
  39. package/lib/commands/lint.d.ts +8 -6
  40. package/lib/commands/lint.d.ts.map +1 -0
  41. package/lib/commands/lint.js +53 -62
  42. package/lib/commands/lint.js.map +1 -0
  43. package/lib/commands/preview-project/constants.d.ts +2 -1
  44. package/lib/commands/preview-project/constants.d.ts.map +1 -0
  45. package/lib/commands/preview-project/constants.js +4 -6
  46. package/lib/commands/preview-project/constants.js.map +1 -0
  47. package/lib/commands/preview-project/index.d.ts +3 -2
  48. package/lib/commands/preview-project/index.d.ts.map +1 -0
  49. package/lib/commands/preview-project/index.js +21 -23
  50. package/lib/commands/preview-project/index.js.map +1 -0
  51. package/lib/commands/preview-project/types.d.ts +3 -2
  52. package/lib/commands/preview-project/types.d.ts.map +1 -0
  53. package/lib/commands/preview-project/types.js +2 -2
  54. package/lib/commands/preview-project/types.js.map +1 -0
  55. package/lib/commands/split/index.d.ts +4 -3
  56. package/lib/commands/split/index.d.ts.map +1 -0
  57. package/lib/commands/split/index.js +53 -57
  58. package/lib/commands/split/index.js.map +1 -0
  59. package/lib/commands/split/types.d.ts +2 -2
  60. package/lib/commands/split/types.d.ts.map +1 -0
  61. package/lib/commands/split/types.js +11 -13
  62. package/lib/commands/split/types.js.map +1 -0
  63. package/lib/commands/stats.d.ts +3 -2
  64. package/lib/commands/stats.d.ts.map +1 -0
  65. package/lib/commands/stats.js +21 -24
  66. package/lib/commands/stats.js.map +1 -0
  67. package/lib/commands/translations.d.ts +3 -2
  68. package/lib/commands/translations.d.ts.map +1 -0
  69. package/lib/commands/translations.js +11 -13
  70. package/lib/commands/translations.js.map +1 -0
  71. package/lib/index.d.ts +2 -1
  72. package/lib/index.d.ts.map +1 -0
  73. package/lib/index.js +109 -239
  74. package/lib/index.js.map +1 -0
  75. package/lib/otel.d.ts +2 -1
  76. package/lib/otel.d.ts.map +1 -0
  77. package/lib/otel.js +22 -23
  78. package/lib/otel.js.map +1 -0
  79. package/lib/reunite/api/api-client.d.ts +4 -3
  80. package/lib/reunite/api/api-client.d.ts.map +1 -0
  81. package/lib/reunite/api/api-client.js +14 -20
  82. package/lib/reunite/api/api-client.js.map +1 -0
  83. package/lib/reunite/api/api-keys.d.ts +2 -1
  84. package/lib/reunite/api/api-keys.d.ts.map +1 -0
  85. package/lib/reunite/api/api-keys.js +4 -20
  86. package/lib/reunite/api/api-keys.js.map +1 -0
  87. package/lib/reunite/api/domains.d.ts +5 -2
  88. package/lib/reunite/api/domains.d.ts.map +1 -0
  89. package/lib/reunite/api/domains.js +6 -15
  90. package/lib/reunite/api/domains.js.map +1 -0
  91. package/lib/reunite/api/index.d.ts +4 -3
  92. package/lib/reunite/api/index.d.ts.map +1 -0
  93. package/lib/reunite/api/index.js +4 -19
  94. package/lib/reunite/api/index.js.map +1 -0
  95. package/lib/reunite/api/types.d.ts +1 -0
  96. package/lib/reunite/api/types.d.ts.map +1 -0
  97. package/lib/reunite/api/types.js +2 -2
  98. package/lib/reunite/api/types.js.map +1 -0
  99. package/lib/reunite/commands/push-status.d.ts +6 -5
  100. package/lib/reunite/commands/push-status.d.ts.map +1 -0
  101. package/lib/reunite/commands/push-status.js +31 -37
  102. package/lib/reunite/commands/push-status.js.map +1 -0
  103. package/lib/reunite/commands/push.d.ts +6 -6
  104. package/lib/reunite/commands/push.d.ts.map +1 -0
  105. package/lib/reunite/commands/push.js +31 -40
  106. package/lib/reunite/commands/push.js.map +1 -0
  107. package/lib/reunite/commands/utils.d.ts +4 -3
  108. package/lib/reunite/commands/utils.d.ts.map +1 -0
  109. package/lib/reunite/commands/utils.js +9 -12
  110. package/lib/reunite/commands/utils.js.map +1 -0
  111. package/lib/reunite/utils.d.ts +1 -0
  112. package/lib/reunite/utils.d.ts.map +1 -0
  113. package/lib/reunite/utils.js +2 -5
  114. package/lib/reunite/utils.js.map +1 -0
  115. package/lib/types.d.ts +15 -27
  116. package/lib/types.d.ts.map +1 -0
  117. package/lib/types.js +2 -5
  118. package/lib/types.js.map +1 -0
  119. package/lib/utils/assert-node-version.d.ts +1 -0
  120. package/lib/utils/assert-node-version.d.ts.map +1 -0
  121. package/lib/utils/assert-node-version.js +8 -10
  122. package/lib/utils/assert-node-version.js.map +1 -0
  123. package/lib/utils/error.d.ts +4 -0
  124. package/lib/utils/error.d.ts.map +1 -0
  125. package/lib/utils/error.js +8 -0
  126. package/lib/utils/error.js.map +1 -0
  127. package/lib/utils/fetch-with-timeout.d.ts +1 -0
  128. package/lib/utils/fetch-with-timeout.d.ts.map +1 -0
  129. package/lib/utils/fetch-with-timeout.js +6 -8
  130. package/lib/utils/fetch-with-timeout.js.map +1 -0
  131. package/lib/utils/{getCommandNameFromArgs.d.ts → get-command-name-from-args.d.ts} +1 -0
  132. package/lib/utils/get-command-name-from-args.d.ts.map +1 -0
  133. package/lib/utils/get-command-name-from-args.js +4 -0
  134. package/lib/utils/get-command-name-from-args.js.map +1 -0
  135. package/lib/utils/js-utils.d.ts +1 -0
  136. package/lib/utils/js-utils.d.ts.map +1 -0
  137. package/lib/utils/js-utils.js +8 -12
  138. package/lib/utils/js-utils.js.map +1 -0
  139. package/lib/utils/miscellaneous.d.ts +9 -48
  140. package/lib/utils/miscellaneous.d.ts.map +1 -0
  141. package/lib/utils/miscellaneous.js +131 -269
  142. package/lib/utils/miscellaneous.js.map +1 -0
  143. package/lib/utils/package.d.ts +2 -0
  144. package/lib/utils/package.d.ts.map +1 -0
  145. package/lib/utils/package.js +4 -0
  146. package/lib/utils/package.js.map +1 -0
  147. package/lib/utils/platform.d.ts +1 -0
  148. package/lib/utils/platform.d.ts.map +1 -0
  149. package/lib/utils/platform.js +5 -9
  150. package/lib/utils/platform.js.map +1 -0
  151. package/lib/utils/proxy-agent.d.ts +3 -0
  152. package/lib/utils/proxy-agent.d.ts.map +1 -0
  153. package/lib/utils/proxy-agent.js +6 -0
  154. package/lib/utils/proxy-agent.js.map +1 -0
  155. package/lib/utils/spinner.d.ts +1 -0
  156. package/lib/utils/spinner.d.ts.map +1 -0
  157. package/lib/utils/spinner.js +8 -10
  158. package/lib/utils/spinner.js.map +1 -0
  159. package/lib/utils/telemetry.d.ts +40 -0
  160. package/lib/utils/telemetry.d.ts.map +1 -0
  161. package/lib/utils/telemetry.js +138 -0
  162. package/lib/utils/telemetry.js.map +1 -0
  163. package/lib/utils/update-version-notifier.d.ts +1 -1
  164. package/lib/utils/update-version-notifier.d.ts.map +1 -0
  165. package/lib/utils/update-version-notifier.js +35 -38
  166. package/lib/utils/update-version-notifier.js.map +1 -0
  167. package/lib/utils/validate-positive-number.d.ts +2 -0
  168. package/lib/utils/validate-positive-number.d.ts.map +1 -0
  169. package/lib/utils/validate-positive-number.js +13 -0
  170. package/lib/utils/validate-positive-number.js.map +1 -0
  171. package/lib/wrapper.d.ts +3 -3
  172. package/lib/wrapper.d.ts.map +1 -0
  173. package/lib/wrapper.js +39 -26
  174. package/lib/wrapper.js.map +1 -0
  175. package/package.json +16 -17
  176. package/CHANGELOG.md +0 -777
  177. package/lib/__mocks__/@redocly/openapi-core.d.ts +0 -99
  178. package/lib/__mocks__/@redocly/openapi-core.js +0 -84
  179. package/lib/__mocks__/documents.d.ts +0 -150
  180. package/lib/__mocks__/documents.js +0 -123
  181. package/lib/__mocks__/fs.d.ts +0 -8
  182. package/lib/__mocks__/fs.js +0 -9
  183. package/lib/__mocks__/perf_hooks.d.ts +0 -3
  184. package/lib/__mocks__/perf_hooks.js +0 -6
  185. package/lib/__mocks__/redoc.d.ts +0 -6
  186. package/lib/__mocks__/redoc.js +0 -5
  187. package/lib/__tests__/commands/build-docs.test.d.ts +0 -1
  188. package/lib/__tests__/commands/build-docs.test.js +0 -54
  189. package/lib/__tests__/commands/bundle.test.d.ts +0 -1
  190. package/lib/__tests__/commands/bundle.test.js +0 -235
  191. package/lib/__tests__/commands/join.test.d.ts +0 -1
  192. package/lib/__tests__/commands/join.test.js +0 -274
  193. package/lib/__tests__/commands/lint.test.d.ts +0 -1
  194. package/lib/__tests__/commands/lint.test.js +0 -149
  195. package/lib/__tests__/commands/push-region.test.d.ts +0 -1
  196. package/lib/__tests__/commands/push-region.test.js +0 -90
  197. package/lib/__tests__/commands/push.test.d.ts +0 -1
  198. package/lib/__tests__/commands/push.test.js +0 -496
  199. package/lib/__tests__/fetch-with-timeout.test.d.ts +0 -1
  200. package/lib/__tests__/fetch-with-timeout.test.js +0 -64
  201. package/lib/__tests__/fixtures/config.d.ts +0 -21
  202. package/lib/__tests__/fixtures/config.js +0 -24
  203. package/lib/__tests__/spinner.test.d.ts +0 -1
  204. package/lib/__tests__/spinner.test.js +0 -43
  205. package/lib/__tests__/utils.test.d.ts +0 -1
  206. package/lib/__tests__/utils.test.js +0 -651
  207. package/lib/__tests__/wrapper.test.d.ts +0 -1
  208. package/lib/__tests__/wrapper.test.js +0 -76
  209. package/lib/auth/__tests__/device-flow.test.d.ts +0 -1
  210. package/lib/auth/__tests__/device-flow.test.js +0 -62
  211. package/lib/auth/__tests__/oauth-client.test.d.ts +0 -1
  212. package/lib/auth/__tests__/oauth-client.test.js +0 -93
  213. package/lib/commands/preview-docs/index.d.ts +0 -12
  214. package/lib/commands/preview-docs/index.js +0 -127
  215. package/lib/commands/preview-docs/preview-server/default.hbs +0 -24
  216. package/lib/commands/preview-docs/preview-server/hot.js +0 -59
  217. package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
  218. package/lib/commands/preview-docs/preview-server/preview-server.d.ts +0 -5
  219. package/lib/commands/preview-docs/preview-server/preview-server.js +0 -113
  220. package/lib/commands/preview-docs/preview-server/server.d.ts +0 -22
  221. package/lib/commands/preview-docs/preview-server/server.js +0 -85
  222. package/lib/commands/push.d.ts +0 -44
  223. package/lib/commands/push.js +0 -301
  224. package/lib/commands/split/__tests__/index.test.d.ts +0 -1
  225. package/lib/commands/split/__tests__/index.test.js +0 -91
  226. package/lib/reunite/api/__tests__/api-keys.test.d.ts +0 -1
  227. package/lib/reunite/api/__tests__/api-keys.test.js +0 -26
  228. package/lib/reunite/api/__tests__/api.client.test.d.ts +0 -1
  229. package/lib/reunite/api/__tests__/api.client.test.js +0 -337
  230. package/lib/reunite/api/__tests__/domains.test.d.ts +0 -1
  231. package/lib/reunite/api/__tests__/domains.test.js +0 -32
  232. package/lib/reunite/commands/__tests__/push-status.test.d.ts +0 -1
  233. package/lib/reunite/commands/__tests__/push-status.test.js +0 -563
  234. package/lib/reunite/commands/__tests__/push.test.d.ts +0 -1
  235. package/lib/reunite/commands/__tests__/push.test.js +0 -315
  236. package/lib/reunite/commands/__tests__/utils.test.d.ts +0 -1
  237. package/lib/reunite/commands/__tests__/utils.test.js +0 -51
  238. package/lib/utils/__mocks__/miscellaneous.d.ts +0 -43
  239. package/lib/utils/__mocks__/miscellaneous.js +0 -24
  240. package/lib/utils/getCommandNameFromArgs.js +0 -6
  241. package/src/__mocks__/@redocly/openapi-core.ts +0 -88
  242. package/src/__mocks__/documents.ts +0 -124
  243. package/src/__mocks__/fs.ts +0 -6
  244. package/src/__mocks__/perf_hooks.ts +0 -3
  245. package/src/__mocks__/redoc.ts +0 -2
  246. package/src/__tests__/commands/build-docs.test.ts +0 -59
  247. package/src/__tests__/commands/bundle.test.ts +0 -285
  248. package/src/__tests__/commands/join.test.ts +0 -334
  249. package/src/__tests__/commands/lint.test.ts +0 -190
  250. package/src/__tests__/commands/push-region.test.ts +0 -104
  251. package/src/__tests__/commands/push.test.ts +0 -553
  252. package/src/__tests__/fetch-with-timeout.test.ts +0 -81
  253. package/src/__tests__/fixtures/config.ts +0 -21
  254. package/src/__tests__/fixtures/openapi.json +0 -0
  255. package/src/__tests__/fixtures/openapi.yaml +0 -0
  256. package/src/__tests__/fixtures/redocly.yaml +0 -0
  257. package/src/__tests__/spinner.test.ts +0 -51
  258. package/src/__tests__/utils.test.ts +0 -781
  259. package/src/__tests__/wrapper.test.ts +0 -91
  260. package/src/auth/__tests__/device-flow.test.ts +0 -73
  261. package/src/auth/__tests__/oauth-client.test.ts +0 -117
  262. package/src/auth/device-flow.ts +0 -175
  263. package/src/auth/oauth-client.ts +0 -111
  264. package/src/commands/auth.ts +0 -66
  265. package/src/commands/build-docs/index.ts +0 -55
  266. package/src/commands/build-docs/template.hbs +0 -23
  267. package/src/commands/build-docs/types.ts +0 -25
  268. package/src/commands/build-docs/utils.ts +0 -110
  269. package/src/commands/bundle.ts +0 -154
  270. package/src/commands/eject.ts +0 -42
  271. package/src/commands/join.ts +0 -794
  272. package/src/commands/lint.ts +0 -169
  273. package/src/commands/preview-docs/index.ts +0 -183
  274. package/src/commands/preview-docs/preview-server/default.hbs +0 -24
  275. package/src/commands/preview-docs/preview-server/hot.js +0 -59
  276. package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
  277. package/src/commands/preview-docs/preview-server/preview-server.ts +0 -159
  278. package/src/commands/preview-docs/preview-server/server.ts +0 -92
  279. package/src/commands/preview-project/constants.ts +0 -23
  280. package/src/commands/preview-project/index.ts +0 -71
  281. package/src/commands/preview-project/types.ts +0 -12
  282. package/src/commands/push.ts +0 -470
  283. package/src/commands/split/__tests__/fixtures/samples.json +0 -61
  284. package/src/commands/split/__tests__/fixtures/spec.json +0 -70
  285. package/src/commands/split/__tests__/fixtures/webhooks.json +0 -85
  286. package/src/commands/split/__tests__/index.test.ts +0 -156
  287. package/src/commands/split/index.ts +0 -397
  288. package/src/commands/split/types.ts +0 -60
  289. package/src/commands/stats.ts +0 -140
  290. package/src/commands/translations.ts +0 -32
  291. package/src/custom.d.ts +0 -1
  292. package/src/index.ts +0 -970
  293. package/src/otel.ts +0 -59
  294. package/src/reunite/api/__tests__/api-keys.test.ts +0 -37
  295. package/src/reunite/api/__tests__/api.client.test.ts +0 -452
  296. package/src/reunite/api/__tests__/domains.test.ts +0 -41
  297. package/src/reunite/api/api-client.ts +0 -381
  298. package/src/reunite/api/api-keys.ts +0 -26
  299. package/src/reunite/api/domains.ts +0 -23
  300. package/src/reunite/api/index.ts +0 -3
  301. package/src/reunite/api/types.ts +0 -108
  302. package/src/reunite/commands/__tests__/push-status.test.ts +0 -653
  303. package/src/reunite/commands/__tests__/push.test.ts +0 -385
  304. package/src/reunite/commands/__tests__/utils.test.ts +0 -62
  305. package/src/reunite/commands/push-status.ts +0 -325
  306. package/src/reunite/commands/push.ts +0 -235
  307. package/src/reunite/commands/utils.ts +0 -66
  308. package/src/reunite/utils.ts +0 -1
  309. package/src/types.ts +0 -64
  310. package/src/utils/__mocks__/miscellaneous.ts +0 -24
  311. package/src/utils/assert-node-version.ts +0 -19
  312. package/src/utils/fetch-with-timeout.ts +0 -30
  313. package/src/utils/getCommandNameFromArgs.ts +0 -5
  314. package/src/utils/js-utils.ts +0 -24
  315. package/src/utils/miscellaneous.ts +0 -729
  316. package/src/utils/platform.ts +0 -31
  317. package/src/utils/spinner.ts +0 -50
  318. package/src/utils/update-version-notifier.ts +0 -115
  319. package/src/wrapper.ts +0 -77
  320. package/tsconfig.json +0 -9
  321. package/tsconfig.tsbuildinfo +0 -1
@@ -1,553 +0,0 @@
1
- import * as fs from 'fs';
2
- import { Config, getMergedConfig } from '@redocly/openapi-core';
3
- import { exitWithError } from '../../utils/miscellaneous';
4
- import { getApiRoot, getDestinationProps, handlePush, transformPush } from '../../commands/push';
5
- import { ConfigFixture } from '../fixtures/config';
6
- import { yellow } from 'colorette';
7
- import { Readable } from 'node:stream';
8
-
9
- // Mock fs operations
10
- jest.mock('fs', () => ({
11
- ...jest.requireActual('fs'),
12
- createReadStream: jest.fn(() => {
13
- const readable = new Readable();
14
- readable.push('test data');
15
- readable.push(null);
16
- return readable;
17
- }),
18
- statSync: jest.fn(() => ({ isDirectory: () => false, size: 10 })),
19
- readFileSync: jest.fn(() => Buffer.from('test data')),
20
- existsSync: jest.fn(() => false),
21
- readdirSync: jest.fn(() => []),
22
- }));
23
-
24
- jest.mock('@redocly/openapi-core');
25
- jest.mock('../../utils/miscellaneous');
26
-
27
- // Mock fetch
28
- const mockFetch = jest.fn(() =>
29
- Promise.resolve({
30
- ok: true,
31
- status: 200,
32
- json: () => Promise.resolve({}),
33
- headers: new Headers(),
34
- statusText: 'OK',
35
- redirected: false,
36
- type: 'default',
37
- url: '',
38
- clone: () => ({} as Response),
39
- body: null,
40
- bodyUsed: false,
41
- arrayBuffer: async () => new ArrayBuffer(0),
42
- blob: async () => new Blob(),
43
- formData: async () => new FormData(),
44
- text: async () => '',
45
- } as Response)
46
- );
47
-
48
- const originalFetch = global.fetch;
49
-
50
- (getMergedConfig as jest.Mock).mockImplementation((config) => config);
51
-
52
- describe('push', () => {
53
- const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
54
-
55
- beforeAll(() => {
56
- global.fetch = mockFetch;
57
- });
58
-
59
- beforeEach(() => {
60
- jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
61
- });
62
-
63
- afterAll(() => {
64
- global.fetch = originalFetch;
65
- });
66
-
67
- it('pushes definition', async () => {
68
- await handlePush({
69
- argv: {
70
- upsert: true,
71
- api: 'spec.json',
72
- destination: '@org/my-api@1.0.0',
73
- branchName: 'test',
74
- public: true,
75
- 'job-id': '123',
76
- 'batch-size': 2,
77
- },
78
- config: ConfigFixture as any,
79
- version: 'cli-version',
80
- });
81
-
82
- expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(1);
83
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
84
- expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
85
- branch: 'test',
86
- filePaths: ['filePath'],
87
- isUpsert: true,
88
- isPublic: true,
89
- name: 'my-api',
90
- organizationId: 'org',
91
- rootFilePath: 'filePath',
92
- version: '1.0.0',
93
- batchId: '123',
94
- batchSize: 2,
95
- });
96
- });
97
-
98
- it('fails if jobId value is an empty string', async () => {
99
- await handlePush({
100
- argv: {
101
- upsert: true,
102
- api: 'spec.json',
103
- destination: '@org/my-api@1.0.0',
104
- branchName: 'test',
105
- public: true,
106
- 'job-id': ' ',
107
- 'batch-size': 2,
108
- },
109
- config: ConfigFixture as any,
110
- version: 'cli-version',
111
- });
112
-
113
- expect(exitWithError).toBeCalledTimes(1);
114
- });
115
-
116
- it('fails if batchSize value is less than 2', async () => {
117
- await handlePush({
118
- argv: {
119
- upsert: true,
120
- api: 'spec.json',
121
- destination: '@org/my-api@1.0.0',
122
- branchName: 'test',
123
- public: true,
124
- 'job-id': '123',
125
- 'batch-size': 1,
126
- },
127
- config: ConfigFixture as any,
128
- version: 'cli-version',
129
- });
130
-
131
- expect(exitWithError).toBeCalledTimes(1);
132
- });
133
-
134
- it('push with --files', async () => {
135
- const mockConfig = { ...ConfigFixture, files: ['./resouces/1.md', './resouces/2.md'] } as any;
136
-
137
- (fs.statSync as jest.Mock).mockImplementation(() => {
138
- return { isDirectory: () => false, size: 10 };
139
- });
140
-
141
- await handlePush({
142
- argv: {
143
- upsert: true,
144
- api: 'spec.json',
145
- destination: '@org/my-api@1.0.0',
146
- public: true,
147
- files: ['./resouces/1.md', './resouces/2.md'],
148
- },
149
- config: mockConfig,
150
- version: 'cli-version',
151
- });
152
-
153
- expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
154
- filePaths: ['filePath', 'filePath', 'filePath'],
155
- isUpsert: true,
156
- isPublic: true,
157
- name: 'my-api',
158
- organizationId: 'org',
159
- rootFilePath: 'filePath',
160
- version: '1.0.0',
161
- });
162
- expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(3);
163
- });
164
-
165
- it('push should fail if organization not provided', async () => {
166
- await handlePush({
167
- argv: {
168
- upsert: true,
169
- api: 'spec.json',
170
- destination: 'test@v1',
171
- branchName: 'test',
172
- public: true,
173
- 'job-id': '123',
174
- 'batch-size': 2,
175
- },
176
- config: ConfigFixture as any,
177
- version: 'cli-version',
178
- });
179
-
180
- expect(exitWithError).toBeCalledTimes(1);
181
- expect(exitWithError).toBeCalledWith(
182
- `No organization provided, please use --organization option or specify the 'organization' field in the config file.`
183
- );
184
- });
185
-
186
- it('push should work with organization in config', async () => {
187
- const mockConfig = { ...ConfigFixture, organization: 'test_org' } as any;
188
- await handlePush({
189
- argv: {
190
- upsert: true,
191
- api: 'spec.json',
192
- destination: 'my-api@1.0.0',
193
- branchName: 'test',
194
- public: true,
195
- 'job-id': '123',
196
- 'batch-size': 2,
197
- },
198
- config: mockConfig,
199
- version: 'cli-version',
200
- });
201
-
202
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
203
- expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
204
- branch: 'test',
205
- filePaths: ['filePath'],
206
- isUpsert: true,
207
- isPublic: true,
208
- name: 'my-api',
209
- organizationId: 'test_org',
210
- rootFilePath: 'filePath',
211
- version: '1.0.0',
212
- batchId: '123',
213
- batchSize: 2,
214
- });
215
- });
216
-
217
- it('push should work if destination not provided but api in config is provided', async () => {
218
- const mockConfig = {
219
- ...ConfigFixture,
220
- organization: 'test_org',
221
- apis: { 'my-api@1.0.0': { root: 'path' } },
222
- } as any;
223
-
224
- await handlePush({
225
- argv: {
226
- upsert: true,
227
- branchName: 'test',
228
- public: true,
229
- 'job-id': '123',
230
- 'batch-size': 2,
231
- },
232
- config: mockConfig,
233
- version: 'cli-version',
234
- });
235
-
236
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
237
- });
238
-
239
- it('push should fail if apis not provided', async () => {
240
- const mockConfig = { organization: 'test_org', apis: {} } as any;
241
-
242
- await handlePush({
243
- argv: {
244
- upsert: true,
245
- branchName: 'test',
246
- public: true,
247
- 'job-id': '123',
248
- 'batch-size': 2,
249
- },
250
- config: mockConfig,
251
- version: 'cli-version',
252
- });
253
-
254
- expect(exitWithError).toBeCalledTimes(1);
255
- expect(exitWithError).toHaveBeenLastCalledWith(
256
- 'Api not found. Please make sure you have provided the correct data in the config file.'
257
- );
258
- });
259
-
260
- it('push should fail if destination not provided', async () => {
261
- const mockConfig = { organization: 'test_org', apis: {} } as any;
262
-
263
- await handlePush({
264
- argv: {
265
- upsert: true,
266
- api: 'api.yaml',
267
- branchName: 'test',
268
- public: true,
269
- 'job-id': '123',
270
- 'batch-size': 2,
271
- },
272
- config: mockConfig,
273
- version: 'cli-version',
274
- });
275
-
276
- expect(exitWithError).toBeCalledTimes(1);
277
- expect(exitWithError).toHaveBeenLastCalledWith(
278
- 'No destination provided, please use --destination option to provide destination.'
279
- );
280
- });
281
-
282
- it('push should fail if destination format is not valid', async () => {
283
- const mockConfig = { organization: 'test_org', apis: {} } as any;
284
-
285
- await handlePush({
286
- argv: {
287
- upsert: true,
288
- destination: 'name/v1',
289
- branchName: 'test',
290
- public: true,
291
- 'job-id': '123',
292
- 'batch-size': 2,
293
- },
294
- config: mockConfig,
295
- version: 'cli-version',
296
- });
297
-
298
- expect(exitWithError).toHaveBeenCalledWith(
299
- `Destination argument value is not valid, please use the right format: ${yellow(
300
- '<api-name@api-version>'
301
- )}.`
302
- );
303
- });
304
-
305
- it('push should work and encode name with spaces', async () => {
306
- const encodeURIComponentSpy = jest.spyOn(global, 'encodeURIComponent');
307
-
308
- const mockConfig = {
309
- ...ConfigFixture,
310
- organization: 'test_org',
311
- apis: { 'my test api@v1': { root: 'path' } },
312
- } as any;
313
-
314
- await handlePush({
315
- argv: {
316
- upsert: true,
317
- destination: 'my test api@v1',
318
- branchName: 'test',
319
- public: true,
320
- 'job-id': '123',
321
- 'batch-size': 2,
322
- },
323
- config: mockConfig,
324
- version: 'cli-version',
325
- });
326
-
327
- expect(encodeURIComponentSpy).toHaveReturnedWith('my%20test%20api');
328
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
329
- });
330
- });
331
-
332
- describe('transformPush', () => {
333
- it('should adapt the existing syntax', () => {
334
- const cb = jest.fn();
335
- transformPush(cb)({
336
- argv: {
337
- apis: ['openapi.yaml', '@testing_org/main@v1'],
338
- },
339
- config: {} as any,
340
- version: 'cli-version',
341
- });
342
- expect(cb).toBeCalledWith({
343
- argv: {
344
- api: 'openapi.yaml',
345
- destination: '@testing_org/main@v1',
346
- },
347
- config: {},
348
- version: 'cli-version',
349
- });
350
- });
351
- it('should adapt the existing syntax (including branchName)', () => {
352
- const cb = jest.fn();
353
- transformPush(cb)({
354
- argv: {
355
- apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
356
- },
357
- config: {} as any,
358
- version: 'cli-version',
359
- });
360
- expect(cb).toBeCalledWith({
361
- argv: {
362
- api: 'openapi.yaml',
363
- destination: '@testing_org/main@v1',
364
- branchName: 'other',
365
- },
366
- config: {},
367
- version: 'cli-version',
368
- });
369
- });
370
- it('should use --branch option firstly', () => {
371
- const cb = jest.fn();
372
- transformPush(cb)({
373
- argv: {
374
- apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
375
- branch: 'priority-branch',
376
- },
377
- config: {} as any,
378
- version: 'cli-version',
379
- });
380
- expect(cb).toBeCalledWith({
381
- argv: {
382
- api: 'openapi.yaml',
383
- destination: '@testing_org/main@v1',
384
- branchName: 'priority-branch',
385
- },
386
- config: {},
387
- version: 'cli-version',
388
- });
389
- });
390
- it('should work for a destination only', () => {
391
- const cb = jest.fn();
392
- transformPush(cb)({
393
- argv: {
394
- apis: ['main@v1'],
395
- },
396
- config: {} as any,
397
- version: 'cli-version',
398
- });
399
- expect(cb).toBeCalledWith({
400
- argv: {
401
- destination: 'main@v1',
402
- },
403
- config: {},
404
- version: 'cli-version',
405
- });
406
- });
407
- it('should work for a api only', () => {
408
- const cb = jest.fn();
409
- transformPush(cb)({
410
- argv: {
411
- apis: ['test.yaml'],
412
- },
413
- config: {} as any,
414
- version: 'cli-version',
415
- });
416
- expect(cb).toBeCalledWith({
417
- argv: {
418
- api: 'test.yaml',
419
- },
420
- config: {},
421
- version: 'cli-version',
422
- });
423
- });
424
-
425
- it('should use destination from option', () => {
426
- const cb = jest.fn();
427
- transformPush(cb)({
428
- argv: {
429
- apis: ['test.yaml', 'test@v1'],
430
- destination: 'main@v1',
431
- },
432
- config: {} as any,
433
- version: 'cli-version',
434
- });
435
- expect(cb).toBeCalledWith({
436
- argv: {
437
- destination: 'main@v1',
438
- api: 'test.yaml',
439
- },
440
- config: {},
441
- version: 'cli-version',
442
- });
443
- });
444
-
445
- it('should use --job-id option firstly', () => {
446
- const cb = jest.fn();
447
- transformPush(cb)({
448
- argv: {
449
- 'batch-id': 'b-123',
450
- 'job-id': 'j-123',
451
- apis: ['test'],
452
- branch: 'test',
453
- destination: 'main@v1',
454
- },
455
- config: {} as any,
456
- version: 'cli-version',
457
- });
458
- expect(cb).toBeCalledWith({
459
- argv: {
460
- 'job-id': 'j-123',
461
- api: 'test',
462
- branchName: 'test',
463
- destination: 'main@v1',
464
- },
465
- config: {},
466
- version: 'cli-version',
467
- });
468
- });
469
- it('should accept no arguments at all', () => {
470
- const cb = jest.fn();
471
- transformPush(cb)({ argv: {}, config: {} as any, version: 'cli-version' });
472
- expect(cb).toBeCalledWith({ argv: {}, config: {}, version: 'cli-version' });
473
- });
474
- });
475
-
476
- describe('getDestinationProps', () => {
477
- it('should get valid destination props for the full destination syntax', () => {
478
- expect(getDestinationProps('@testing_org/main@v1', 'org-from-config')).toEqual({
479
- organizationId: 'testing_org',
480
- name: 'main',
481
- version: 'v1',
482
- });
483
- });
484
- it('should fallback the organizationId from a config for the short destination syntax', () => {
485
- expect(getDestinationProps('main@v1', 'org-from-config')).toEqual({
486
- organizationId: 'org-from-config',
487
- name: 'main',
488
- version: 'v1',
489
- });
490
- });
491
- it('should fallback the organizationId from a config if no destination provided', () => {
492
- expect(getDestinationProps(undefined, 'org-from-config')).toEqual({
493
- organizationId: 'org-from-config',
494
- });
495
- });
496
- it('should return empty organizationId if there is no one found', () => {
497
- expect(getDestinationProps('main@v1', undefined)).toEqual({
498
- organizationId: undefined,
499
- name: 'main',
500
- version: 'v1',
501
- });
502
- });
503
- it('should return organizationId from destination string', () => {
504
- expect(getDestinationProps('@test-org/main@main-v1', undefined)).toEqual({
505
- organizationId: 'test-org',
506
- name: 'main',
507
- version: 'main-v1',
508
- });
509
- });
510
-
511
- it('should return organizationId, version and empty name from destination string', () => {
512
- expect(getDestinationProps('@test_org/@main_v1', undefined)).toEqual({
513
- organizationId: 'test_org',
514
- name: '',
515
- version: 'main_v1',
516
- });
517
- });
518
-
519
- it('should validate organizationId with space and version with dot', () => {
520
- expect(getDestinationProps('@test org/simple_name@main.v1', undefined)).toEqual({
521
- organizationId: 'test org',
522
- name: 'simple_name',
523
- version: 'main.v1',
524
- });
525
- });
526
-
527
- it('should not work with "@" in destination name', () => {
528
- expect(getDestinationProps('@test org/simple@name@main.v1', undefined)).toEqual({
529
- organizationId: undefined,
530
- name: undefined,
531
- version: undefined,
532
- });
533
- });
534
- });
535
-
536
- describe('getApiRoot', () => {
537
- let config: Config = {
538
- apis: {
539
- 'main@v1': {
540
- root: 'openapi.yaml',
541
- },
542
- main: {
543
- root: 'latest.yaml',
544
- },
545
- },
546
- } as unknown as Config;
547
- it('should resolve the correct api for a valid name & version', () => {
548
- expect(getApiRoot({ name: 'main', version: 'v1', config })).toEqual('openapi.yaml');
549
- });
550
- it('should resolve the latest version of api if there is no matching version', () => {
551
- expect(getApiRoot({ name: 'main', version: 'latest', config })).toEqual('latest.yaml');
552
- });
553
- });
@@ -1,81 +0,0 @@
1
- import AbortController from 'abort-controller';
2
- import fetchWithTimeout from '../utils/fetch-with-timeout';
3
- import { getProxyAgent } from '@redocly/openapi-core';
4
- import { HttpsProxyAgent } from 'https-proxy-agent';
5
-
6
- jest.mock('@redocly/openapi-core');
7
-
8
- const signalInstance = new AbortController().signal;
9
-
10
- const mockFetch = jest.fn(() =>
11
- Promise.resolve({
12
- ok: true,
13
- status: 200,
14
- json: () => Promise.resolve({}),
15
- headers: new Headers(),
16
- statusText: 'OK',
17
- redirected: false,
18
- type: 'default',
19
- url: '',
20
- clone: () => ({} as Response),
21
- body: null,
22
- bodyUsed: false,
23
- arrayBuffer: async () => new ArrayBuffer(0),
24
- blob: async () => new Blob(),
25
- formData: async () => new FormData(),
26
- text: async () => '',
27
- signal: signalInstance,
28
- dispatcher: undefined,
29
- } as Response)
30
- );
31
-
32
- const originalFetch = global.fetch;
33
- global.fetch = mockFetch;
34
-
35
- describe('fetchWithTimeout', () => {
36
- beforeAll(() => {
37
- // @ts-ignore
38
- global.setTimeout = jest.fn();
39
- global.clearTimeout = jest.fn();
40
- });
41
-
42
- beforeEach(() => {
43
- (getProxyAgent as jest.Mock).mockReturnValueOnce(undefined);
44
- });
45
-
46
- afterAll(() => {
47
- global.fetch = originalFetch;
48
- });
49
-
50
- it('should call fetch with signal', async () => {
51
- await fetchWithTimeout('url', { timeout: 1000 });
52
-
53
- expect(global.setTimeout).toHaveBeenCalledTimes(1);
54
- expect(global.fetch).toHaveBeenCalledWith(
55
- 'url',
56
- expect.objectContaining({
57
- signal: expect.any(AbortSignal),
58
- dispatcher: undefined,
59
- })
60
- );
61
- expect(global.clearTimeout).toHaveBeenCalledTimes(1);
62
- });
63
-
64
- it('should call fetch with proxy agent', async () => {
65
- (getProxyAgent as jest.Mock).mockRestore();
66
- const proxyAgent = new HttpsProxyAgent('http://localhost');
67
- (getProxyAgent as jest.Mock).mockReturnValueOnce(proxyAgent);
68
-
69
- await fetchWithTimeout('url');
70
-
71
- expect(global.fetch).toHaveBeenCalledWith('url', { dispatcher: proxyAgent });
72
- });
73
-
74
- it('should call fetch without signal when timeout is not passed', async () => {
75
- await fetchWithTimeout('url');
76
-
77
- expect(global.setTimeout).not.toHaveBeenCalled();
78
- expect(global.fetch).toHaveBeenCalledWith('url', { agent: undefined });
79
- expect(global.clearTimeout).not.toHaveBeenCalled();
80
- });
81
- });
@@ -1,21 +0,0 @@
1
- export const ConfigFixture = {
2
- configFile: null,
3
- styleguide: {
4
- addIgnore: jest.fn(),
5
- skipRules: jest.fn(),
6
- skipPreprocessors: jest.fn(),
7
- saveIgnore: jest.fn(),
8
- skipDecorators: jest.fn(),
9
- ignore: null,
10
- decorators: {
11
- oas2: {},
12
- oas3_0: {},
13
- oas3_1: {},
14
- },
15
- preprocessors: {
16
- oas2: {},
17
- oas3_0: {},
18
- oas3_1: {},
19
- },
20
- },
21
- };
File without changes
File without changes
File without changes
@@ -1,51 +0,0 @@
1
- import { Spinner } from '../utils/spinner';
2
- import * as process from 'process';
3
-
4
- jest.useFakeTimers();
5
-
6
- describe('Spinner', () => {
7
- const IS_TTY = process.stdout.isTTY;
8
-
9
- let writeMock: jest.SpyInstance;
10
- let spinner: Spinner;
11
-
12
- beforeEach(() => {
13
- process.stdout.isTTY = true;
14
- writeMock = jest.spyOn(process.stdout, 'write').mockImplementation(jest.fn());
15
- spinner = new Spinner();
16
- });
17
-
18
- afterEach(() => {
19
- writeMock.mockRestore();
20
- jest.clearAllTimers();
21
- });
22
-
23
- afterAll(() => {
24
- process.stdout.isTTY = IS_TTY;
25
- });
26
-
27
- it('starts the spinner', () => {
28
- spinner.start('Loading');
29
- jest.advanceTimersByTime(100);
30
- expect(writeMock).toHaveBeenCalledWith('\r⠋ Loading');
31
- });
32
-
33
- it('stops the spinner', () => {
34
- spinner.start('Loading');
35
- spinner.stop();
36
- expect(writeMock).toHaveBeenCalledWith('\r');
37
- });
38
-
39
- it('should write 3 frames', () => {
40
- spinner.start('Loading');
41
- jest.advanceTimersByTime(300);
42
- expect(writeMock).toHaveBeenCalledTimes(3);
43
- });
44
-
45
- it('should call write 1 times if CI set to true', () => {
46
- process.stdout.isTTY = false;
47
- spinner.start('Loading');
48
- jest.advanceTimersByTime(300);
49
- expect(writeMock).toHaveBeenCalledTimes(1);
50
- });
51
- });