@redocly/cli 1.0.0-beta.128 → 1.0.0-beta.129
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.
- package/lib/__tests__/commands/build-docs.test.js +1 -1
- package/lib/__tests__/commands/bundle.test.js +18 -17
- package/lib/__tests__/commands/join.test.js +9 -8
- package/lib/__tests__/commands/lint.test.js +40 -20
- package/lib/__tests__/commands/push-region.test.js +3 -2
- package/lib/__tests__/commands/push.test.js +94 -55
- package/lib/__tests__/utils.test.js +100 -40
- package/lib/__tests__/wrapper.test.d.ts +1 -0
- package/lib/__tests__/wrapper.test.js +47 -0
- package/lib/commands/build-docs/index.d.ts +2 -1
- package/lib/commands/build-docs/index.js +1 -2
- package/lib/commands/bundle.d.ts +10 -4
- package/lib/commands/bundle.js +4 -8
- package/lib/commands/join.d.ts +6 -3
- package/lib/commands/join.js +1 -2
- package/lib/commands/lint.d.ts +13 -6
- package/lib/commands/lint.js +9 -17
- package/lib/commands/login.d.ts +5 -3
- package/lib/commands/login.js +2 -2
- package/lib/commands/preview-docs/index.d.ts +4 -2
- package/lib/commands/preview-docs/index.js +11 -4
- package/lib/commands/push.d.ts +11 -6
- package/lib/commands/push.js +40 -22
- package/lib/commands/split/index.d.ts +4 -2
- package/lib/commands/stats.d.ts +7 -4
- package/lib/commands/stats.js +1 -2
- package/lib/index.js +70 -22
- package/lib/types.d.ts +11 -8
- package/lib/update-version-notifier.d.ts +1 -0
- package/lib/update-version-notifier.js +6 -5
- package/lib/utils.d.ts +22 -2
- package/lib/utils.js +104 -11
- package/lib/wrapper.d.ts +4 -0
- package/lib/wrapper.js +52 -0
- package/package.json +3 -3
|
@@ -53,7 +53,7 @@ describe('build-docs', () => {
|
|
|
53
53
|
templateOptions: {},
|
|
54
54
|
theme: { openapi: {} },
|
|
55
55
|
api: '../some-path/openapi.yaml',
|
|
56
|
-
});
|
|
56
|
+
}, {});
|
|
57
57
|
expect(redoc_1.loadAndBundleSpec).toBeCalledTimes(1);
|
|
58
58
|
expect(utils_2.getFallbackApisOrExit).toBeCalledTimes(1);
|
|
59
59
|
expect(processExitMock).toBeCalledTimes(0);
|
|
@@ -12,6 +12,7 @@ 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
14
|
const utils_1 = require("../../utils");
|
|
15
|
+
const wrapper_1 = require("../../wrapper");
|
|
15
16
|
jest.mock('@redocly/openapi-core');
|
|
16
17
|
jest.mock('../../utils');
|
|
17
18
|
openapi_core_1.getMergedConfig.mockImplementation((config) => config);
|
|
@@ -33,22 +34,22 @@ describe('bundle', () => {
|
|
|
33
34
|
});
|
|
34
35
|
it('bundles definitions w/o linting', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
36
|
const apis = ['foo.yaml', 'bar.yaml'];
|
|
36
|
-
yield bundle_1.handleBundle({
|
|
37
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
37
38
|
apis,
|
|
38
39
|
ext: 'yaml',
|
|
39
40
|
format: 'codeframe',
|
|
40
|
-
}
|
|
41
|
+
});
|
|
41
42
|
expect(openapi_core_1.lint).toBeCalledTimes(0);
|
|
42
43
|
expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
|
|
43
44
|
}));
|
|
44
45
|
it('exits with code 0 when bundles definitions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
46
|
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
46
|
-
yield bundle_1.handleBundle({
|
|
47
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
47
48
|
apis,
|
|
48
49
|
ext: 'yaml',
|
|
49
50
|
format: 'codeframe',
|
|
50
|
-
}
|
|
51
|
-
exitCb === null || exitCb === void 0 ? void 0 : exitCb();
|
|
51
|
+
});
|
|
52
|
+
yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
|
|
52
53
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
53
54
|
}));
|
|
54
55
|
it('bundles definitions w/ linting', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -58,24 +59,24 @@ describe('bundle', () => {
|
|
|
58
59
|
warnings: 0,
|
|
59
60
|
ignored: 0,
|
|
60
61
|
});
|
|
61
|
-
yield bundle_1.handleBundle({
|
|
62
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
62
63
|
apis,
|
|
63
64
|
ext: 'yaml',
|
|
64
65
|
format: 'codeframe',
|
|
65
66
|
lint: true,
|
|
66
|
-
}
|
|
67
|
+
});
|
|
67
68
|
expect(openapi_core_1.lint).toBeCalledTimes(apis.length);
|
|
68
69
|
expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
|
|
69
70
|
}));
|
|
70
71
|
it('exits with code 0 when bundles definitions w/linting w/o errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
72
|
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
72
|
-
yield bundle_1.handleBundle({
|
|
73
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
73
74
|
apis,
|
|
74
75
|
ext: 'yaml',
|
|
75
76
|
format: 'codeframe',
|
|
76
77
|
lint: true,
|
|
77
|
-
}
|
|
78
|
-
exitCb === null || exitCb === void 0 ? void 0 : exitCb();
|
|
78
|
+
});
|
|
79
|
+
yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
|
|
79
80
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
80
81
|
}));
|
|
81
82
|
it('exits with code 1 when bundles definitions w/linting w/errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -85,14 +86,14 @@ describe('bundle', () => {
|
|
|
85
86
|
warnings: 0,
|
|
86
87
|
ignored: 0,
|
|
87
88
|
});
|
|
88
|
-
yield bundle_1.handleBundle({
|
|
89
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
89
90
|
apis,
|
|
90
91
|
ext: 'yaml',
|
|
91
92
|
format: 'codeframe',
|
|
92
93
|
lint: true,
|
|
93
|
-
}
|
|
94
|
+
});
|
|
94
95
|
expect(openapi_core_1.lint).toBeCalledTimes(apis.length);
|
|
95
|
-
exitCb === null || exitCb === void 0 ? void 0 : exitCb();
|
|
96
|
+
yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
|
|
96
97
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
97
98
|
}));
|
|
98
99
|
it('handleError is called when bundles an invalid definition', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -100,12 +101,12 @@ describe('bundle', () => {
|
|
|
100
101
|
openapi_core_1.bundle.mockImplementationOnce(() => {
|
|
101
102
|
throw new Error('Invalid definition');
|
|
102
103
|
});
|
|
103
|
-
yield bundle_1.handleBundle({
|
|
104
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
104
105
|
apis,
|
|
105
106
|
ext: 'json',
|
|
106
107
|
format: 'codeframe',
|
|
107
108
|
lint: false,
|
|
108
|
-
}
|
|
109
|
+
});
|
|
109
110
|
expect(utils_1.handleError).toHaveBeenCalledTimes(1);
|
|
110
111
|
expect(utils_1.handleError).toHaveBeenCalledWith(new Error('Invalid definition'), 'invalid.json');
|
|
111
112
|
}));
|
|
@@ -116,12 +117,12 @@ describe('bundle', () => {
|
|
|
116
117
|
warnings: 0,
|
|
117
118
|
ignored: 0,
|
|
118
119
|
});
|
|
119
|
-
yield bundle_1.handleBundle({
|
|
120
|
+
yield wrapper_1.commandWrapper(bundle_1.handleBundle)({
|
|
120
121
|
apis,
|
|
121
122
|
ext: 'yaml',
|
|
122
123
|
format: 'codeframe',
|
|
123
124
|
lint: false,
|
|
124
|
-
}
|
|
125
|
+
});
|
|
125
126
|
expect(utils_1.handleError).toHaveBeenCalledTimes(0);
|
|
126
127
|
}));
|
|
127
128
|
});
|
|
@@ -14,13 +14,14 @@ const utils_1 = require("../../utils");
|
|
|
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
|
+
const config_1 = require("../fixtures/config");
|
|
17
18
|
jest.mock('../../utils');
|
|
18
19
|
jest.mock('colorette');
|
|
19
20
|
describe('handleJoin fails', () => {
|
|
20
21
|
const colloreteYellowMock = colorette_1.yellow;
|
|
21
22
|
colloreteYellowMock.mockImplementation((string) => string);
|
|
22
23
|
it('should call exitWithError because only one entrypoint', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
yield join_1.handleJoin({ apis: ['first.yaml'] }, 'cli-version');
|
|
24
|
+
yield join_1.handleJoin({ apis: ['first.yaml'] }, {}, 'cli-version');
|
|
24
25
|
expect(utils_1.exitWithError).toHaveBeenCalledWith(`At least 2 apis should be provided. \n\n`);
|
|
25
26
|
}));
|
|
26
27
|
it('should call exitWithError because passed all 3 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -29,7 +30,7 @@ describe('handleJoin fails', () => {
|
|
|
29
30
|
'prefix-tags-with-info-prop': 'something',
|
|
30
31
|
'without-x-tag-groups': true,
|
|
31
32
|
'prefix-tags-with-filename': true,
|
|
32
|
-
}, 'cli-version');
|
|
33
|
+
}, {}, 'cli-version');
|
|
33
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
35
|
}));
|
|
35
36
|
it('should call exitWithError because passed all 2 options for tags', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -37,20 +38,20 @@ describe('handleJoin fails', () => {
|
|
|
37
38
|
apis: ['first.yaml', 'second.yaml'],
|
|
38
39
|
'without-x-tag-groups': true,
|
|
39
40
|
'prefix-tags-with-filename': true,
|
|
40
|
-
}, 'cli-version');
|
|
41
|
+
}, {}, 'cli-version');
|
|
41
42
|
expect(utils_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, without-x-tag-groups together.\nPlease choose only one! \n\n`);
|
|
42
43
|
}));
|
|
43
44
|
it('should call exitWithError because Only OpenAPI 3 is supported', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
45
|
yield join_1.handleJoin({
|
|
45
46
|
apis: ['first.yaml', 'second.yaml'],
|
|
46
|
-
}, 'cli-version');
|
|
47
|
+
}, config_1.ConfigFixture, 'cli-version');
|
|
47
48
|
expect(utils_1.exitWithError).toHaveBeenCalledWith('Only OpenAPI 3 is supported: undefined \n\n');
|
|
48
49
|
}));
|
|
49
50
|
it('should call writeYaml function', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
51
|
openapi_core_1.detectOpenAPI.mockReturnValue('oas3_0');
|
|
51
52
|
yield join_1.handleJoin({
|
|
52
53
|
apis: ['first.yaml', 'second.yaml'],
|
|
53
|
-
}, 'cli-version');
|
|
54
|
+
}, config_1.ConfigFixture, 'cli-version');
|
|
54
55
|
expect(utils_1.writeYaml).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
|
|
55
56
|
}));
|
|
56
57
|
it('should call writeYaml function with custom output file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -58,14 +59,14 @@ describe('handleJoin fails', () => {
|
|
|
58
59
|
yield join_1.handleJoin({
|
|
59
60
|
apis: ['first.yaml', 'second.yaml'],
|
|
60
61
|
output: 'output.yml',
|
|
61
|
-
}, 'cli-version');
|
|
62
|
+
}, config_1.ConfigFixture, 'cli-version');
|
|
62
63
|
expect(utils_1.writeYaml).toHaveBeenCalledWith(expect.any(Object), 'output.yml', expect.any(Boolean));
|
|
63
64
|
}));
|
|
64
65
|
it('should call skipDecorators and skipPreprocessors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
66
|
openapi_core_1.detectOpenAPI.mockReturnValue('oas3_0');
|
|
66
67
|
yield join_1.handleJoin({
|
|
67
68
|
apis: ['first.yaml', 'second.yaml'],
|
|
68
|
-
}, 'cli-version');
|
|
69
|
+
}, config_1.ConfigFixture, 'cli-version');
|
|
69
70
|
const config = openapi_core_2.loadConfig();
|
|
70
71
|
expect(config.styleguide.skipDecorators).toHaveBeenCalled();
|
|
71
72
|
expect(config.styleguide.skipPreprocessors).toHaveBeenCalled();
|
|
@@ -76,7 +77,7 @@ describe('handleJoin fails', () => {
|
|
|
76
77
|
apis: ['first.yaml', 'second.yaml'],
|
|
77
78
|
decorate: true,
|
|
78
79
|
preprocess: true,
|
|
79
|
-
}, 'cli-version');
|
|
80
|
+
}, config_1.ConfigFixture, 'cli-version');
|
|
80
81
|
const config = openapi_core_2.loadConfig();
|
|
81
82
|
expect(config.styleguide.skipDecorators).not.toHaveBeenCalled();
|
|
82
83
|
expect(config.styleguide.skipPreprocessors).not.toHaveBeenCalled();
|
|
@@ -14,15 +14,19 @@ const openapi_core_1 = require("@redocly/openapi-core");
|
|
|
14
14
|
const utils_1 = require("../../utils");
|
|
15
15
|
const config_1 = require("../fixtures/config");
|
|
16
16
|
const perf_hooks_1 = require("perf_hooks");
|
|
17
|
+
const wrapper_1 = require("../../wrapper");
|
|
18
|
+
const colorette_1 = require("colorette");
|
|
17
19
|
jest.mock('@redocly/openapi-core');
|
|
18
20
|
jest.mock('../../utils');
|
|
19
21
|
jest.mock('perf_hooks');
|
|
22
|
+
jest.mock('../../update-version-notifier', () => ({
|
|
23
|
+
version: '1.0.0',
|
|
24
|
+
}));
|
|
20
25
|
const argvMock = {
|
|
21
26
|
apis: ['openapi.yaml'],
|
|
22
27
|
'lint-config': 'off',
|
|
23
28
|
format: 'codeframe',
|
|
24
29
|
};
|
|
25
|
-
const versionMock = '1.0.0';
|
|
26
30
|
describe('handleLint', () => {
|
|
27
31
|
let processExitMock;
|
|
28
32
|
let exitCb;
|
|
@@ -43,12 +47,11 @@ describe('handleLint', () => {
|
|
|
43
47
|
});
|
|
44
48
|
describe('loadConfig and getEnrtypoints stage', () => {
|
|
45
49
|
it('should fail if config file does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { config: 'config.yaml' })
|
|
50
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'config.yaml' }));
|
|
47
51
|
expect(utils_1.exitWithError).toHaveBeenCalledWith('Please, provide valid path to the configuration file');
|
|
48
|
-
expect(utils_1.loadConfigAndHandleErrors).toHaveBeenCalledTimes(0);
|
|
49
52
|
}));
|
|
50
53
|
it('should call loadConfigAndHandleErrors and getFallbackApisOrExit', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
-
yield lint_1.handleLint(argvMock
|
|
54
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
52
55
|
expect(utils_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
|
|
53
56
|
configPath: undefined,
|
|
54
57
|
customExtends: undefined,
|
|
@@ -57,7 +60,7 @@ describe('handleLint', () => {
|
|
|
57
60
|
expect(utils_1.getFallbackApisOrExit).toHaveBeenCalled();
|
|
58
61
|
}));
|
|
59
62
|
it('should call loadConfig with args if such exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
-
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { config: 'redocly.yaml', extends: ['some/path'] })
|
|
63
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { config: 'redocly.yaml', extends: ['some/path'] }));
|
|
61
64
|
expect(utils_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
|
|
62
65
|
configPath: 'redocly.yaml',
|
|
63
66
|
customExtends: ['some/path'],
|
|
@@ -65,65 +68,82 @@ describe('handleLint', () => {
|
|
|
65
68
|
});
|
|
66
69
|
}));
|
|
67
70
|
it('should call mergedConfig with clear ignore if `generate-ignore-file` argv', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
-
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { 'generate-ignore-file': true })
|
|
71
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'generate-ignore-file': true }));
|
|
69
72
|
expect(getMergedConfigMock).toHaveBeenCalled();
|
|
70
73
|
}));
|
|
71
74
|
it('should check if ruleset exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
-
yield lint_1.handleLint(argvMock
|
|
75
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
73
76
|
expect(utils_1.checkIfRulesetExist).toHaveBeenCalledTimes(1);
|
|
74
77
|
}));
|
|
75
78
|
it('should fail if apis not provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
-
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { apis: [] })
|
|
79
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { apis: [] }));
|
|
77
80
|
expect(utils_1.getFallbackApisOrExit).toHaveBeenCalledTimes(1);
|
|
78
81
|
expect(utils_1.exitWithError).toHaveBeenCalledWith('No APIs were provided');
|
|
79
82
|
}));
|
|
80
83
|
});
|
|
81
|
-
describe('loop through
|
|
84
|
+
describe('loop through entrypoints and lint stage', () => {
|
|
82
85
|
it('should call getMergedConfig and lint ', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
-
yield lint_1.handleLint(argvMock
|
|
86
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
84
87
|
expect(perf_hooks_1.performance.now).toHaveBeenCalled();
|
|
85
88
|
expect(getMergedConfigMock).toHaveBeenCalled();
|
|
86
89
|
expect(openapi_core_1.lint).toHaveBeenCalled();
|
|
87
90
|
}));
|
|
88
91
|
it('should call skipRules,skipPreprocessors and addIgnore with argv', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
92
|
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
90
|
-
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { 'skip-preprocessor': ['preprocessor'], 'skip-rule': ['rule'], 'generate-ignore-file': true })
|
|
93
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'skip-preprocessor': ['preprocessor'], 'skip-rule': ['rule'], 'generate-ignore-file': true }));
|
|
91
94
|
expect(config_1.ConfigFixture.styleguide.skipRules).toHaveBeenCalledWith(['rule']);
|
|
92
95
|
expect(config_1.ConfigFixture.styleguide.skipPreprocessors).toHaveBeenCalledWith(['preprocessor']);
|
|
93
96
|
}));
|
|
94
97
|
it('should call formatProblems and getExecutionTime with argv', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
98
|
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
96
|
-
yield lint_1.handleLint(Object.assign(Object.assign({}, argvMock), { 'max-problems': 2, format: 'stylish' })
|
|
99
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(Object.assign(Object.assign({}, argvMock), { 'max-problems': 2, format: 'stylish' }));
|
|
97
100
|
expect(openapi_core_1.getTotals).toHaveBeenCalledWith(['problem']);
|
|
98
101
|
expect(openapi_core_1.formatProblems).toHaveBeenCalledWith(['problem'], {
|
|
99
102
|
format: 'stylish',
|
|
100
103
|
maxProblems: 2,
|
|
101
104
|
totals: { errors: 0 },
|
|
102
|
-
version:
|
|
105
|
+
version: '1.0.0',
|
|
103
106
|
});
|
|
104
107
|
expect(utils_1.getExecutionTime).toHaveBeenCalledWith(42);
|
|
105
108
|
}));
|
|
106
109
|
it('should catch error in handleError if something fails', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
110
|
openapi_core_1.lint.mockRejectedValueOnce('error');
|
|
108
|
-
yield lint_1.handleLint(argvMock
|
|
111
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
109
112
|
expect(utils_1.handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
|
|
110
113
|
}));
|
|
111
114
|
});
|
|
112
115
|
describe('erros and warning handle after lint stage', () => {
|
|
113
116
|
it('should call printLintTotals and printLintTotals', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
-
yield lint_1.handleLint(argvMock
|
|
117
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
115
118
|
expect(utils_1.printUnusedWarnings).toHaveBeenCalled();
|
|
116
119
|
}));
|
|
117
120
|
it('should call exit with 0 if no errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
-
|
|
119
|
-
|
|
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());
|
|
120
126
|
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
121
127
|
}));
|
|
122
|
-
it('should exit with 1 if
|
|
128
|
+
it('should exit with 1 if total errors > 0', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
129
|
openapi_core_1.getTotals.mockReturnValueOnce({ errors: 1 });
|
|
124
|
-
yield lint_1.handleLint(argvMock
|
|
125
|
-
exitCb === null || exitCb === void 0 ? void 0 : exitCb();
|
|
130
|
+
yield wrapper_1.commandWrapper(lint_1.handleLint)(argvMock);
|
|
131
|
+
yield (exitCb === null || exitCb === void 0 ? void 0 : exitCb());
|
|
126
132
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
127
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
|
+
}));
|
|
128
148
|
});
|
|
129
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(() => ({
|
|
@@ -37,7 +38,7 @@ describe('push-with-region', () => {
|
|
|
37
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
|
}));
|
|
@@ -48,7 +49,7 @@ describe('push-with-region', () => {
|
|
|
48
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
|
}));
|
|
@@ -37,9 +37,9 @@ describe('push', () => {
|
|
|
37
37
|
destination: '@org/my-api@1.0.0',
|
|
38
38
|
branchName: 'test',
|
|
39
39
|
public: true,
|
|
40
|
-
'
|
|
40
|
+
'job-id': '123',
|
|
41
41
|
'batch-size': 2,
|
|
42
|
-
});
|
|
42
|
+
}, config_1.ConfigFixture);
|
|
43
43
|
expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(1);
|
|
44
44
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
45
45
|
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
@@ -55,16 +55,16 @@ describe('push', () => {
|
|
|
55
55
|
batchSize: 2,
|
|
56
56
|
});
|
|
57
57
|
}));
|
|
58
|
-
it('fails if
|
|
58
|
+
it('fails if jobId value is an empty string', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
59
|
yield push_1.handlePush({
|
|
60
60
|
upsert: true,
|
|
61
61
|
api: 'spec.json',
|
|
62
62
|
destination: '@org/my-api@1.0.0',
|
|
63
63
|
branchName: 'test',
|
|
64
64
|
public: true,
|
|
65
|
-
'
|
|
65
|
+
'job-id': ' ',
|
|
66
66
|
'batch-size': 2,
|
|
67
|
-
});
|
|
67
|
+
}, config_1.ConfigFixture);
|
|
68
68
|
expect(utils_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* () {
|
|
@@ -74,16 +74,13 @@ describe('push', () => {
|
|
|
74
74
|
destination: '@org/my-api@1.0.0',
|
|
75
75
|
branchName: 'test',
|
|
76
76
|
public: true,
|
|
77
|
-
'
|
|
77
|
+
'job-id': '123',
|
|
78
78
|
'batch-size': 1,
|
|
79
|
-
});
|
|
79
|
+
}, config_1.ConfigFixture);
|
|
80
80
|
expect(utils_1.exitWithError).toBeCalledTimes(1);
|
|
81
81
|
}));
|
|
82
82
|
it('push with --files', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
-
|
|
84
|
-
return Object.assign(Object.assign({}, config_1.ConfigFixture), { files });
|
|
85
|
-
});
|
|
86
|
-
//@ts-ignore
|
|
83
|
+
const mockConfig = Object.assign(Object.assign({}, config_1.ConfigFixture), { files: ['./resouces/1.md', './resouces/2.md'] });
|
|
87
84
|
fs.statSync.mockImplementation(() => {
|
|
88
85
|
return { isDirectory: () => false, size: 10 };
|
|
89
86
|
});
|
|
@@ -93,7 +90,7 @@ describe('push', () => {
|
|
|
93
90
|
destination: '@org/my-api@1.0.0',
|
|
94
91
|
public: true,
|
|
95
92
|
files: ['./resouces/1.md', './resouces/2.md'],
|
|
96
|
-
});
|
|
93
|
+
}, mockConfig);
|
|
97
94
|
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
98
95
|
filePaths: ['filePath', 'filePath', 'filePath'],
|
|
99
96
|
isUpsert: true,
|
|
@@ -112,25 +109,23 @@ describe('push', () => {
|
|
|
112
109
|
destination: 'test@v1',
|
|
113
110
|
branchName: 'test',
|
|
114
111
|
public: true,
|
|
115
|
-
'
|
|
112
|
+
'job-id': '123',
|
|
116
113
|
'batch-size': 2,
|
|
117
|
-
});
|
|
114
|
+
}, config_1.ConfigFixture);
|
|
118
115
|
expect(utils_1.exitWithError).toBeCalledTimes(1);
|
|
119
|
-
expect(utils_1.exitWithError).toBeCalledWith(`No organization provided, please use
|
|
116
|
+
expect(utils_1.exitWithError).toBeCalledWith(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
|
|
120
117
|
}));
|
|
121
118
|
it('push should work with organization in config', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
-
|
|
123
|
-
return Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org' });
|
|
124
|
-
});
|
|
119
|
+
const mockConfig = Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org' });
|
|
125
120
|
yield push_1.handlePush({
|
|
126
121
|
upsert: true,
|
|
127
122
|
api: 'spec.json',
|
|
128
123
|
destination: 'my-api@1.0.0',
|
|
129
124
|
branchName: 'test',
|
|
130
125
|
public: true,
|
|
131
|
-
'
|
|
126
|
+
'job-id': '123',
|
|
132
127
|
'batch-size': 2,
|
|
133
|
-
});
|
|
128
|
+
}, mockConfig);
|
|
134
129
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
135
130
|
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
136
131
|
branch: 'test',
|
|
@@ -145,47 +140,65 @@ describe('push', () => {
|
|
|
145
140
|
batchSize: 2,
|
|
146
141
|
});
|
|
147
142
|
}));
|
|
148
|
-
it('push should work if destination not provided
|
|
149
|
-
|
|
150
|
-
return Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org', apis: { 'my-api@1.0.0': { root: 'path' } } });
|
|
151
|
-
});
|
|
143
|
+
it('push should work if destination not provided but api in config is provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
+
const mockConfig = Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org', apis: { 'my-api@1.0.0': { root: 'path' } } });
|
|
152
145
|
yield push_1.handlePush({
|
|
153
146
|
upsert: true,
|
|
154
|
-
api: 'spec.json',
|
|
155
147
|
branchName: 'test',
|
|
156
148
|
public: true,
|
|
157
|
-
'
|
|
149
|
+
'job-id': '123',
|
|
158
150
|
'batch-size': 2,
|
|
159
|
-
});
|
|
151
|
+
}, mockConfig);
|
|
160
152
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
161
153
|
}));
|
|
162
|
-
it('push should fail if
|
|
163
|
-
|
|
164
|
-
return { organization: 'test_org', apis: {} };
|
|
165
|
-
});
|
|
154
|
+
it('push should fail if apis not provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
|
+
const mockConfig = { organization: 'test_org', apis: {} };
|
|
166
156
|
yield push_1.handlePush({
|
|
167
157
|
upsert: true,
|
|
168
158
|
branchName: 'test',
|
|
169
159
|
public: true,
|
|
170
|
-
'
|
|
160
|
+
'job-id': '123',
|
|
171
161
|
'batch-size': 2,
|
|
172
|
-
});
|
|
162
|
+
}, mockConfig);
|
|
173
163
|
expect(utils_1.exitWithError).toBeCalledTimes(1);
|
|
174
164
|
expect(utils_1.exitWithError).toHaveBeenLastCalledWith('Api not found. Please make sure you have provided the correct data in the config file.');
|
|
175
165
|
}));
|
|
166
|
+
it('push should fail if destination not provided', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
167
|
+
const mockConfig = { organization: 'test_org', apis: {} };
|
|
168
|
+
yield push_1.handlePush({
|
|
169
|
+
upsert: true,
|
|
170
|
+
api: 'api.yaml',
|
|
171
|
+
branchName: 'test',
|
|
172
|
+
public: true,
|
|
173
|
+
'job-id': '123',
|
|
174
|
+
'batch-size': 2,
|
|
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.');
|
|
178
|
+
}));
|
|
179
|
+
it('push should fail if destination format is not valid', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
180
|
+
const mockConfig = { organization: 'test_org', apis: {} };
|
|
181
|
+
yield push_1.handlePush({
|
|
182
|
+
upsert: true,
|
|
183
|
+
destination: 'name/v1',
|
|
184
|
+
branchName: 'test',
|
|
185
|
+
public: true,
|
|
186
|
+
'job-id': '123',
|
|
187
|
+
'batch-size': 2,
|
|
188
|
+
}, mockConfig);
|
|
189
|
+
expect(utils_1.exitWithError).toHaveBeenCalledWith(`Destination argument value is not valid, please use the right format: ${colorette_1.yellow('<api-name@api-version>')}`);
|
|
190
|
+
}));
|
|
176
191
|
it('push should work and encode name with spaces', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
177
192
|
const encodeURIComponentSpy = jest.spyOn(global, 'encodeURIComponent');
|
|
178
|
-
|
|
179
|
-
return Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org', apis: { 'my test api@v1': { root: 'path' } } });
|
|
180
|
-
});
|
|
193
|
+
const mockConfig = Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org', apis: { 'my test api@v1': { root: 'path' } } });
|
|
181
194
|
yield push_1.handlePush({
|
|
182
195
|
upsert: true,
|
|
183
196
|
destination: 'my test api@v1',
|
|
184
197
|
branchName: 'test',
|
|
185
198
|
public: true,
|
|
186
|
-
'
|
|
199
|
+
'job-id': '123',
|
|
187
200
|
'batch-size': 2,
|
|
188
|
-
});
|
|
201
|
+
}, mockConfig);
|
|
189
202
|
expect(encodeURIComponentSpy).toHaveReturnedWith('my%20test%20api');
|
|
190
203
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
191
204
|
}));
|
|
@@ -194,65 +207,91 @@ describe('transformPush', () => {
|
|
|
194
207
|
it('should adapt the existing syntax', () => {
|
|
195
208
|
const cb = jest.fn();
|
|
196
209
|
push_1.transformPush(cb)({
|
|
197
|
-
|
|
210
|
+
api: 'openapi.yaml',
|
|
198
211
|
maybeDestination: '@testing_org/main@v1',
|
|
199
|
-
});
|
|
212
|
+
}, {});
|
|
200
213
|
expect(cb).toBeCalledWith({
|
|
201
214
|
api: 'openapi.yaml',
|
|
202
215
|
destination: '@testing_org/main@v1',
|
|
203
|
-
});
|
|
216
|
+
}, {});
|
|
204
217
|
});
|
|
205
218
|
it('should adapt the existing syntax (including branchName)', () => {
|
|
206
219
|
const cb = jest.fn();
|
|
207
220
|
push_1.transformPush(cb)({
|
|
208
|
-
|
|
221
|
+
api: 'openapi.yaml',
|
|
209
222
|
maybeDestination: '@testing_org/main@v1',
|
|
210
223
|
maybeBranchName: 'other',
|
|
211
|
-
});
|
|
224
|
+
}, {});
|
|
212
225
|
expect(cb).toBeCalledWith({
|
|
213
226
|
api: 'openapi.yaml',
|
|
214
227
|
destination: '@testing_org/main@v1',
|
|
215
228
|
branchName: 'other',
|
|
216
|
-
});
|
|
229
|
+
}, {});
|
|
217
230
|
});
|
|
218
231
|
it('should use --branch option firstly', () => {
|
|
219
232
|
const cb = jest.fn();
|
|
220
233
|
push_1.transformPush(cb)({
|
|
221
|
-
|
|
234
|
+
api: 'openapi.yaml',
|
|
222
235
|
maybeDestination: '@testing_org/main@v1',
|
|
223
236
|
maybeBranchName: 'other',
|
|
224
237
|
branch: 'priority-branch',
|
|
225
|
-
});
|
|
238
|
+
}, {});
|
|
226
239
|
expect(cb).toBeCalledWith({
|
|
227
240
|
api: 'openapi.yaml',
|
|
228
241
|
destination: '@testing_org/main@v1',
|
|
229
242
|
branchName: 'priority-branch',
|
|
230
|
-
});
|
|
243
|
+
}, {});
|
|
231
244
|
});
|
|
232
245
|
it('should work for a destination only', () => {
|
|
233
246
|
const cb = jest.fn();
|
|
234
247
|
push_1.transformPush(cb)({
|
|
235
|
-
|
|
236
|
-
});
|
|
248
|
+
api: '@testing_org/main@v1',
|
|
249
|
+
}, {});
|
|
237
250
|
expect(cb).toBeCalledWith({
|
|
238
251
|
destination: '@testing_org/main@v1',
|
|
239
|
-
});
|
|
252
|
+
}, {});
|
|
253
|
+
});
|
|
254
|
+
it('should work for a api only', () => {
|
|
255
|
+
const cb = jest.fn();
|
|
256
|
+
push_1.transformPush(cb)({
|
|
257
|
+
api: 'test.yaml',
|
|
258
|
+
}, {});
|
|
259
|
+
expect(cb).toBeCalledWith({
|
|
260
|
+
api: 'test.yaml',
|
|
261
|
+
}, {});
|
|
240
262
|
});
|
|
241
263
|
it('should accept aliases for the old syntax', () => {
|
|
242
264
|
const cb = jest.fn();
|
|
243
265
|
push_1.transformPush(cb)({
|
|
244
|
-
|
|
266
|
+
api: 'alias',
|
|
245
267
|
maybeDestination: '@testing_org/main@v1',
|
|
246
|
-
});
|
|
268
|
+
}, {});
|
|
247
269
|
expect(cb).toBeCalledWith({
|
|
248
270
|
destination: '@testing_org/main@v1',
|
|
249
271
|
api: 'alias',
|
|
250
|
-
});
|
|
272
|
+
}, {});
|
|
273
|
+
});
|
|
274
|
+
it('should use --job-id option firstly', () => {
|
|
275
|
+
const cb = jest.fn();
|
|
276
|
+
push_1.transformPush(cb)({
|
|
277
|
+
'batch-id': 'b-123',
|
|
278
|
+
'job-id': 'j-123',
|
|
279
|
+
api: 'test',
|
|
280
|
+
maybeDestination: 'main@v1',
|
|
281
|
+
branch: 'test',
|
|
282
|
+
destination: 'main@v1',
|
|
283
|
+
}, {});
|
|
284
|
+
expect(cb).toBeCalledWith({
|
|
285
|
+
'job-id': 'j-123',
|
|
286
|
+
api: 'test',
|
|
287
|
+
branchName: 'test',
|
|
288
|
+
destination: 'main@v1',
|
|
289
|
+
}, {});
|
|
251
290
|
});
|
|
252
291
|
it('should accept no arguments at all', () => {
|
|
253
292
|
const cb = jest.fn();
|
|
254
|
-
push_1.transformPush(cb)({});
|
|
255
|
-
expect(cb).toBeCalledWith({});
|
|
293
|
+
push_1.transformPush(cb)({}, {});
|
|
294
|
+
expect(cb).toBeCalledWith({}, {});
|
|
256
295
|
});
|
|
257
296
|
});
|
|
258
297
|
describe('getDestinationProps', () => {
|