@redocly/cli 1.6.0 → 1.8.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 (126) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +5 -5
  3. package/lib/__tests__/commands/build-docs.test.js +3 -3
  4. package/lib/__tests__/commands/bundle.test.js +5 -5
  5. package/lib/__tests__/commands/join.test.js +11 -11
  6. package/lib/__tests__/commands/lint.test.js +14 -14
  7. package/lib/__tests__/commands/push-region.test.js +1 -1
  8. package/lib/__tests__/commands/push.test.js +11 -11
  9. package/lib/__tests__/fetch-with-timeout.test.js +4 -13
  10. package/lib/__tests__/spinner.test.js +43 -0
  11. package/lib/__tests__/utils.test.js +54 -36
  12. package/lib/__tests__/wrapper.test.js +8 -8
  13. package/lib/cms/api/__tests__/api-keys.test.d.ts +1 -0
  14. package/lib/cms/api/__tests__/api-keys.test.js +26 -0
  15. package/lib/cms/api/__tests__/api.client.test.d.ts +1 -0
  16. package/lib/cms/api/__tests__/api.client.test.js +217 -0
  17. package/lib/cms/api/__tests__/domains.test.d.ts +1 -0
  18. package/lib/cms/api/__tests__/domains.test.js +13 -0
  19. package/lib/cms/api/api-client.d.ts +50 -0
  20. package/lib/cms/api/api-client.js +148 -0
  21. package/lib/cms/api/api-keys.d.ts +1 -0
  22. package/lib/cms/api/api-keys.js +24 -0
  23. package/lib/cms/api/domains.d.ts +1 -0
  24. package/lib/cms/api/domains.js +12 -0
  25. package/lib/cms/api/index.d.ts +3 -0
  26. package/lib/cms/api/index.js +19 -0
  27. package/lib/cms/api/types.d.ts +91 -0
  28. package/lib/cms/api/types.js +2 -0
  29. package/lib/cms/commands/__tests__/push-status.test.d.ts +1 -0
  30. package/lib/cms/commands/__tests__/push-status.test.js +164 -0
  31. package/lib/cms/commands/__tests__/push.test.d.ts +1 -0
  32. package/lib/cms/commands/__tests__/push.test.js +226 -0
  33. package/lib/cms/commands/push-status.d.ts +12 -0
  34. package/lib/cms/commands/push-status.js +150 -0
  35. package/lib/cms/commands/push.d.ts +23 -0
  36. package/lib/cms/commands/push.js +142 -0
  37. package/lib/cms/utils.d.ts +2 -0
  38. package/lib/cms/utils.js +6 -0
  39. package/lib/commands/build-docs/index.js +4 -4
  40. package/lib/commands/build-docs/utils.js +2 -2
  41. package/lib/commands/bundle.js +13 -13
  42. package/lib/commands/join.js +25 -25
  43. package/lib/commands/lint.js +10 -10
  44. package/lib/commands/login.js +2 -2
  45. package/lib/commands/preview-docs/index.js +4 -4
  46. package/lib/commands/preview-docs/preview-server/preview-server.js +2 -2
  47. package/lib/commands/preview-project/constants.d.ts +14 -0
  48. package/lib/commands/preview-project/constants.js +22 -0
  49. package/lib/commands/preview-project/index.d.ts +2 -0
  50. package/lib/commands/preview-project/index.js +58 -0
  51. package/lib/commands/preview-project/types.d.ts +10 -0
  52. package/lib/commands/preview-project/types.js +2 -0
  53. package/lib/commands/push.d.ts +5 -0
  54. package/lib/commands/push.js +25 -17
  55. package/lib/commands/split/__tests__/index.test.js +2 -2
  56. package/lib/commands/split/index.js +20 -20
  57. package/lib/commands/stats.js +4 -4
  58. package/lib/index.d.ts +1 -1
  59. package/lib/index.js +169 -25
  60. package/lib/types.d.ts +9 -1
  61. package/lib/{__mocks__/utils.js → utils/__mocks__/miscellaneous.js} +1 -1
  62. package/lib/utils/assert-node-version.d.ts +1 -0
  63. package/lib/{fetch-with-timeout.js → utils/fetch-with-timeout.js} +2 -7
  64. package/lib/{utils.d.ts → utils/miscellaneous.d.ts} +1 -1
  65. package/lib/{utils.js → utils/miscellaneous.js} +20 -2
  66. package/lib/utils/spinner.d.ts +10 -0
  67. package/lib/utils/spinner.js +42 -0
  68. package/lib/{update-version-notifier.js → utils/update-version-notifier.js} +4 -4
  69. package/lib/wrapper.js +5 -5
  70. package/package.json +5 -3
  71. package/src/__tests__/commands/build-docs.test.ts +2 -2
  72. package/src/__tests__/commands/bundle.test.ts +2 -2
  73. package/src/__tests__/commands/join.test.ts +2 -2
  74. package/src/__tests__/commands/lint.test.ts +3 -3
  75. package/src/__tests__/commands/push-region.test.ts +1 -1
  76. package/src/__tests__/commands/push.test.ts +2 -2
  77. package/src/__tests__/fetch-with-timeout.test.ts +4 -16
  78. package/src/__tests__/spinner.test.ts +51 -0
  79. package/src/__tests__/utils.test.ts +20 -5
  80. package/src/__tests__/wrapper.test.ts +2 -2
  81. package/src/cms/api/__tests__/api-keys.test.ts +37 -0
  82. package/src/cms/api/__tests__/api.client.test.ts +275 -0
  83. package/src/cms/api/__tests__/domains.test.ts +15 -0
  84. package/src/cms/api/api-client.ts +199 -0
  85. package/src/cms/api/api-keys.ts +26 -0
  86. package/src/cms/api/domains.ts +11 -0
  87. package/src/cms/api/index.ts +3 -0
  88. package/src/cms/api/types.ts +101 -0
  89. package/src/cms/commands/__tests__/push-status.test.ts +212 -0
  90. package/src/cms/commands/__tests__/push.test.ts +293 -0
  91. package/src/cms/commands/push-status.ts +203 -0
  92. package/src/cms/commands/push.ts +215 -0
  93. package/src/cms/utils.ts +1 -0
  94. package/src/commands/build-docs/index.ts +1 -1
  95. package/src/commands/build-docs/utils.ts +1 -1
  96. package/src/commands/bundle.ts +2 -2
  97. package/src/commands/join.ts +2 -2
  98. package/src/commands/lint.ts +1 -1
  99. package/src/commands/login.ts +1 -1
  100. package/src/commands/preview-docs/index.ts +5 -1
  101. package/src/commands/preview-docs/preview-server/preview-server.ts +1 -1
  102. package/src/commands/preview-project/constants.ts +23 -0
  103. package/src/commands/preview-project/index.ts +58 -0
  104. package/src/commands/preview-project/types.ts +12 -0
  105. package/src/commands/push.ts +15 -1
  106. package/src/commands/split/__tests__/index.test.ts +3 -4
  107. package/src/commands/split/index.ts +5 -5
  108. package/src/commands/stats.ts +2 -2
  109. package/src/index.ts +184 -28
  110. package/src/types.ts +12 -1
  111. package/src/{__mocks__/utils.ts → utils/__mocks__/miscellaneous.ts} +1 -1
  112. package/src/{fetch-with-timeout.ts → utils/fetch-with-timeout.ts} +1 -6
  113. package/src/{utils.ts → utils/miscellaneous.ts} +20 -2
  114. package/src/utils/spinner.ts +50 -0
  115. package/src/{update-version-notifier.ts → utils/update-version-notifier.ts} +2 -2
  116. package/src/wrapper.ts +7 -2
  117. package/tsconfig.tsbuildinfo +1 -1
  118. /package/lib/{assert-node-version.d.ts → __tests__/spinner.test.d.ts} +0 -0
  119. /package/lib/{__mocks__/utils.d.ts → utils/__mocks__/miscellaneous.d.ts} +0 -0
  120. /package/lib/{assert-node-version.js → utils/assert-node-version.js} +0 -0
  121. /package/lib/{fetch-with-timeout.d.ts → utils/fetch-with-timeout.d.ts} +0 -0
  122. /package/lib/{js-utils.d.ts → utils/js-utils.d.ts} +0 -0
  123. /package/lib/{js-utils.js → utils/js-utils.js} +0 -0
  124. /package/lib/{update-version-notifier.d.ts → utils/update-version-notifier.d.ts} +0 -0
  125. /package/src/{assert-node-version.ts → utils/assert-node-version.ts} +0 -0
  126. /package/src/{js-utils.ts → utils/js-utils.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @redocly/cli
2
2
 
3
+ ## 1.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added a `push` and `push-status` command for use with future Redocly products.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated @redocly/openapi-core to v1.8.0.
12
+
13
+ ## 1.7.0
14
+
15
+ ### Minor Changes
16
+
17
+ - Added a `preview` command that starts a local preview server for Redocly projects that use products that are currently in a pre-release stage.
18
+
19
+ ### Patch Changes
20
+
21
+ - Fixed an issue with resolving references after splitting API descriptions written in the json format.
22
+ - Added filename extension support for more `x-codeSamples` languages.
23
+ - Fixed a problem where the linter incorrectly returned an error for valid examples that contain references.
24
+ - Updated @redocly/openapi-core to v1.7.0.
25
+
3
26
  ## 1.6.0
4
27
 
5
28
  ### Minor Changes
package/README.md CHANGED
@@ -28,7 +28,7 @@ Then you can use it as `redocly [command] [options]`, for example:
28
28
  redocly lint path-to-root-file.yaml
29
29
  ```
30
30
 
31
- Minimal required versions of Node.js and NPM are 14.19.0 and 7.0.0 respectively.
31
+ The minimum required versions of Node.js and NPM are 14.19.0 and 7.0.0 respectively.
32
32
 
33
33
  ### Docker
34
34
 
@@ -63,11 +63,11 @@ Your API reference docs are in `redoc-static.html` by default. You can customize
63
63
 
64
64
  ### Bundle multiple OpenAPI documents
65
65
 
66
- Having one massive OpenAPI description can be annoying, so most people split them up into multiple documents via `$ref`, only to later find out some tools don't support `$ref`, or don't support multiple documents?! Well fear not, because Redocly has a `bundle` command you can use to recombine all of those documents back into one single document. The bundled output Redocly CLI provides is clean, tidy, and looks like a human made it.
66
+ Having one massive OpenAPI description can be annoying, so most people split them up into multiple documents via `$ref`, only to later find out some tools don't support `$ref` or don't support multiple documents. Redocly CLI to the rescue! It has a `bundle` command you can use to recombine all of those documents back into one single document. The bundled output that Redocly CLI provides is clean, tidy, and looks like a human made it.
67
67
 
68
68
  ### Automate API guidelines with Linting
69
69
 
70
- Check your API matches the expected API guidelines by using the `lint` command. API guidelines are an important piece of API governance, it helps to keep APIs consistent (enforcing the same standards and naming conventions) but can also guide API teams through potential security hazards and other pitfalls. Automating API guidelines means you can keep APIs consistent and secure throughout their lifecycle. Even better, you can shape the design of the API before it even exists if you combine API linting with a design-first API workflow!
70
+ Check that your API matches the expected API guidelines by using the `lint` command. API guidelines are an important piece of API governance. They help to keep APIs consistent by enforcing the same standards and naming conventions, and they can also guide API teams through potential security hazards and other pitfalls. Automating API guidelines means you can keep APIs consistent and secure throughout their lifecycle. Even better, you can shape the design of the API before it even exists by combining API linting with a design-first API workflow.
71
71
 
72
72
  Our API linter is designed for speed on even large documents, and it's easy to run locally, in CI, or anywhere you need it. It's also designed for humans, with meaningful error messages to help you get your API right every time.
73
73
 
@@ -79,9 +79,9 @@ redocly lint openapi.yaml
79
79
 
80
80
  **Configure the rules** as you wish. Other API Linters use complicated identifiers like JSONPath, but Redocly makes life easy with simple expressions that understand the OpenAPI structure. You can either use the [built-in rules](https://redocly.com/docs/cli/rules) to mix-and-match your ideal API guidelines, or break out the tools to build your own.
81
81
 
82
- **Format the output** in whatever way you need, the `stylish` output is as good as it sounds, but if you need JSON or Checkstyle outputs to integrate with other tools, the lint command can output those too.
82
+ **Format the output** in whatever way you need. The `stylish` output is as good as it sounds, but if you need JSON or Checkstyle outputs to integrate with other tools, the `lint` command can output those too.
83
83
 
84
- **Multiple files supported** so you don't need to bundle your API description to lint it, just point Redocly CLI at the "entry point" (e.g.: `openapi.yaml`) and it handles the rest.
84
+ **Multiple files supported** so you don't need to bundle your API description to lint it; just point Redocly CLI at the "entry point" (e.g.: `openapi.yaml`) and it handles the rest.
85
85
 
86
86
  [Learn more about API standards and configuring Redocly rules](https://redocly.com/docs/cli/api-standards).
87
87
 
@@ -13,10 +13,10 @@ const redoc_1 = require("redoc");
13
13
  const server_1 = require("react-dom/server");
14
14
  const build_docs_1 = require("../../commands/build-docs");
15
15
  const utils_1 = require("../../commands/build-docs/utils");
16
- const utils_2 = require("../../utils");
16
+ const miscellaneous_1 = require("../../utils/miscellaneous");
17
17
  jest.mock('redoc');
18
18
  jest.mock('fs');
19
- jest.mock('../../utils');
19
+ jest.mock('../../utils/miscellaneous');
20
20
  const config = {
21
21
  output: '',
22
22
  title: 'Test',
@@ -50,7 +50,7 @@ describe('build-docs', () => {
50
50
  api: '../some-path/openapi.yaml',
51
51
  }, {});
52
52
  expect(redoc_1.loadAndBundleSpec).toBeCalledTimes(1);
53
- expect(utils_2.getFallbackApisOrExit).toBeCalledTimes(1);
53
+ expect(miscellaneous_1.getFallbackApisOrExit).toBeCalledTimes(1);
54
54
  expect(processExitMock).toBeCalledTimes(0);
55
55
  }));
56
56
  });
@@ -11,10 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const openapi_core_1 = require("@redocly/openapi-core");
13
13
  const bundle_1 = require("../../commands/bundle");
14
- const utils_1 = require("../../utils");
14
+ const miscellaneous_1 = require("../../utils/miscellaneous");
15
15
  const wrapper_1 = require("../../wrapper");
16
16
  jest.mock('@redocly/openapi-core');
17
- jest.mock('../../utils');
17
+ jest.mock('../../utils/miscellaneous');
18
18
  openapi_core_1.getMergedConfig.mockImplementation((config) => config);
19
19
  describe('bundle', () => {
20
20
  let processExitMock;
@@ -107,8 +107,8 @@ describe('bundle', () => {
107
107
  format: 'codeframe',
108
108
  lint: false,
109
109
  });
110
- expect(utils_1.handleError).toHaveBeenCalledTimes(1);
111
- expect(utils_1.handleError).toHaveBeenCalledWith(new Error('Invalid definition'), 'invalid.json');
110
+ expect(miscellaneous_1.handleError).toHaveBeenCalledTimes(1);
111
+ expect(miscellaneous_1.handleError).toHaveBeenCalledWith(new Error('Invalid definition'), 'invalid.json');
112
112
  }));
113
113
  it("handleError isn't called when bundles a valid definition", () => __awaiter(void 0, void 0, void 0, function* () {
114
114
  const apis = ['foo.yaml'];
@@ -123,6 +123,6 @@ describe('bundle', () => {
123
123
  format: 'codeframe',
124
124
  lint: false,
125
125
  });
126
- expect(utils_1.handleError).toHaveBeenCalledTimes(0);
126
+ expect(miscellaneous_1.handleError).toHaveBeenCalledTimes(0);
127
127
  }));
128
128
  });
@@ -10,19 +10,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const join_1 = require("../../commands/join");
13
- const utils_1 = require("../../utils");
13
+ const miscellaneous_1 = require("../../utils/miscellaneous");
14
14
  const colorette_1 = require("colorette");
15
15
  const openapi_core_1 = require("@redocly/openapi-core");
16
16
  const openapi_core_2 = require("../../__mocks__/@redocly/openapi-core");
17
17
  const config_1 = require("../fixtures/config");
18
- jest.mock('../../utils');
18
+ jest.mock('../../utils/miscellaneous');
19
19
  jest.mock('colorette');
20
20
  describe('handleJoin fails', () => {
21
21
  const colloreteYellowMock = colorette_1.yellow;
22
22
  colloreteYellowMock.mockImplementation((string) => string);
23
23
  it('should call exitWithError because only one entrypoint', () => __awaiter(void 0, void 0, void 0, function* () {
24
24
  yield (0, join_1.handleJoin)({ apis: ['first.yaml'] }, {}, 'cli-version');
25
- expect(utils_1.exitWithError).toHaveBeenCalledWith(`At least 2 apis should be provided. \n\n`);
25
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`At least 2 apis should be provided. \n\n`);
26
26
  }));
27
27
  it('should call exitWithError because passed all 3 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
28
28
  yield (0, join_1.handleJoin)({
@@ -31,7 +31,7 @@ describe('handleJoin fails', () => {
31
31
  'without-x-tag-groups': true,
32
32
  'prefix-tags-with-filename': true,
33
33
  }, {}, 'cli-version');
34
- expect(utils_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, prefix-tags-with-info-prop, without-x-tag-groups together.\nPlease choose only one! \n\n`);
34
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, prefix-tags-with-info-prop, without-x-tag-groups together.\nPlease choose only one! \n\n`);
35
35
  }));
36
36
  it('should call exitWithError because passed all 2 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
37
37
  yield (0, join_1.handleJoin)({
@@ -39,13 +39,13 @@ describe('handleJoin fails', () => {
39
39
  'without-x-tag-groups': true,
40
40
  'prefix-tags-with-filename': true,
41
41
  }, {}, 'cli-version');
42
- expect(utils_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, without-x-tag-groups together.\nPlease choose only one! \n\n`);
42
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, without-x-tag-groups together.\nPlease choose only one! \n\n`);
43
43
  }));
44
44
  it('should call exitWithError because Only OpenAPI 3.0 and OpenAPI 3.1 are supported', () => __awaiter(void 0, void 0, void 0, function* () {
45
45
  yield (0, join_1.handleJoin)({
46
46
  apis: ['first.yaml', 'second.yaml'],
47
47
  }, config_1.ConfigFixture, 'cli-version');
48
- expect(utils_1.exitWithError).toHaveBeenCalledWith('Only OpenAPI 3.0 and OpenAPI 3.1 are supported: undefined \n\n');
48
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('Only OpenAPI 3.0 and OpenAPI 3.1 are supported: undefined \n\n');
49
49
  }));
50
50
  it('should call exitWithError if mixing OpenAPI 3.0 and 3.1', () => __awaiter(void 0, void 0, void 0, function* () {
51
51
  openapi_core_1.detectSpec
@@ -54,21 +54,21 @@ describe('handleJoin fails', () => {
54
54
  yield (0, join_1.handleJoin)({
55
55
  apis: ['first.yaml', 'second.yaml'],
56
56
  }, config_1.ConfigFixture, 'cli-version');
57
- expect(utils_1.exitWithError).toHaveBeenCalledWith('All APIs must use the same OpenAPI version: undefined \n\n');
57
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('All APIs must use the same OpenAPI version: undefined \n\n');
58
58
  }));
59
59
  it('should call writeToFileByExtension function', () => __awaiter(void 0, void 0, void 0, function* () {
60
60
  openapi_core_1.detectSpec.mockReturnValue('oas3_0');
61
61
  yield (0, join_1.handleJoin)({
62
62
  apis: ['first.yaml', 'second.yaml'],
63
63
  }, config_1.ConfigFixture, 'cli-version');
64
- expect(utils_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
64
+ expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
65
65
  }));
66
66
  it('should call writeToFileByExtension function for OpenAPI 3.1', () => __awaiter(void 0, void 0, void 0, function* () {
67
67
  openapi_core_1.detectSpec.mockReturnValue('oas3_1');
68
68
  yield (0, join_1.handleJoin)({
69
69
  apis: ['first.yaml', 'second.yaml'],
70
70
  }, config_1.ConfigFixture, 'cli-version');
71
- expect(utils_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
71
+ expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
72
72
  }));
73
73
  it('should call writeToFileByExtension function with custom output file', () => __awaiter(void 0, void 0, void 0, function* () {
74
74
  openapi_core_1.detectSpec.mockReturnValue('oas3_0');
@@ -76,14 +76,14 @@ describe('handleJoin fails', () => {
76
76
  apis: ['first.yaml', 'second.yaml'],
77
77
  output: 'output.yml',
78
78
  }, config_1.ConfigFixture, 'cli-version');
79
- expect(utils_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'output.yml', expect.any(Boolean));
79
+ expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'output.yml', expect.any(Boolean));
80
80
  }));
81
81
  it('should call writeToFileByExtension function with json file extension', () => __awaiter(void 0, void 0, void 0, function* () {
82
82
  openapi_core_1.detectSpec.mockReturnValue('oas3_0');
83
83
  yield (0, join_1.handleJoin)({
84
84
  apis: ['first.json', 'second.yaml'],
85
85
  }, config_1.ConfigFixture, 'cli-version');
86
- expect(utils_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.json', expect.any(Boolean));
86
+ expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.json', expect.any(Boolean));
87
87
  }));
88
88
  it('should call skipDecorators and skipPreprocessors', () => __awaiter(void 0, void 0, void 0, function* () {
89
89
  openapi_core_1.detectSpec.mockReturnValue('oas3_0');
@@ -11,15 +11,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const lint_1 = require("../../commands/lint");
13
13
  const openapi_core_1 = require("@redocly/openapi-core");
14
- const utils_1 = require("../../utils");
14
+ const miscellaneous_1 = require("../../utils/miscellaneous");
15
15
  const config_1 = require("../fixtures/config");
16
16
  const perf_hooks_1 = require("perf_hooks");
17
17
  const wrapper_1 = require("../../wrapper");
18
18
  const colorette_1 = require("colorette");
19
19
  jest.mock('@redocly/openapi-core');
20
- jest.mock('../../utils');
20
+ jest.mock('../../utils/miscellaneous');
21
21
  jest.mock('perf_hooks');
22
- jest.mock('../../update-version-notifier', () => ({
22
+ jest.mock('../../utils/update-version-notifier', () => ({
23
23
  version: '1.0.0',
24
24
  }));
25
25
  const argvMock = {
@@ -48,20 +48,20 @@ describe('handleLint', () => {
48
48
  describe('loadConfig and getEnrtypoints stage', () => {
49
49
  it('should fail if config file does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
50
50
  yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'config.yaml' }));
51
- expect(utils_1.exitWithError).toHaveBeenCalledWith('Please, provide valid path to the configuration file');
51
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('Please, provide valid path to the configuration file');
52
52
  }));
53
53
  it('should call loadConfigAndHandleErrors and getFallbackApisOrExit', () => __awaiter(void 0, void 0, void 0, function* () {
54
54
  yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
55
- expect(utils_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
55
+ expect(miscellaneous_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
56
56
  configPath: undefined,
57
57
  customExtends: undefined,
58
58
  processRawConfig: undefined,
59
59
  });
60
- expect(utils_1.getFallbackApisOrExit).toHaveBeenCalled();
60
+ expect(miscellaneous_1.getFallbackApisOrExit).toHaveBeenCalled();
61
61
  }));
62
62
  it('should call loadConfig with args if such exist', () => __awaiter(void 0, void 0, void 0, function* () {
63
63
  yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'redocly.yaml', extends: ['some/path'] }));
64
- expect(utils_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
64
+ expect(miscellaneous_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
65
65
  configPath: 'redocly.yaml',
66
66
  customExtends: ['some/path'],
67
67
  processRawConfig: undefined,
@@ -73,12 +73,12 @@ describe('handleLint', () => {
73
73
  }));
74
74
  it('should check if ruleset exist', () => __awaiter(void 0, void 0, void 0, function* () {
75
75
  yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
76
- expect(utils_1.checkIfRulesetExist).toHaveBeenCalledTimes(1);
76
+ expect(miscellaneous_1.checkIfRulesetExist).toHaveBeenCalledTimes(1);
77
77
  }));
78
78
  it('should fail if apis not provided', () => __awaiter(void 0, void 0, void 0, function* () {
79
79
  yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { apis: [] }));
80
- expect(utils_1.getFallbackApisOrExit).toHaveBeenCalledTimes(1);
81
- expect(utils_1.exitWithError).toHaveBeenCalledWith('No APIs were provided');
80
+ expect(miscellaneous_1.getFallbackApisOrExit).toHaveBeenCalledTimes(1);
81
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('No APIs were provided');
82
82
  }));
83
83
  });
84
84
  describe('loop through entrypoints and lint stage', () => {
@@ -104,21 +104,21 @@ describe('handleLint', () => {
104
104
  totals: { errors: 0 },
105
105
  version: '1.0.0',
106
106
  });
107
- expect(utils_1.getExecutionTime).toHaveBeenCalledWith(42);
107
+ expect(miscellaneous_1.getExecutionTime).toHaveBeenCalledWith(42);
108
108
  }));
109
109
  it('should catch error in handleError if something fails', () => __awaiter(void 0, void 0, void 0, function* () {
110
110
  openapi_core_1.lint.mockRejectedValueOnce('error');
111
111
  yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
112
- expect(utils_1.handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
112
+ expect(miscellaneous_1.handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
113
113
  }));
114
114
  });
115
115
  describe('erros and warning handle after lint stage', () => {
116
116
  it('should call printLintTotals and printLintTotals', () => __awaiter(void 0, void 0, void 0, function* () {
117
117
  yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
118
- expect(utils_1.printUnusedWarnings).toHaveBeenCalled();
118
+ expect(miscellaneous_1.printUnusedWarnings).toHaveBeenCalled();
119
119
  }));
120
120
  it('should call exit with 0 if no errors', () => __awaiter(void 0, void 0, void 0, function* () {
121
- utils_1.loadConfigAndHandleErrors.mockImplementation(() => {
121
+ miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
122
122
  return Object.assign({}, config_1.ConfigFixture);
123
123
  });
124
124
  yield (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
@@ -22,7 +22,7 @@ jest.mock('node-fetch', () => ({
22
22
  }));
23
23
  jest.mock('@redocly/openapi-core');
24
24
  jest.mock('../../commands/login');
25
- jest.mock('../../utils');
25
+ jest.mock('../../utils/miscellaneous');
26
26
  openapi_core_1.getMergedConfig.mockImplementation((config) => config);
27
27
  const mockPromptClientToken = login_1.promptClientToken;
28
28
  describe('push-with-region', () => {
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const fs = require("fs");
13
13
  const openapi_core_1 = require("@redocly/openapi-core");
14
- const utils_1 = require("../../utils");
14
+ const miscellaneous_1 = require("../../utils/miscellaneous");
15
15
  const push_1 = require("../../commands/push");
16
16
  const config_1 = require("../fixtures/config");
17
17
  const colorette_1 = require("colorette");
@@ -23,7 +23,7 @@ jest.mock('node-fetch', () => ({
23
23
  })),
24
24
  }));
25
25
  jest.mock('@redocly/openapi-core');
26
- jest.mock('../../utils');
26
+ jest.mock('../../utils/miscellaneous');
27
27
  openapi_core_1.getMergedConfig.mockImplementation((config) => config);
28
28
  describe('push', () => {
29
29
  const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
@@ -65,7 +65,7 @@ describe('push', () => {
65
65
  'job-id': ' ',
66
66
  'batch-size': 2,
67
67
  }, config_1.ConfigFixture);
68
- expect(utils_1.exitWithError).toBeCalledTimes(1);
68
+ expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
69
69
  }));
70
70
  it('fails if batchSize value is less than 2', () => __awaiter(void 0, void 0, void 0, function* () {
71
71
  yield (0, push_1.handlePush)({
@@ -77,7 +77,7 @@ describe('push', () => {
77
77
  'job-id': '123',
78
78
  'batch-size': 1,
79
79
  }, config_1.ConfigFixture);
80
- expect(utils_1.exitWithError).toBeCalledTimes(1);
80
+ expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
81
81
  }));
82
82
  it('push with --files', () => __awaiter(void 0, void 0, void 0, function* () {
83
83
  const mockConfig = Object.assign(Object.assign({}, config_1.ConfigFixture), { files: ['./resouces/1.md', './resouces/2.md'] });
@@ -112,8 +112,8 @@ describe('push', () => {
112
112
  'job-id': '123',
113
113
  'batch-size': 2,
114
114
  }, config_1.ConfigFixture);
115
- expect(utils_1.exitWithError).toBeCalledTimes(1);
116
- expect(utils_1.exitWithError).toBeCalledWith(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
115
+ expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
116
+ expect(miscellaneous_1.exitWithError).toBeCalledWith(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
117
117
  }));
118
118
  it('push should work with organization in config', () => __awaiter(void 0, void 0, void 0, function* () {
119
119
  const mockConfig = Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org' });
@@ -160,8 +160,8 @@ describe('push', () => {
160
160
  'job-id': '123',
161
161
  'batch-size': 2,
162
162
  }, mockConfig);
163
- expect(utils_1.exitWithError).toBeCalledTimes(1);
164
- expect(utils_1.exitWithError).toHaveBeenLastCalledWith('Api not found. Please make sure you have provided the correct data in the config file.');
163
+ expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
164
+ expect(miscellaneous_1.exitWithError).toHaveBeenLastCalledWith('Api not found. Please make sure you have provided the correct data in the config file.');
165
165
  }));
166
166
  it('push should fail if destination not provided', () => __awaiter(void 0, void 0, void 0, function* () {
167
167
  const mockConfig = { organization: 'test_org', apis: {} };
@@ -173,8 +173,8 @@ describe('push', () => {
173
173
  'job-id': '123',
174
174
  'batch-size': 2,
175
175
  }, mockConfig);
176
- expect(utils_1.exitWithError).toBeCalledTimes(1);
177
- expect(utils_1.exitWithError).toHaveBeenLastCalledWith('No destination provided, please use --destination option to provide destination.');
176
+ expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
177
+ expect(miscellaneous_1.exitWithError).toHaveBeenLastCalledWith('No destination provided, please use --destination option to provide destination.');
178
178
  }));
179
179
  it('push should fail if destination format is not valid', () => __awaiter(void 0, void 0, void 0, function* () {
180
180
  const mockConfig = { organization: 'test_org', apis: {} };
@@ -186,7 +186,7 @@ describe('push', () => {
186
186
  'job-id': '123',
187
187
  'batch-size': 2,
188
188
  }, mockConfig);
189
- expect(utils_1.exitWithError).toHaveBeenCalledWith(`Destination argument value is not valid, please use the right format: ${(0, colorette_1.yellow)('<api-name@api-version>')}`);
189
+ expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`Destination argument value is not valid, please use the right format: ${(0, colorette_1.yellow)('<api-name@api-version>')}`);
190
190
  }));
191
191
  it('push should work and encode name with spaces', () => __awaiter(void 0, void 0, void 0, function* () {
192
192
  const encodeURIComponentSpy = jest.spyOn(global, 'encodeURIComponent');
@@ -9,30 +9,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const fetch_with_timeout_1 = require("../fetch-with-timeout");
12
+ const abort_controller_1 = require("abort-controller");
13
+ const fetch_with_timeout_1 = require("../utils/fetch-with-timeout");
13
14
  const node_fetch_1 = require("node-fetch");
14
15
  jest.mock('node-fetch');
15
16
  describe('fetchWithTimeout', () => {
16
17
  afterEach(() => {
17
18
  jest.clearAllMocks();
18
19
  });
19
- it('should use bare node-fetch if AbortController is not available', () => __awaiter(void 0, void 0, void 0, function* () {
20
- // @ts-ignore
21
- global.AbortController = undefined;
22
- // @ts-ignore
23
- global.setTimeout = jest.fn();
24
- yield (0, fetch_with_timeout_1.default)('url', { method: 'GET' });
25
- expect(node_fetch_1.default).toHaveBeenCalledWith('url', { method: 'GET' });
26
- expect(global.setTimeout).toHaveBeenCalledTimes(0);
27
- }));
28
- it('should call node-fetch with signal if AbortController is available', () => __awaiter(void 0, void 0, void 0, function* () {
29
- global.AbortController = jest.fn().mockImplementation(() => ({ signal: 'something' }));
20
+ it('should call node-fetch with signal', () => __awaiter(void 0, void 0, void 0, function* () {
30
21
  // @ts-ignore
31
22
  global.setTimeout = jest.fn();
32
23
  global.clearTimeout = jest.fn();
33
24
  yield (0, fetch_with_timeout_1.default)('url');
34
25
  expect(global.setTimeout).toHaveBeenCalledTimes(1);
35
- expect(node_fetch_1.default).toHaveBeenCalledWith('url', { signal: 'something' });
26
+ expect(node_fetch_1.default).toHaveBeenCalledWith('url', { signal: new abort_controller_1.default().signal });
36
27
  expect(global.clearTimeout).toHaveBeenCalledTimes(1);
37
28
  }));
38
29
  });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const spinner_1 = require("../utils/spinner");
4
+ const process = require("process");
5
+ jest.useFakeTimers();
6
+ describe('Spinner', () => {
7
+ const IS_TTY = process.stdout.isTTY;
8
+ let writeMock;
9
+ let spinner;
10
+ beforeEach(() => {
11
+ process.stdout.isTTY = true;
12
+ writeMock = jest.spyOn(process.stdout, 'write').mockImplementation(jest.fn());
13
+ spinner = new spinner_1.Spinner();
14
+ });
15
+ afterEach(() => {
16
+ writeMock.mockRestore();
17
+ jest.clearAllTimers();
18
+ });
19
+ afterAll(() => {
20
+ process.stdout.isTTY = IS_TTY;
21
+ });
22
+ it('starts the spinner', () => {
23
+ spinner.start('Loading');
24
+ jest.advanceTimersByTime(100);
25
+ expect(writeMock).toHaveBeenCalledWith('\r⠋ Loading');
26
+ });
27
+ it('stops the spinner', () => {
28
+ spinner.start('Loading');
29
+ spinner.stop();
30
+ expect(writeMock).toHaveBeenCalledWith('\r');
31
+ });
32
+ it('should write 3 frames', () => {
33
+ spinner.start('Loading');
34
+ jest.advanceTimersByTime(300);
35
+ expect(writeMock).toHaveBeenCalledTimes(3);
36
+ });
37
+ it('should call write 1 times if CI set to true', () => {
38
+ process.stdout.isTTY = false;
39
+ spinner.start('Loading');
40
+ jest.advanceTimersByTime(300);
41
+ expect(writeMock).toHaveBeenCalledTimes(1);
42
+ });
43
+ });