@redocly/cli 1.0.0-beta.99 → 1.0.0-rc.2

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 (103) hide show
  1. package/README.md +83 -22
  2. package/bin/cli.js +1 -1
  3. package/lib/__mocks__/@redocly/openapi-core.d.ts +53 -1
  4. package/lib/__mocks__/@redocly/openapi-core.js +56 -5
  5. package/lib/__mocks__/documents.d.ts +92 -0
  6. package/lib/__mocks__/documents.js +63 -0
  7. package/lib/__mocks__/fs.d.ts +2 -0
  8. package/lib/__mocks__/fs.js +3 -1
  9. package/lib/__mocks__/perf_hooks.d.ts +4 -0
  10. package/lib/__mocks__/perf_hooks.js +6 -0
  11. package/lib/__mocks__/redoc.d.ts +7 -0
  12. package/lib/__mocks__/redoc.js +5 -0
  13. package/lib/__mocks__/utils.d.ts +26 -4
  14. package/lib/__mocks__/utils.js +8 -3
  15. package/lib/__tests__/commands/build-docs.test.d.ts +1 -0
  16. package/lib/__tests__/commands/build-docs.test.js +59 -0
  17. package/lib/__tests__/commands/bundle.test.js +66 -30
  18. package/lib/__tests__/commands/join.test.d.ts +1 -0
  19. package/lib/__tests__/commands/join.test.js +85 -0
  20. package/lib/__tests__/commands/lint.test.d.ts +1 -0
  21. package/lib/__tests__/commands/lint.test.js +149 -0
  22. package/lib/__tests__/commands/push-region.test.js +5 -4
  23. package/lib/__tests__/commands/push.test.js +254 -39
  24. package/lib/__tests__/fetch-with-timeout.test.d.ts +1 -0
  25. package/lib/__tests__/fetch-with-timeout.test.js +38 -0
  26. package/lib/__tests__/fixtures/config.d.ts +22 -0
  27. package/lib/__tests__/fixtures/config.js +24 -0
  28. package/lib/__tests__/utils.test.js +429 -1
  29. package/lib/__tests__/wrapper.test.d.ts +1 -0
  30. package/lib/__tests__/wrapper.test.js +57 -0
  31. package/lib/commands/build-docs/index.d.ts +3 -0
  32. package/lib/commands/build-docs/index.js +50 -0
  33. package/{src/commands/preview-docs/preview-server/default.hbs → lib/commands/build-docs/template.hbs} +2 -3
  34. package/lib/commands/build-docs/types.d.ts +23 -0
  35. package/lib/commands/build-docs/types.js +2 -0
  36. package/lib/commands/build-docs/utils.d.ts +7 -0
  37. package/lib/commands/build-docs/utils.js +99 -0
  38. package/lib/commands/bundle.d.ts +10 -12
  39. package/lib/commands/bundle.js +25 -24
  40. package/lib/commands/join.d.ts +12 -3
  41. package/lib/commands/join.js +295 -109
  42. package/lib/commands/lint.d.ts +11 -8
  43. package/lib/commands/lint.js +49 -19
  44. package/lib/commands/login.d.ts +5 -3
  45. package/lib/commands/login.js +2 -2
  46. package/lib/commands/preview-docs/index.d.ts +6 -6
  47. package/lib/commands/preview-docs/index.js +30 -20
  48. package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +1 -1
  49. package/lib/commands/preview-docs/preview-server/preview-server.js +5 -4
  50. package/lib/commands/preview-docs/preview-server/server.d.ts +1 -1
  51. package/lib/commands/push.d.ts +21 -10
  52. package/lib/commands/push.js +110 -63
  53. package/lib/commands/split/__tests__/index.test.js +10 -8
  54. package/lib/commands/split/index.d.ts +5 -3
  55. package/lib/commands/split/index.js +15 -24
  56. package/lib/commands/split/types.d.ts +11 -11
  57. package/lib/commands/split/types.js +19 -19
  58. package/lib/commands/stats.d.ts +7 -4
  59. package/lib/commands/stats.js +13 -12
  60. package/lib/fetch-with-timeout.d.ts +2 -0
  61. package/lib/fetch-with-timeout.js +30 -0
  62. package/lib/index.js +194 -40
  63. package/lib/js-utils.d.ts +1 -0
  64. package/lib/js-utils.js +9 -3
  65. package/lib/types.d.ts +17 -1
  66. package/lib/update-version-notifier.d.ts +3 -0
  67. package/lib/update-version-notifier.js +105 -0
  68. package/lib/utils.d.ts +38 -5
  69. package/lib/utils.js +270 -41
  70. package/lib/wrapper.d.ts +4 -0
  71. package/lib/wrapper.js +52 -0
  72. package/package.json +18 -8
  73. package/src/__mocks__/@redocly/openapi-core.ts +0 -26
  74. package/src/__mocks__/fs.ts +0 -4
  75. package/src/__mocks__/utils.ts +0 -11
  76. package/src/__tests__/commands/bundle.test.ts +0 -120
  77. package/src/__tests__/commands/push-region.test.ts +0 -51
  78. package/src/__tests__/commands/push.test.ts +0 -158
  79. package/src/__tests__/utils.test.ts +0 -50
  80. package/src/assert-node-version.ts +0 -8
  81. package/src/commands/bundle.ts +0 -180
  82. package/src/commands/join.ts +0 -488
  83. package/src/commands/lint.ts +0 -110
  84. package/src/commands/login.ts +0 -21
  85. package/src/commands/preview-docs/index.ts +0 -188
  86. package/src/commands/preview-docs/preview-server/hot.js +0 -42
  87. package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
  88. package/src/commands/preview-docs/preview-server/preview-server.ts +0 -155
  89. package/src/commands/preview-docs/preview-server/server.ts +0 -91
  90. package/src/commands/push.ts +0 -357
  91. package/src/commands/split/__tests__/fixtures/samples.json +0 -61
  92. package/src/commands/split/__tests__/fixtures/spec.json +0 -70
  93. package/src/commands/split/__tests__/fixtures/webhooks.json +0 -88
  94. package/src/commands/split/__tests__/index.test.ts +0 -117
  95. package/src/commands/split/index.ts +0 -349
  96. package/src/commands/split/types.ts +0 -73
  97. package/src/commands/stats.ts +0 -115
  98. package/src/index.ts +0 -316
  99. package/src/js-utils.ts +0 -12
  100. package/src/types.ts +0 -13
  101. package/src/utils.ts +0 -307
  102. package/tsconfig.json +0 -9
  103. package/tsconfig.tsbuildinfo +0 -1
