@redocly/cli 1.34.3 → 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 +15 -16
  176. package/CHANGELOG.md +0 -770
  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,653 +0,0 @@
1
- import { handlePushStatus } from '../push-status';
2
- import { PushResponse } from '../../api/types';
3
-
4
- const remotes = {
5
- getPush: jest.fn(),
6
- getRemotesList: jest.fn(),
7
- };
8
-
9
- jest.mock('colorette', () => ({
10
- green: (str: string) => str,
11
- yellow: (str: string) => str,
12
- red: (str: string) => str,
13
- gray: (str: string) => str,
14
- magenta: (str: string) => str,
15
- cyan: (str: string) => str,
16
- }));
17
-
18
- jest.mock('../../api', () => ({
19
- ...jest.requireActual('../../api'),
20
- ReuniteApi: jest.fn().mockImplementation(function (this: any, ...args) {
21
- this.remotes = remotes;
22
- this.reportSunsetWarnings = jest.fn();
23
- }),
24
- }));
25
-
26
- jest.mock('@redocly/openapi-core', () => ({
27
- pause: jest.requireActual('@redocly/openapi-core').pause,
28
- }));
29
-
30
- describe('handlePushStatus()', () => {
31
- const mockConfig = { apis: {} } as any;
32
-
33
- const commitStub: PushResponse['commit'] = {
34
- message: 'test-commit-message',
35
- branchName: 'test-branch-name',
36
- sha: null,
37
- url: null,
38
- createdAt: null,
39
- namespaceId: null,
40
- repositoryId: null,
41
- author: {
42
- name: 'test-author-name',
43
- email: 'test-author-email',
44
- image: null,
45
- },
46
- statuses: [],
47
- };
48
-
49
- const pushResponseStub: PushResponse = {
50
- id: 'test-push-id',
51
- remoteId: 'test-remote-id',
52
- replace: false,
53
- scoutJobId: null,
54
- uploadedFiles: [],
55
- commit: commitStub,
56
- remote: { commits: [] },
57
- isOutdated: false,
58
- isMainBranch: false,
59
- hasChanges: true,
60
- status: {
61
- preview: {
62
- scorecard: [],
63
- deploy: {
64
- url: 'https://preview-test-url',
65
- status: 'success',
66
- },
67
- },
68
- production: {
69
- scorecard: [],
70
- deploy: {
71
- url: 'https://production-test-url',
72
- status: 'success',
73
- },
74
- },
75
- },
76
- };
77
-
78
- beforeEach(() => {
79
- jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
80
- jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
81
- });
82
-
83
- afterEach(() => {
84
- jest.clearAllMocks();
85
- });
86
-
87
- it('should throw error if organization not provided', async () => {
88
- await expect(
89
- handlePushStatus({
90
- argv: {
91
- domain: 'test-domain',
92
- organization: '',
93
- project: 'test-project',
94
- pushId: 'test-push-id',
95
- },
96
- config: mockConfig,
97
- version: 'cli-version',
98
- })
99
- ).rejects.toThrowErrorMatchingInlineSnapshot(
100
- `"No organization provided, please use --organization option or specify the 'organization' field in the config file."`
101
- );
102
-
103
- expect(process.stderr.write).toHaveBeenCalledWith(
104
- `No organization provided, please use --organization option or specify the 'organization' field in the config file.` +
105
- '\n\n'
106
- );
107
- });
108
-
109
- it('should print success push status for preview-build', async () => {
110
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
111
- remotes.getPush.mockResolvedValueOnce(pushResponseStub);
112
-
113
- await handlePushStatus({
114
- argv: {
115
- domain: 'test-domain',
116
- organization: 'test-org',
117
- project: 'test-project',
118
- pushId: 'test-push-id',
119
- },
120
- config: mockConfig,
121
- version: 'cli-version',
122
- });
123
- expect(process.stdout.write).toHaveBeenCalledTimes(1);
124
- expect(process.stdout.write).toHaveBeenCalledWith(
125
- '🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n'
126
- );
127
- });
128
-
129
- it('should print success push status for preview and production builds', async () => {
130
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
131
- remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: true });
132
-
133
- await 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
- });
143
- expect(process.stdout.write).toHaveBeenCalledTimes(2);
144
- expect(process.stdout.write).toHaveBeenCalledWith(
145
- '🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n'
146
- );
147
- expect(process.stdout.write).toHaveBeenCalledWith(
148
- '🚀 Production deploy success.\nProduction URL: https://production-test-url\n'
149
- );
150
- });
151
-
152
- it('should print failed push status for preview build', async () => {
153
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
154
-
155
- remotes.getPush.mockResolvedValue({
156
- isOutdated: false,
157
- hasChanges: true,
158
- status: {
159
- preview: { deploy: { status: 'failed', url: 'https://preview-test-url' }, scorecard: [] },
160
- },
161
- });
162
-
163
- await expect(
164
- handlePushStatus({
165
- argv: {
166
- domain: 'test-domain',
167
- organization: 'test-org',
168
- project: 'test-project',
169
- pushId: 'test-push-id',
170
- },
171
- config: mockConfig,
172
- version: 'cli-version',
173
- })
174
- ).rejects.toThrowErrorMatchingInlineSnapshot(`
175
- "❌ Preview deploy fail.
176
- Preview URL: https://preview-test-url"
177
- `);
178
-
179
- expect(process.stderr.write).toHaveBeenCalledWith(
180
- '❌ Preview deploy fail.\nPreview URL: https://preview-test-url' + '\n\n'
181
- );
182
- });
183
-
184
- it('should print success push status for preview build and print scorecards', async () => {
185
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
186
-
187
- remotes.getPush.mockResolvedValue({
188
- isOutdated: false,
189
- hasChanges: true,
190
- status: {
191
- preview: {
192
- deploy: { status: 'success', url: 'https://preview-test-url' },
193
- scorecard: [
194
- {
195
- name: 'test-name',
196
- status: 'success',
197
- description: 'test-description',
198
- url: 'test-url',
199
- },
200
- ],
201
- },
202
- },
203
- });
204
-
205
- await handlePushStatus({
206
- argv: {
207
- domain: 'test-domain',
208
- organization: 'test-org',
209
- project: 'test-project',
210
- pushId: 'test-push-id',
211
- },
212
- config: mockConfig,
213
- version: 'cli-version',
214
- });
215
- expect(process.stdout.write).toHaveBeenCalledTimes(4);
216
- expect(process.stdout.write).toHaveBeenCalledWith(
217
- '🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n'
218
- );
219
- expect(process.stdout.write).toHaveBeenCalledWith('\nScorecard:');
220
- expect(process.stdout.write).toHaveBeenCalledWith(
221
- '\n Name: test-name\n Status: success\n URL: test-url\n Description: test-description\n'
222
- );
223
- expect(process.stdout.write).toHaveBeenCalledWith('\n');
224
- });
225
-
226
- it('should print message if there is no changes', async () => {
227
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
228
-
229
- remotes.getPush.mockResolvedValueOnce({
230
- isOutdated: false,
231
- hasChanges: false,
232
- status: {
233
- preview: { deploy: { status: 'skipped', url: 'https://preview-test-url' }, scorecard: [] },
234
- production: {
235
- deploy: { status: 'skipped', url: null },
236
- scorecard: [],
237
- },
238
- },
239
- });
240
-
241
- await handlePushStatus({
242
- argv: {
243
- domain: 'test-domain',
244
- organization: 'test-org',
245
- project: 'test-project',
246
- pushId: 'test-push-id',
247
- wait: true,
248
- },
249
- config: mockConfig,
250
- version: 'cli-version',
251
- });
252
-
253
- expect(process.stderr.write).toHaveBeenCalledWith(
254
- 'Files not added to your project. Reason: no changes.\n'
255
- );
256
- });
257
-
258
- describe('return value', () => {
259
- it('should return preview deployment info', async () => {
260
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
261
- remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: false });
262
-
263
- const result = await handlePushStatus({
264
- argv: {
265
- domain: 'test-domain',
266
- organization: 'test-org',
267
- project: 'test-project',
268
- pushId: 'test-push-id',
269
- },
270
- config: mockConfig,
271
- version: 'cli-version',
272
- });
273
-
274
- expect(result).toEqual({
275
- preview: {
276
- deploy: {
277
- status: 'success',
278
- url: 'https://preview-test-url',
279
- },
280
- scorecard: [],
281
- },
282
- production: null,
283
- commit: commitStub,
284
- });
285
- });
286
-
287
- it('should return preview and production deployment info', async () => {
288
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
289
- remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: true });
290
-
291
- const result = await handlePushStatus({
292
- argv: {
293
- domain: 'test-domain',
294
- organization: 'test-org',
295
- project: 'test-project',
296
- pushId: 'test-push-id',
297
- },
298
- config: mockConfig,
299
- version: 'cli-version',
300
- });
301
-
302
- expect(result).toEqual({
303
- preview: {
304
- deploy: {
305
- status: 'success',
306
- url: 'https://preview-test-url',
307
- },
308
- scorecard: [],
309
- },
310
- production: {
311
- deploy: {
312
- status: 'success',
313
- url: 'https://production-test-url',
314
- },
315
- scorecard: [],
316
- },
317
- commit: commitStub,
318
- });
319
- });
320
- });
321
-
322
- describe('"wait" option', () => {
323
- it('should wait for preview "success" deployment status', async () => {
324
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
325
-
326
- remotes.getPush.mockResolvedValueOnce({
327
- ...pushResponseStub,
328
- status: {
329
- preview: {
330
- deploy: { status: 'pending', url: 'https://preview-test-url' },
331
- scorecard: [],
332
- },
333
- },
334
- });
335
-
336
- remotes.getPush.mockResolvedValueOnce({
337
- ...pushResponseStub,
338
- status: {
339
- preview: {
340
- deploy: { status: 'running', url: 'https://preview-test-url' },
341
- scorecard: [],
342
- },
343
- },
344
- });
345
-
346
- remotes.getPush.mockResolvedValueOnce({
347
- ...pushResponseStub,
348
- status: {
349
- preview: {
350
- deploy: { status: 'success', url: 'https://preview-test-url' },
351
- scorecard: [],
352
- },
353
- },
354
- });
355
-
356
- const result = await handlePushStatus({
357
- argv: {
358
- domain: 'test-domain',
359
- organization: 'test-org',
360
- project: 'test-project',
361
- pushId: 'test-push-id',
362
- 'retry-interval': 0.5, // 500 ms
363
- wait: true,
364
- },
365
- config: mockConfig,
366
- version: 'cli-version',
367
- });
368
-
369
- expect(result).toEqual({
370
- preview: {
371
- deploy: {
372
- status: 'success',
373
- url: 'https://preview-test-url',
374
- },
375
- scorecard: [],
376
- },
377
- production: null,
378
- commit: commitStub,
379
- });
380
- });
381
-
382
- it('should wait for production "success" status after preview "success" status', async () => {
383
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
384
-
385
- remotes.getPush.mockResolvedValueOnce({
386
- ...pushResponseStub,
387
- isMainBranch: true,
388
- status: {
389
- preview: {
390
- deploy: { status: 'success', url: 'https://preview-test-url' },
391
- scorecard: [],
392
- },
393
- production: {
394
- deploy: { status: 'pending', url: 'https://production-test-url' },
395
- scorecard: [],
396
- },
397
- },
398
- });
399
-
400
- remotes.getPush.mockResolvedValueOnce({
401
- ...pushResponseStub,
402
- isMainBranch: true,
403
- status: {
404
- preview: {
405
- deploy: { status: 'success', url: 'https://preview-test-url' },
406
- scorecard: [],
407
- },
408
- production: {
409
- deploy: { status: 'running', url: 'https://production-test-url' },
410
- scorecard: [],
411
- },
412
- },
413
- });
414
-
415
- remotes.getPush.mockResolvedValueOnce({
416
- ...pushResponseStub,
417
- isMainBranch: true,
418
- status: {
419
- preview: {
420
- deploy: { status: 'success', url: 'https://preview-test-url' },
421
- scorecard: [],
422
- },
423
- production: {
424
- deploy: { status: 'success', url: 'https://production-test-url' },
425
- scorecard: [],
426
- },
427
- },
428
- });
429
-
430
- const result = await handlePushStatus({
431
- argv: {
432
- domain: 'test-domain',
433
- organization: 'test-org',
434
- project: 'test-project',
435
- pushId: 'test-push-id',
436
- 'retry-interval': 0.5, // 500 ms
437
- wait: true,
438
- },
439
- config: mockConfig,
440
- version: 'cli-version',
441
- });
442
-
443
- expect(result).toEqual({
444
- preview: {
445
- deploy: { status: 'success', url: 'https://preview-test-url' },
446
- scorecard: [],
447
- },
448
- production: {
449
- deploy: { status: 'success', url: 'https://production-test-url' },
450
- scorecard: [],
451
- },
452
- commit: commitStub,
453
- });
454
- });
455
- });
456
-
457
- describe('"continue-on-deploy-failures" option', () => {
458
- it('should throw error if option value is false', async () => {
459
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
460
-
461
- remotes.getPush.mockResolvedValueOnce({
462
- ...pushResponseStub,
463
- status: {
464
- preview: {
465
- deploy: { status: 'failed', url: 'https://preview-test-url' },
466
- scorecard: [],
467
- },
468
- },
469
- });
470
-
471
- await expect(
472
- handlePushStatus({
473
- argv: {
474
- domain: 'test-domain',
475
- organization: 'test-org',
476
- project: 'test-project',
477
- pushId: 'test-push-id',
478
- 'continue-on-deploy-failures': false,
479
- },
480
- config: mockConfig,
481
- version: 'cli-version',
482
- })
483
- ).rejects.toThrowErrorMatchingInlineSnapshot(`
484
- "❌ Preview deploy fail.
485
- Preview URL: https://preview-test-url"
486
- `);
487
- });
488
-
489
- it('should not throw error if option value is true', async () => {
490
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
491
-
492
- remotes.getPush.mockResolvedValueOnce({
493
- ...pushResponseStub,
494
- status: {
495
- preview: {
496
- deploy: { status: 'failed', url: 'https://preview-test-url' },
497
- scorecard: [],
498
- },
499
- },
500
- });
501
-
502
- await expect(
503
- handlePushStatus({
504
- argv: {
505
- domain: 'test-domain',
506
- organization: 'test-org',
507
- project: 'test-project',
508
- pushId: 'test-push-id',
509
- 'continue-on-deploy-failures': true,
510
- },
511
- config: mockConfig,
512
- version: 'cli-version',
513
- })
514
- ).resolves.toStrictEqual({
515
- preview: {
516
- deploy: { status: 'failed', url: 'https://preview-test-url' },
517
- scorecard: [],
518
- },
519
- production: null,
520
- commit: commitStub,
521
- });
522
- });
523
- });
524
-
525
- describe('"onRetry" callback', () => {
526
- it('should be called when command retries request to API in wait mode for preview deploy', async () => {
527
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
528
-
529
- remotes.getPush.mockResolvedValueOnce({
530
- ...pushResponseStub,
531
- status: {
532
- preview: {
533
- deploy: { status: 'pending', url: 'https://preview-test-url' },
534
- scorecard: [],
535
- },
536
- },
537
- });
538
-
539
- remotes.getPush.mockResolvedValueOnce({
540
- ...pushResponseStub,
541
- status: {
542
- preview: {
543
- deploy: { status: 'running', url: 'https://preview-test-url' },
544
- scorecard: [],
545
- },
546
- },
547
- });
548
-
549
- remotes.getPush.mockResolvedValueOnce({
550
- ...pushResponseStub,
551
- status: {
552
- preview: {
553
- deploy: { status: 'success', url: 'https://preview-test-url' },
554
- scorecard: [],
555
- },
556
- },
557
- });
558
-
559
- const onRetrySpy = jest.fn();
560
-
561
- const result = await handlePushStatus({
562
- argv: {
563
- domain: 'test-domain',
564
- organization: 'test-org',
565
- project: 'test-project',
566
- pushId: 'test-push-id',
567
- wait: true,
568
- 'retry-interval': 0.5, // 500 ms
569
- onRetry: onRetrySpy,
570
- },
571
- config: mockConfig,
572
- version: 'cli-version',
573
- });
574
-
575
- expect(onRetrySpy).toBeCalledTimes(2);
576
-
577
- // first retry
578
- expect(onRetrySpy).toHaveBeenNthCalledWith(1, {
579
- preview: {
580
- deploy: {
581
- status: 'pending',
582
- url: 'https://preview-test-url',
583
- },
584
- scorecard: [],
585
- },
586
- production: null,
587
- commit: commitStub,
588
- });
589
-
590
- // second retry
591
- expect(onRetrySpy).toHaveBeenNthCalledWith(2, {
592
- preview: {
593
- deploy: {
594
- status: 'running',
595
- url: 'https://preview-test-url',
596
- },
597
- scorecard: [],
598
- },
599
- production: null,
600
- commit: commitStub,
601
- });
602
-
603
- // final result
604
- expect(result).toEqual({
605
- preview: {
606
- deploy: {
607
- status: 'success',
608
- url: 'https://preview-test-url',
609
- },
610
- scorecard: [],
611
- },
612
- production: null,
613
- commit: commitStub,
614
- });
615
- });
616
- });
617
-
618
- describe('"max-execution-time" option', () => {
619
- it('should throw error in case "max-execution-time" was exceeded', async () => {
620
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
621
-
622
- // Stuck deployment simulation
623
- remotes.getPush.mockResolvedValue({
624
- ...pushResponseStub,
625
- status: {
626
- preview: {
627
- deploy: { status: 'pending', url: 'https://preview-test-url' },
628
- scorecard: [],
629
- },
630
- },
631
- });
632
-
633
- await expect(
634
- handlePushStatus({
635
- argv: {
636
- domain: 'test-domain',
637
- organization: 'test-org',
638
- project: 'test-project',
639
- pushId: 'test-push-id',
640
- 'retry-interval': 2, // seconds
641
- 'max-execution-time': 1, // seconds
642
- wait: true,
643
- },
644
- config: mockConfig,
645
- version: 'cli-version',
646
- })
647
- ).rejects.toThrowErrorMatchingInlineSnapshot(`
648
- "✗ Failed to get push status. Reason: Timeout exceeded.
649
- "
650
- `);
651
- });
652
- });
653
- });