@@ -11,9 +11,11 @@ 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");
15
+ const wrapper_1 = require("../../wrapper");
14
16
  jest.mock('@redocly/openapi-core');
15
17
  jest.mock('../../utils');
16
- openapi_core_1.getMergedConfig.mockImplementation(config => config);
18
+ openapi_core_1.getMergedConfig.mockImplementation((config) => config);
17
19
  describe('bundle', () => {
18
20
  let processExitMock;
19
21
  let exitCb;
@@ -28,65 +30,99 @@ describe('bundle', () => {
28
30
  afterEach(() => {
29
31
  openapi_core_1.lint.mockClear();
30
32
  openapi_core_1.bundle.mockClear();
31
- openapi_core_1.getTotals.mockClear();
33
+ openapi_core_1.getTotals.mockReset();
32
34
  });
33
35
  it('bundles definitions w/o linting', () => __awaiter(void 0, void 0, void 0, function* () {
34
- const entrypoints = ['foo.yaml', 'bar.yaml'];
35
- yield bundle_1.handleBundle({
36
- entrypoints,
36
+ const apis = ['foo.yaml', 'bar.yaml'];
37
+ yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
38
+ apis,
37
39
  ext: 'yaml',
38
40
  format: 'codeframe',
39
- }, '1.0.0');
41
+ });
40
42
  expect(openapi_core_1.lint).toBeCalledTimes(0);
41
- expect(openapi_core_1.bundle).toBeCalledTimes(entrypoints.length);
43
+ expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
42
44
  }));
43
45
  it('exits with code 0 when bundles definitions', () => __awaiter(void 0, void 0, void 0, function* () {
44
- const entrypoints = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
45
- yield bundle_1.handleBundle({
46
- entrypoints,
46
+ const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
47
+ yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
48
+ apis,
47
49
  ext: 'yaml',
48
50
  format: 'codeframe',
49
- }, '1.0.0');
50
- exitCb === null || exitCb === void 0 ? void 0 : exitCb();
51
+ });
52
+ yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
51
53
  expect(processExitMock).toHaveBeenCalledWith(0);
52
54
  }));
53
55
  it('bundles definitions w/ linting', () => __awaiter(void 0, void 0, void 0, function* () {
54
- const entrypoints = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
55
- yield bundle_1.handleBundle({
56
- entrypoints,
56
+ const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
57
+ openapi_core_1.getTotals.mockReturnValue({
58
+ errors: 0,
59
+ warnings: 0,
60
+ ignored: 0,
61
+ });
62
+ yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
63
+ apis,
57
64
  ext: 'yaml',
58
65
  format: 'codeframe',
59
66
  lint: true,
60
- }, '1.0.0');
61
- expect(openapi_core_1.lint).toBeCalledTimes(entrypoints.length);
62
- expect(openapi_core_1.bundle).toBeCalledTimes(entrypoints.length);
67
+ });
68
+ expect(openapi_core_1.lint).toBeCalledTimes(apis.length);
69
+ expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
63
70
  }));
64
71
  it('exits with code 0 when bundles definitions w/linting w/o errors', () => __awaiter(void 0, void 0, void 0, function* () {
65
- const entrypoints = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
66
- yield bundle_1.handleBundle({
67
- entrypoints,
72
+ const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
73
+ yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
74
+ apis,
68
75
  ext: 'yaml',
69
76
  format: 'codeframe',
70
77
  lint: true,
71
- }, '1.0.0');
72
- exitCb === null || exitCb === void 0 ? void 0 : exitCb();
78
+ });
79
+ yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
73
80
  expect(processExitMock).toHaveBeenCalledWith(0);
74
81
  }));
75
82
  it('exits with code 1 when bundles definitions w/linting w/errors', () => __awaiter(void 0, void 0, void 0, function* () {
76
- const entrypoints = ['foo.yaml'];
83
+ const apis = ['foo.yaml'];
77
84
  openapi_core_1.getTotals.mockReturnValue({
78
85
  errors: 1,
79
86
  warnings: 0,
80
- ignored: 0
87
+ ignored: 0,
81
88
  });
82
- yield bundle_1.handleBundle({
83
- entrypoints,
89
+ yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
90
+ apis,
84
91
  ext: 'yaml',
85
92
  format: 'codeframe',
86
93
  lint: true,
87
- }, '1.0.0');
88
- expect(openapi_core_1.lint).toBeCalledTimes(entrypoints.length);
89
- exitCb === null || exitCb === void 0 ? void 0 : exitCb();
94
+ });
95
+ expect(openapi_core_1.lint).toBeCalledTimes(apis.length);
96
+ yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
90
97
  expect(processExitMock).toHaveBeenCalledWith(1);
91
98
  }));
99
+ it('handleError is called when bundles an invalid definition', () => __awaiter(void 0, void 0, void 0, function* () {
100
+ const apis = ['invalid.json'];
101
+ openapi_core_1.bundle.mockImplementationOnce(() => {
102
+ throw new Error('Invalid definition');
103
+ });
104
+ yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
105
+ apis,
106
+ ext: 'json',
107
+ format: 'codeframe',
108
+ lint: false,
109
+ });
110
+ expect(utils_1.handleError).toHaveBeenCalledTimes(1);
111
+ expect(utils_1.handleError).toHaveBeenCalledWith(new Error('Invalid definition'), 'invalid.json');
112
+ }));
113
+ it("handleError isn't called when bundles a valid definition", () => __awaiter(void 0, void 0, void 0, function* () {
114
+ const apis = ['foo.yaml'];
115
+ openapi_core_1.getTotals.mockReturnValue({
116
+ errors: 0,
117
+ warnings: 0,
118
+ ignored: 0,
119
+ });
120
+ yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
121
+ apis,
122
+ ext: 'yaml',
123
+ format: 'codeframe',
124
+ lint: false,
125
+ });
126
+ expect(utils_1.handleError).toHaveBeenCalledTimes(0);
127
+ }));
92
128
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const join_1 = require("../../commands/join");
13
+ const utils_1 = require("../../utils");
14
+ const colorette_1 = require("colorette");
15
+ const openapi_core_1 = require("@redocly/openapi-core");
16
+ const openapi_core_2 = require("../../__mocks__/@redocly/openapi-core");
17
+ const config_1 = require("../fixtures/config");
18
+ jest.mock('../../utils');
19
+ jest.mock('colorette');
20
+ describe('handleJoin fails', () => {
21
+ const colloreteYellowMock = colorette_1.yellow;
22
+ colloreteYellowMock.mockImplementation((string) => string);
23
+ it('should call exitWithError because only one entrypoint', () => __awaiter(void 0, void 0, void 0, function* () {
24
+ yield join_1.handleJoin({ apis: ['first.yaml'] }, {}, 'cli-version');
25
+ expect(utils_1.exitWithError).toHaveBeenCalledWith(`At least 2 apis should be provided. \n\n`);
26
+ }));
27
+ it('should call exitWithError because passed all 3 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
28
+ yield join_1.handleJoin({
29
+ apis: ['first.yaml', 'second.yaml'],
30
+ 'prefix-tags-with-info-prop': 'something',
31
+ 'without-x-tag-groups': true,
32
+ 'prefix-tags-with-filename': true,
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`);
35
+ }));
36
+ it('should call exitWithError because passed all 2 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
37
+ yield join_1.handleJoin({
38
+ apis: ['first.yaml', 'second.yaml'],
39
+ 'without-x-tag-groups': true,
40
+ 'prefix-tags-with-filename': true,
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`);
43
+ }));
44
+ it('should call exitWithError because Only OpenAPI 3 is supported', () => __awaiter(void 0, void 0, void 0, function* () {
45
+ yield join_1.handleJoin({
46
+ apis: ['first.yaml', 'second.yaml'],
47
+ }, config_1.ConfigFixture, 'cli-version');
48
+ expect(utils_1.exitWithError).toHaveBeenCalledWith('Only OpenAPI 3 is supported: undefined \n\n');
49
+ }));
50
+ it('should call writeYaml function', () => __awaiter(void 0, void 0, void 0, function* () {
51
+ openapi_core_1.detectOpenAPI.mockReturnValue('oas3_0');
52
+ yield join_1.handleJoin({
53
+ apis: ['first.yaml', 'second.yaml'],
54
+ }, config_1.ConfigFixture, 'cli-version');
55
+ expect(utils_1.writeYaml).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
56
+ }));
57
+ it('should call writeYaml function with custom output file', () => __awaiter(void 0, void 0, void 0, function* () {
58
+ openapi_core_1.detectOpenAPI.mockReturnValue('oas3_0');
59
+ yield join_1.handleJoin({
60
+ apis: ['first.yaml', 'second.yaml'],
61
+ output: 'output.yml',
62
+ }, config_1.ConfigFixture, 'cli-version');
63
+ expect(utils_1.writeYaml).toHaveBeenCalledWith(expect.any(Object), 'output.yml', expect.any(Boolean));
64
+ }));
65
+ it('should call skipDecorators and skipPreprocessors', () => __awaiter(void 0, void 0, void 0, function* () {
66
+ openapi_core_1.detectOpenAPI.mockReturnValue('oas3_0');
67
+ yield join_1.handleJoin({
68
+ apis: ['first.yaml', 'second.yaml'],
69
+ }, config_1.ConfigFixture, 'cli-version');
70
+ const config = openapi_core_2.loadConfig();
71
+ expect(config.styleguide.skipDecorators).toHaveBeenCalled();
72
+ expect(config.styleguide.skipPreprocessors).toHaveBeenCalled();
73
+ }));
74
+ it('should not call skipDecorators and skipPreprocessors', () => __awaiter(void 0, void 0, void 0, function* () {
75
+ openapi_core_1.detectOpenAPI.mockReturnValue('oas3_0');
76
+ yield join_1.handleJoin({
77
+ apis: ['first.yaml', 'second.yaml'],
78
+ decorate: true,
79
+ preprocess: true,
80
+ }, config_1.ConfigFixture, 'cli-version');
81
+ const config = openapi_core_2.loadConfig();
82
+ expect(config.styleguide.skipDecorators).not.toHaveBeenCalled();
83
+ expect(config.styleguide.skipPreprocessors).not.toHaveBeenCalled();
84
+ }));
85
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const lint_1 = require("../../commands/lint");
13
+ const openapi_core_1 = require("@redocly/openapi-core");
14
+ const utils_1 = require("../../utils");
15
+ const config_1 = require("../fixtures/config");
16
+ const perf_hooks_1 = require("perf_hooks");
17
+ const wrapper_1 = require("../../wrapper");
18
+ const colorette_1 = require("colorette");
19
+ jest.mock('@redocly/openapi-core');
20
+ jest.mock('../../utils');
21
+ jest.mock('perf_hooks');
22
+ jest.mock('../../update-version-notifier', () => ({
23
+ version: '1.0.0',
24
+ }));
25
+ const argvMock = {
26
+ apis: ['openapi.yaml'],
27
+ 'lint-config': 'off',
28
+ format: 'codeframe',
29
+ };
30
+ describe('handleLint', () => {
31
+ let processExitMock;
32
+ let exitCb;
33
+ const getMergedConfigMock = openapi_core_1.getMergedConfig;
34
+ beforeEach(() => {
35
+ jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
36
+ perf_hooks_1.performance.now.mockImplementation(() => 42);
37
+ processExitMock = jest.spyOn(process, 'exit').mockImplementation();
38
+ jest.spyOn(process, 'once').mockImplementation((_e, cb) => {
39
+ exitCb = cb;
40
+ return process.on(_e, cb);
41
+ });
42
+ getMergedConfigMock.mockReturnValue(config_1.ConfigFixture);
43
+ openapi_core_1.doesYamlFileExist.mockImplementation((path) => path === 'redocly.yaml');
44
+ });
45
+ afterEach(() => {
46
+ getMergedConfigMock.mockReset();
47
+ });
48
+ describe('loadConfig and getEnrtypoints stage', () => {
49
+ it('should fail if config file does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ yield 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');
52
+ }));
53
+ it('should call loadConfigAndHandleErrors and getFallbackApisOrExit', () => __awaiter(void 0, void 0, void 0, function* () {
54
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
55
+ expect(utils_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
56
+ configPath: undefined,
57
+ customExtends: undefined,
58
+ processRawConfig: undefined,
59
+ });
60
+ expect(utils_1.getFallbackApisOrExit).toHaveBeenCalled();
61
+ }));
62
+ it('should call loadConfig with args if such exist', () => __awaiter(void 0, void 0, void 0, function* () {
63
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'redocly.yaml', extends: ['some/path'] }));
64
+ expect(utils_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
65
+ configPath: 'redocly.yaml',
66
+ customExtends: ['some/path'],
67
+ processRawConfig: undefined,
68
+ });
69
+ }));
70
+ it('should call mergedConfig with clear ignore if `generate-ignore-file` argv', () => __awaiter(void 0, void 0, void 0, function* () {
71
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'generate-ignore-file': true }));
72
+ expect(getMergedConfigMock).toHaveBeenCalled();
73
+ }));
74
+ it('should check if ruleset exist', () => __awaiter(void 0, void 0, void 0, function* () {
75
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
76
+ expect(utils_1.checkIfRulesetExist).toHaveBeenCalledTimes(1);
77
+ }));
78
+ it('should fail if apis not provided', () => __awaiter(void 0, void 0, void 0, function* () {
79
+ yield 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');
82
+ }));
83
+ });
84
+ describe('loop through entrypoints and lint stage', () => {
85
+ it('should call getMergedConfig and lint ', () => __awaiter(void 0, void 0, void 0, function* () {
86
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
87
+ expect(perf_hooks_1.performance.now).toHaveBeenCalled();
88
+ expect(getMergedConfigMock).toHaveBeenCalled();
89
+ expect(openapi_core_1.lint).toHaveBeenCalled();
90
+ }));
91
+ it('should call skipRules,skipPreprocessors and addIgnore with argv', () => __awaiter(void 0, void 0, void 0, function* () {
92
+ openapi_core_1.lint.mockResolvedValueOnce(['problem']);
93
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'skip-preprocessor': ['preprocessor'], 'skip-rule': ['rule'], 'generate-ignore-file': true }));
94
+ expect(config_1.ConfigFixture.styleguide.skipRules).toHaveBeenCalledWith(['rule']);
95
+ expect(config_1.ConfigFixture.styleguide.skipPreprocessors).toHaveBeenCalledWith(['preprocessor']);
96
+ }));
97
+ it('should call formatProblems and getExecutionTime with argv', () => __awaiter(void 0, void 0, void 0, function* () {
98
+ openapi_core_1.lint.mockResolvedValueOnce(['problem']);
99
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'max-problems': 2, format: 'stylish' }));
100
+ expect(openapi_core_1.getTotals).toHaveBeenCalledWith(['problem']);
101
+ expect(openapi_core_1.formatProblems).toHaveBeenCalledWith(['problem'], {
102
+ format: 'stylish',
103
+ maxProblems: 2,
104
+ totals: { errors: 0 },
105
+ version: '1.0.0',
106
+ });
107
+ expect(utils_1.getExecutionTime).toHaveBeenCalledWith(42);
108
+ }));
109
+ it('should catch error in handleError if something fails', () => __awaiter(void 0, void 0, void 0, function* () {
110
+ openapi_core_1.lint.mockRejectedValueOnce('error');
111
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
112
+ expect(utils_1.handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
113
+ }));
114
+ });
115
+ describe('erros and warning handle after lint stage', () => {
116
+ it('should call printLintTotals and printLintTotals', () => __awaiter(void 0, void 0, void 0, function* () {
117
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
118
+ expect(utils_1.printUnusedWarnings).toHaveBeenCalled();
119
+ }));
120
+ it('should call exit with 0 if no errors', () => __awaiter(void 0, void 0, void 0, function* () {
121
+ utils_1.loadConfigAndHandleErrors.mockImplementation(() => {
122
+ return Object.assign({}, config_1.ConfigFixture);
123
+ });
124
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
125
+ yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
126
+ expect(processExitMock).toHaveBeenCalledWith(0);
127
+ }));
128
+ it('should exit with 1 if total errors > 0', () => __awaiter(void 0, void 0, void 0, function* () {
129
+ openapi_core_1.getTotals.mockReturnValueOnce({ errors: 1 });
130
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
131
+ yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
132
+ expect(processExitMock).toHaveBeenCalledWith(1);
133
+ }));
134
+ it('should use recommended fallback if no config', () => __awaiter(void 0, void 0, void 0, function* () {
135
+ openapi_core_1.getMergedConfig.mockImplementation(() => {
136
+ return {
137
+ styleguide: {
138
+ recommendedFallback: true,
139
+ rules: {},
140
+ skipRules: jest.fn(),
141
+ skipPreprocessors: jest.fn(),
142
+ },
143
+ };
144
+ });
145
+ yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
146
+ expect(process.stderr.write).toHaveBeenCalledWith(`No configurations were provided -- using built in ${colorette_1.blue('recommended')} configuration by default.\n\n`);
147
+ }));
148
+ });
149
+ });
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const openapi_core_1 = require("@redocly/openapi-core");
13
13
  const push_1 = require("../../commands/push");
14
14
  const login_1 = require("../../commands/login");
15
+ const config_1 = require("../fixtures/config");
15
16
  jest.mock('fs');
16
17
  jest.mock('node-fetch', () => ({
17
18
  default: jest.fn(() => ({
@@ -34,10 +35,10 @@ describe('push-with-region', () => {
34
35
  redoclyClient.domain = 'redoc.ly';
35
36
  yield push_1.handlePush({
36
37
  upsert: true,
37
- entrypoint: 'spec.json',
38
+ api: 'spec.json',
38
39
  destination: '@org/my-api@1.0.0',
39
40
  branchName: 'test',
40
- });
41
+ }, config_1.ConfigFixture);
41
42
  expect(mockPromptClientToken).toBeCalledTimes(1);
42
43
  expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
43
44
  }));
@@ -45,10 +46,10 @@ describe('push-with-region', () => {
45
46
  redoclyClient.domain = 'eu.redocly.com';
46
47
  yield push_1.handlePush({
47
48
  upsert: true,
48
- entrypoint: 'spec.json',
49
+ api: 'spec.json',
49
50
  destination: '@org/my-api@1.0.0',
50
51
  branchName: 'test',
51
- });
52
+ }, config_1.ConfigFixture);
52
53
  expect(mockPromptClientToken).toBeCalledTimes(1);
53
54
  expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
54
55
  }));