@redocly/cli 0.0.0-snapshot.1737554067
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/README.md +114 -0
- package/bin/cli.js +3 -0
- package/lib/__mocks__/@redocly/openapi-core.d.ts +99 -0
- package/lib/__mocks__/@redocly/openapi-core.js +84 -0
- package/lib/__mocks__/documents.d.ts +150 -0
- package/lib/__mocks__/documents.js +123 -0
- package/lib/__mocks__/fs.d.ts +8 -0
- package/lib/__mocks__/fs.js +9 -0
- package/lib/__mocks__/perf_hooks.d.ts +3 -0
- package/lib/__mocks__/perf_hooks.js +6 -0
- package/lib/__mocks__/redoc.d.ts +6 -0
- package/lib/__mocks__/redoc.js +5 -0
- package/lib/__tests__/commands/build-docs.test.d.ts +1 -0
- package/lib/__tests__/commands/build-docs.test.js +54 -0
- package/lib/__tests__/commands/bundle.test.d.ts +1 -0
- package/lib/__tests__/commands/bundle.test.js +235 -0
- package/lib/__tests__/commands/join.test.d.ts +1 -0
- package/lib/__tests__/commands/join.test.js +274 -0
- package/lib/__tests__/commands/lint.test.d.ts +1 -0
- package/lib/__tests__/commands/lint.test.js +149 -0
- package/lib/__tests__/commands/push-region.test.d.ts +1 -0
- package/lib/__tests__/commands/push-region.test.js +55 -0
- package/lib/__tests__/commands/push.test.d.ts +1 -0
- package/lib/__tests__/commands/push.test.js +463 -0
- package/lib/__tests__/fetch-with-timeout.test.d.ts +1 -0
- package/lib/__tests__/fetch-with-timeout.test.js +44 -0
- package/lib/__tests__/fixtures/config.d.ts +21 -0
- package/lib/__tests__/fixtures/config.js +24 -0
- package/lib/__tests__/spinner.test.d.ts +1 -0
- package/lib/__tests__/spinner.test.js +43 -0
- package/lib/__tests__/utils.test.d.ts +1 -0
- package/lib/__tests__/utils.test.js +593 -0
- package/lib/__tests__/wrapper.test.d.ts +1 -0
- package/lib/__tests__/wrapper.test.js +68 -0
- package/lib/cms/api/__tests__/api-keys.test.d.ts +1 -0
- package/lib/cms/api/__tests__/api-keys.test.js +26 -0
- package/lib/cms/api/__tests__/api.client.test.d.ts +1 -0
- package/lib/cms/api/__tests__/api.client.test.js +333 -0
- package/lib/cms/api/__tests__/domains.test.d.ts +1 -0
- package/lib/cms/api/__tests__/domains.test.js +13 -0
- package/lib/cms/api/api-client.d.ts +75 -0
- package/lib/cms/api/api-client.js +225 -0
- package/lib/cms/api/api-keys.d.ts +1 -0
- package/lib/cms/api/api-keys.js +23 -0
- package/lib/cms/api/domains.d.ts +1 -0
- package/lib/cms/api/domains.js +11 -0
- package/lib/cms/api/index.d.ts +3 -0
- package/lib/cms/api/index.js +19 -0
- package/lib/cms/api/types.d.ts +102 -0
- package/lib/cms/api/types.js +2 -0
- package/lib/cms/commands/__tests__/push-status.test.d.ts +1 -0
- package/lib/cms/commands/__tests__/push-status.test.js +563 -0
- package/lib/cms/commands/__tests__/push.test.d.ts +1 -0
- package/lib/cms/commands/__tests__/push.test.js +315 -0
- package/lib/cms/commands/__tests__/utils.test.d.ts +1 -0
- package/lib/cms/commands/__tests__/utils.test.js +51 -0
- package/lib/cms/commands/push-status.d.ts +23 -0
- package/lib/cms/commands/push-status.js +206 -0
- package/lib/cms/commands/push.d.ts +28 -0
- package/lib/cms/commands/push.js +142 -0
- package/lib/cms/commands/utils.d.ts +25 -0
- package/lib/cms/commands/utils.js +46 -0
- package/lib/cms/utils.d.ts +2 -0
- package/lib/cms/utils.js +6 -0
- package/lib/commands/build-docs/index.d.ts +3 -0
- package/lib/commands/build-docs/index.js +39 -0
- package/lib/commands/build-docs/template.hbs +23 -0
- package/lib/commands/build-docs/types.d.ts +23 -0
- package/lib/commands/build-docs/types.js +2 -0
- package/lib/commands/build-docs/utils.d.ts +7 -0
- package/lib/commands/build-docs/utils.js +87 -0
- package/lib/commands/bundle.d.ts +14 -0
- package/lib/commands/bundle.js +91 -0
- package/lib/commands/eject.d.ts +9 -0
- package/lib/commands/eject.js +28 -0
- package/lib/commands/join.d.ts +11 -0
- package/lib/commands/join.js +565 -0
- package/lib/commands/lint.d.ts +13 -0
- package/lib/commands/lint.js +108 -0
- package/lib/commands/login.d.ts +9 -0
- package/lib/commands/login.js +23 -0
- package/lib/commands/preview-docs/index.d.ts +12 -0
- package/lib/commands/preview-docs/index.js +127 -0
- package/lib/commands/preview-docs/preview-server/default.hbs +24 -0
- package/lib/commands/preview-docs/preview-server/hot.js +59 -0
- package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +21 -0
- package/lib/commands/preview-docs/preview-server/preview-server.d.ts +5 -0
- package/lib/commands/preview-docs/preview-server/preview-server.js +113 -0
- package/lib/commands/preview-docs/preview-server/server.d.ts +22 -0
- package/lib/commands/preview-docs/preview-server/server.js +85 -0
- package/lib/commands/preview-project/constants.d.ts +14 -0
- package/lib/commands/preview-project/constants.js +22 -0
- package/lib/commands/preview-project/index.d.ts +3 -0
- package/lib/commands/preview-project/index.js +56 -0
- package/lib/commands/preview-project/types.d.ts +10 -0
- package/lib/commands/preview-project/types.js +2 -0
- package/lib/commands/push.d.ts +44 -0
- package/lib/commands/push.js +295 -0
- package/lib/commands/split/__tests__/index.test.d.ts +1 -0
- package/lib/commands/split/__tests__/index.test.js +91 -0
- package/lib/commands/split/index.d.ts +13 -0
- package/lib/commands/split/index.js +259 -0
- package/lib/commands/split/types.d.ts +36 -0
- package/lib/commands/split/types.js +51 -0
- package/lib/commands/stats.d.ts +8 -0
- package/lib/commands/stats.js +96 -0
- package/lib/commands/translations.d.ts +7 -0
- package/lib/commands/translations.js +20 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +733 -0
- package/lib/types.d.ts +43 -0
- package/lib/types.js +5 -0
- package/lib/utils/__mocks__/miscellaneous.d.ts +43 -0
- package/lib/utils/__mocks__/miscellaneous.js +24 -0
- package/lib/utils/assert-node-version.d.ts +1 -0
- package/lib/utils/assert-node-version.js +16 -0
- package/lib/utils/fetch-with-timeout.d.ts +7 -0
- package/lib/utils/fetch-with-timeout.js +26 -0
- package/lib/utils/getCommandNameFromArgs.d.ts +2 -0
- package/lib/utils/getCommandNameFromArgs.js +6 -0
- package/lib/utils/js-utils.d.ts +5 -0
- package/lib/utils/js-utils.js +28 -0
- package/lib/utils/miscellaneous.d.ts +81 -0
- package/lib/utils/miscellaneous.js +551 -0
- package/lib/utils/platform.d.ts +16 -0
- package/lib/utils/platform.js +34 -0
- package/lib/utils/spinner.d.ts +10 -0
- package/lib/utils/spinner.js +42 -0
- package/lib/utils/update-version-notifier.d.ts +3 -0
- package/lib/utils/update-version-notifier.js +102 -0
- package/lib/wrapper.d.ts +11 -0
- package/lib/wrapper.js +65 -0
- package/package.json +69 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const openapi_core_1 = require("@redocly/openapi-core");
|
|
4
|
+
const push_1 = require("../../commands/push");
|
|
5
|
+
const login_1 = require("../../commands/login");
|
|
6
|
+
const config_1 = require("../fixtures/config");
|
|
7
|
+
jest.mock('fs');
|
|
8
|
+
jest.mock('node-fetch', () => ({
|
|
9
|
+
default: jest.fn(() => ({
|
|
10
|
+
ok: true,
|
|
11
|
+
json: jest.fn().mockResolvedValue({}),
|
|
12
|
+
})),
|
|
13
|
+
}));
|
|
14
|
+
jest.mock('@redocly/openapi-core');
|
|
15
|
+
jest.mock('../../commands/login');
|
|
16
|
+
jest.mock('../../utils/miscellaneous');
|
|
17
|
+
openapi_core_1.getMergedConfig.mockImplementation((config) => config);
|
|
18
|
+
const mockPromptClientToken = login_1.promptClientToken;
|
|
19
|
+
describe('push-with-region', () => {
|
|
20
|
+
const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
|
|
21
|
+
redoclyClient.isAuthorizedWithRedoclyByRegion = jest.fn().mockResolvedValue(false);
|
|
22
|
+
beforeAll(() => {
|
|
23
|
+
jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
|
|
24
|
+
});
|
|
25
|
+
it('should call login with default domain when region is US', async () => {
|
|
26
|
+
redoclyClient.domain = 'redoc.ly';
|
|
27
|
+
await (0, push_1.handlePush)({
|
|
28
|
+
argv: {
|
|
29
|
+
upsert: true,
|
|
30
|
+
api: 'spec.json',
|
|
31
|
+
destination: '@org/my-api@1.0.0',
|
|
32
|
+
branchName: 'test',
|
|
33
|
+
},
|
|
34
|
+
config: config_1.ConfigFixture,
|
|
35
|
+
version: 'cli-version',
|
|
36
|
+
});
|
|
37
|
+
expect(mockPromptClientToken).toBeCalledTimes(1);
|
|
38
|
+
expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
|
|
39
|
+
});
|
|
40
|
+
it('should call login with EU domain when region is EU', async () => {
|
|
41
|
+
redoclyClient.domain = 'eu.redocly.com';
|
|
42
|
+
await (0, push_1.handlePush)({
|
|
43
|
+
argv: {
|
|
44
|
+
upsert: true,
|
|
45
|
+
api: 'spec.json',
|
|
46
|
+
destination: '@org/my-api@1.0.0',
|
|
47
|
+
branchName: 'test',
|
|
48
|
+
},
|
|
49
|
+
config: config_1.ConfigFixture,
|
|
50
|
+
version: 'cli-version',
|
|
51
|
+
});
|
|
52
|
+
expect(mockPromptClientToken).toBeCalledTimes(1);
|
|
53
|
+
expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const openapi_core_1 = require("@redocly/openapi-core");
|
|
5
|
+
const miscellaneous_1 = require("../../utils/miscellaneous");
|
|
6
|
+
const push_1 = require("../../commands/push");
|
|
7
|
+
const config_1 = require("../fixtures/config");
|
|
8
|
+
const colorette_1 = require("colorette");
|
|
9
|
+
jest.mock('fs');
|
|
10
|
+
jest.mock('node-fetch', () => ({
|
|
11
|
+
default: jest.fn(() => ({
|
|
12
|
+
ok: true,
|
|
13
|
+
json: jest.fn().mockResolvedValue({}),
|
|
14
|
+
})),
|
|
15
|
+
}));
|
|
16
|
+
jest.mock('@redocly/openapi-core');
|
|
17
|
+
jest.mock('../../utils/miscellaneous');
|
|
18
|
+
openapi_core_1.getMergedConfig.mockImplementation((config) => config);
|
|
19
|
+
describe('push', () => {
|
|
20
|
+
const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
|
|
23
|
+
});
|
|
24
|
+
it('pushes definition', async () => {
|
|
25
|
+
await (0, push_1.handlePush)({
|
|
26
|
+
argv: {
|
|
27
|
+
upsert: true,
|
|
28
|
+
api: 'spec.json',
|
|
29
|
+
destination: '@org/my-api@1.0.0',
|
|
30
|
+
branchName: 'test',
|
|
31
|
+
public: true,
|
|
32
|
+
'job-id': '123',
|
|
33
|
+
'batch-size': 2,
|
|
34
|
+
},
|
|
35
|
+
config: config_1.ConfigFixture,
|
|
36
|
+
version: 'cli-version',
|
|
37
|
+
});
|
|
38
|
+
expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(1);
|
|
39
|
+
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
40
|
+
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
41
|
+
branch: 'test',
|
|
42
|
+
filePaths: ['filePath'],
|
|
43
|
+
isUpsert: true,
|
|
44
|
+
isPublic: true,
|
|
45
|
+
name: 'my-api',
|
|
46
|
+
organizationId: 'org',
|
|
47
|
+
rootFilePath: 'filePath',
|
|
48
|
+
version: '1.0.0',
|
|
49
|
+
batchId: '123',
|
|
50
|
+
batchSize: 2,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('fails if jobId value is an empty string', async () => {
|
|
54
|
+
await (0, push_1.handlePush)({
|
|
55
|
+
argv: {
|
|
56
|
+
upsert: true,
|
|
57
|
+
api: 'spec.json',
|
|
58
|
+
destination: '@org/my-api@1.0.0',
|
|
59
|
+
branchName: 'test',
|
|
60
|
+
public: true,
|
|
61
|
+
'job-id': ' ',
|
|
62
|
+
'batch-size': 2,
|
|
63
|
+
},
|
|
64
|
+
config: config_1.ConfigFixture,
|
|
65
|
+
version: 'cli-version',
|
|
66
|
+
});
|
|
67
|
+
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
68
|
+
});
|
|
69
|
+
it('fails if batchSize value is less than 2', async () => {
|
|
70
|
+
await (0, push_1.handlePush)({
|
|
71
|
+
argv: {
|
|
72
|
+
upsert: true,
|
|
73
|
+
api: 'spec.json',
|
|
74
|
+
destination: '@org/my-api@1.0.0',
|
|
75
|
+
branchName: 'test',
|
|
76
|
+
public: true,
|
|
77
|
+
'job-id': '123',
|
|
78
|
+
'batch-size': 1,
|
|
79
|
+
},
|
|
80
|
+
config: config_1.ConfigFixture,
|
|
81
|
+
version: 'cli-version',
|
|
82
|
+
});
|
|
83
|
+
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
84
|
+
});
|
|
85
|
+
it('push with --files', async () => {
|
|
86
|
+
const mockConfig = { ...config_1.ConfigFixture, files: ['./resouces/1.md', './resouces/2.md'] };
|
|
87
|
+
fs.statSync.mockImplementation(() => {
|
|
88
|
+
return { isDirectory: () => false, size: 10 };
|
|
89
|
+
});
|
|
90
|
+
await (0, push_1.handlePush)({
|
|
91
|
+
argv: {
|
|
92
|
+
upsert: true,
|
|
93
|
+
api: 'spec.json',
|
|
94
|
+
destination: '@org/my-api@1.0.0',
|
|
95
|
+
public: true,
|
|
96
|
+
files: ['./resouces/1.md', './resouces/2.md'],
|
|
97
|
+
},
|
|
98
|
+
config: mockConfig,
|
|
99
|
+
version: 'cli-version',
|
|
100
|
+
});
|
|
101
|
+
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
102
|
+
filePaths: ['filePath', 'filePath', 'filePath'],
|
|
103
|
+
isUpsert: true,
|
|
104
|
+
isPublic: true,
|
|
105
|
+
name: 'my-api',
|
|
106
|
+
organizationId: 'org',
|
|
107
|
+
rootFilePath: 'filePath',
|
|
108
|
+
version: '1.0.0',
|
|
109
|
+
});
|
|
110
|
+
expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(3);
|
|
111
|
+
});
|
|
112
|
+
it('push should fail if organization not provided', async () => {
|
|
113
|
+
await (0, push_1.handlePush)({
|
|
114
|
+
argv: {
|
|
115
|
+
upsert: true,
|
|
116
|
+
api: 'spec.json',
|
|
117
|
+
destination: 'test@v1',
|
|
118
|
+
branchName: 'test',
|
|
119
|
+
public: true,
|
|
120
|
+
'job-id': '123',
|
|
121
|
+
'batch-size': 2,
|
|
122
|
+
},
|
|
123
|
+
config: config_1.ConfigFixture,
|
|
124
|
+
version: 'cli-version',
|
|
125
|
+
});
|
|
126
|
+
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
127
|
+
expect(miscellaneous_1.exitWithError).toBeCalledWith(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
|
|
128
|
+
});
|
|
129
|
+
it('push should work with organization in config', async () => {
|
|
130
|
+
const mockConfig = { ...config_1.ConfigFixture, organization: 'test_org' };
|
|
131
|
+
await (0, push_1.handlePush)({
|
|
132
|
+
argv: {
|
|
133
|
+
upsert: true,
|
|
134
|
+
api: 'spec.json',
|
|
135
|
+
destination: 'my-api@1.0.0',
|
|
136
|
+
branchName: 'test',
|
|
137
|
+
public: true,
|
|
138
|
+
'job-id': '123',
|
|
139
|
+
'batch-size': 2,
|
|
140
|
+
},
|
|
141
|
+
config: mockConfig,
|
|
142
|
+
version: 'cli-version',
|
|
143
|
+
});
|
|
144
|
+
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
145
|
+
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
146
|
+
branch: 'test',
|
|
147
|
+
filePaths: ['filePath'],
|
|
148
|
+
isUpsert: true,
|
|
149
|
+
isPublic: true,
|
|
150
|
+
name: 'my-api',
|
|
151
|
+
organizationId: 'test_org',
|
|
152
|
+
rootFilePath: 'filePath',
|
|
153
|
+
version: '1.0.0',
|
|
154
|
+
batchId: '123',
|
|
155
|
+
batchSize: 2,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
it('push should work if destination not provided but api in config is provided', async () => {
|
|
159
|
+
const mockConfig = {
|
|
160
|
+
...config_1.ConfigFixture,
|
|
161
|
+
organization: 'test_org',
|
|
162
|
+
apis: { 'my-api@1.0.0': { root: 'path' } },
|
|
163
|
+
};
|
|
164
|
+
await (0, push_1.handlePush)({
|
|
165
|
+
argv: {
|
|
166
|
+
upsert: true,
|
|
167
|
+
branchName: 'test',
|
|
168
|
+
public: true,
|
|
169
|
+
'job-id': '123',
|
|
170
|
+
'batch-size': 2,
|
|
171
|
+
},
|
|
172
|
+
config: mockConfig,
|
|
173
|
+
version: 'cli-version',
|
|
174
|
+
});
|
|
175
|
+
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
176
|
+
});
|
|
177
|
+
it('push should fail if apis not provided', async () => {
|
|
178
|
+
const mockConfig = { organization: 'test_org', apis: {} };
|
|
179
|
+
await (0, push_1.handlePush)({
|
|
180
|
+
argv: {
|
|
181
|
+
upsert: true,
|
|
182
|
+
branchName: 'test',
|
|
183
|
+
public: true,
|
|
184
|
+
'job-id': '123',
|
|
185
|
+
'batch-size': 2,
|
|
186
|
+
},
|
|
187
|
+
config: mockConfig,
|
|
188
|
+
version: 'cli-version',
|
|
189
|
+
});
|
|
190
|
+
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
191
|
+
expect(miscellaneous_1.exitWithError).toHaveBeenLastCalledWith('Api not found. Please make sure you have provided the correct data in the config file.');
|
|
192
|
+
});
|
|
193
|
+
it('push should fail if destination not provided', async () => {
|
|
194
|
+
const mockConfig = { organization: 'test_org', apis: {} };
|
|
195
|
+
await (0, push_1.handlePush)({
|
|
196
|
+
argv: {
|
|
197
|
+
upsert: true,
|
|
198
|
+
api: 'api.yaml',
|
|
199
|
+
branchName: 'test',
|
|
200
|
+
public: true,
|
|
201
|
+
'job-id': '123',
|
|
202
|
+
'batch-size': 2,
|
|
203
|
+
},
|
|
204
|
+
config: mockConfig,
|
|
205
|
+
version: 'cli-version',
|
|
206
|
+
});
|
|
207
|
+
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
208
|
+
expect(miscellaneous_1.exitWithError).toHaveBeenLastCalledWith('No destination provided, please use --destination option to provide destination.');
|
|
209
|
+
});
|
|
210
|
+
it('push should fail if destination format is not valid', async () => {
|
|
211
|
+
const mockConfig = { organization: 'test_org', apis: {} };
|
|
212
|
+
await (0, push_1.handlePush)({
|
|
213
|
+
argv: {
|
|
214
|
+
upsert: true,
|
|
215
|
+
destination: 'name/v1',
|
|
216
|
+
branchName: 'test',
|
|
217
|
+
public: true,
|
|
218
|
+
'job-id': '123',
|
|
219
|
+
'batch-size': 2,
|
|
220
|
+
},
|
|
221
|
+
config: mockConfig,
|
|
222
|
+
version: 'cli-version',
|
|
223
|
+
});
|
|
224
|
+
expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`Destination argument value is not valid, please use the right format: ${(0, colorette_1.yellow)('<api-name@api-version>')}.`);
|
|
225
|
+
});
|
|
226
|
+
it('push should work and encode name with spaces', async () => {
|
|
227
|
+
const encodeURIComponentSpy = jest.spyOn(global, 'encodeURIComponent');
|
|
228
|
+
const mockConfig = {
|
|
229
|
+
...config_1.ConfigFixture,
|
|
230
|
+
organization: 'test_org',
|
|
231
|
+
apis: { 'my test api@v1': { root: 'path' } },
|
|
232
|
+
};
|
|
233
|
+
await (0, push_1.handlePush)({
|
|
234
|
+
argv: {
|
|
235
|
+
upsert: true,
|
|
236
|
+
destination: 'my test api@v1',
|
|
237
|
+
branchName: 'test',
|
|
238
|
+
public: true,
|
|
239
|
+
'job-id': '123',
|
|
240
|
+
'batch-size': 2,
|
|
241
|
+
},
|
|
242
|
+
config: mockConfig,
|
|
243
|
+
version: 'cli-version',
|
|
244
|
+
});
|
|
245
|
+
expect(encodeURIComponentSpy).toHaveReturnedWith('my%20test%20api');
|
|
246
|
+
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
describe('transformPush', () => {
|
|
250
|
+
it('should adapt the existing syntax', () => {
|
|
251
|
+
const cb = jest.fn();
|
|
252
|
+
(0, push_1.transformPush)(cb)({
|
|
253
|
+
argv: {
|
|
254
|
+
apis: ['openapi.yaml', '@testing_org/main@v1'],
|
|
255
|
+
},
|
|
256
|
+
config: {},
|
|
257
|
+
version: 'cli-version',
|
|
258
|
+
});
|
|
259
|
+
expect(cb).toBeCalledWith({
|
|
260
|
+
argv: {
|
|
261
|
+
api: 'openapi.yaml',
|
|
262
|
+
destination: '@testing_org/main@v1',
|
|
263
|
+
},
|
|
264
|
+
config: {},
|
|
265
|
+
version: 'cli-version',
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
it('should adapt the existing syntax (including branchName)', () => {
|
|
269
|
+
const cb = jest.fn();
|
|
270
|
+
(0, push_1.transformPush)(cb)({
|
|
271
|
+
argv: {
|
|
272
|
+
apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
|
|
273
|
+
},
|
|
274
|
+
config: {},
|
|
275
|
+
version: 'cli-version',
|
|
276
|
+
});
|
|
277
|
+
expect(cb).toBeCalledWith({
|
|
278
|
+
argv: {
|
|
279
|
+
api: 'openapi.yaml',
|
|
280
|
+
destination: '@testing_org/main@v1',
|
|
281
|
+
branchName: 'other',
|
|
282
|
+
},
|
|
283
|
+
config: {},
|
|
284
|
+
version: 'cli-version',
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
it('should use --branch option firstly', () => {
|
|
288
|
+
const cb = jest.fn();
|
|
289
|
+
(0, push_1.transformPush)(cb)({
|
|
290
|
+
argv: {
|
|
291
|
+
apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
|
|
292
|
+
branch: 'priority-branch',
|
|
293
|
+
},
|
|
294
|
+
config: {},
|
|
295
|
+
version: 'cli-version',
|
|
296
|
+
});
|
|
297
|
+
expect(cb).toBeCalledWith({
|
|
298
|
+
argv: {
|
|
299
|
+
api: 'openapi.yaml',
|
|
300
|
+
destination: '@testing_org/main@v1',
|
|
301
|
+
branchName: 'priority-branch',
|
|
302
|
+
},
|
|
303
|
+
config: {},
|
|
304
|
+
version: 'cli-version',
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
it('should work for a destination only', () => {
|
|
308
|
+
const cb = jest.fn();
|
|
309
|
+
(0, push_1.transformPush)(cb)({
|
|
310
|
+
argv: {
|
|
311
|
+
apis: ['main@v1'],
|
|
312
|
+
},
|
|
313
|
+
config: {},
|
|
314
|
+
version: 'cli-version',
|
|
315
|
+
});
|
|
316
|
+
expect(cb).toBeCalledWith({
|
|
317
|
+
argv: {
|
|
318
|
+
destination: 'main@v1',
|
|
319
|
+
},
|
|
320
|
+
config: {},
|
|
321
|
+
version: 'cli-version',
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
it('should work for a api only', () => {
|
|
325
|
+
const cb = jest.fn();
|
|
326
|
+
(0, push_1.transformPush)(cb)({
|
|
327
|
+
argv: {
|
|
328
|
+
apis: ['test.yaml'],
|
|
329
|
+
},
|
|
330
|
+
config: {},
|
|
331
|
+
version: 'cli-version',
|
|
332
|
+
});
|
|
333
|
+
expect(cb).toBeCalledWith({
|
|
334
|
+
argv: {
|
|
335
|
+
api: 'test.yaml',
|
|
336
|
+
},
|
|
337
|
+
config: {},
|
|
338
|
+
version: 'cli-version',
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
it('should use destination from option', () => {
|
|
342
|
+
const cb = jest.fn();
|
|
343
|
+
(0, push_1.transformPush)(cb)({
|
|
344
|
+
argv: {
|
|
345
|
+
apis: ['test.yaml', 'test@v1'],
|
|
346
|
+
destination: 'main@v1',
|
|
347
|
+
},
|
|
348
|
+
config: {},
|
|
349
|
+
version: 'cli-version',
|
|
350
|
+
});
|
|
351
|
+
expect(cb).toBeCalledWith({
|
|
352
|
+
argv: {
|
|
353
|
+
destination: 'main@v1',
|
|
354
|
+
api: 'test.yaml',
|
|
355
|
+
},
|
|
356
|
+
config: {},
|
|
357
|
+
version: 'cli-version',
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
it('should use --job-id option firstly', () => {
|
|
361
|
+
const cb = jest.fn();
|
|
362
|
+
(0, push_1.transformPush)(cb)({
|
|
363
|
+
argv: {
|
|
364
|
+
'batch-id': 'b-123',
|
|
365
|
+
'job-id': 'j-123',
|
|
366
|
+
apis: ['test'],
|
|
367
|
+
branch: 'test',
|
|
368
|
+
destination: 'main@v1',
|
|
369
|
+
},
|
|
370
|
+
config: {},
|
|
371
|
+
version: 'cli-version',
|
|
372
|
+
});
|
|
373
|
+
expect(cb).toBeCalledWith({
|
|
374
|
+
argv: {
|
|
375
|
+
'job-id': 'j-123',
|
|
376
|
+
api: 'test',
|
|
377
|
+
branchName: 'test',
|
|
378
|
+
destination: 'main@v1',
|
|
379
|
+
},
|
|
380
|
+
config: {},
|
|
381
|
+
version: 'cli-version',
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
it('should accept no arguments at all', () => {
|
|
385
|
+
const cb = jest.fn();
|
|
386
|
+
(0, push_1.transformPush)(cb)({ argv: {}, config: {}, version: 'cli-version' });
|
|
387
|
+
expect(cb).toBeCalledWith({ argv: {}, config: {}, version: 'cli-version' });
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
describe('getDestinationProps', () => {
|
|
391
|
+
it('should get valid destination props for the full destination syntax', () => {
|
|
392
|
+
expect((0, push_1.getDestinationProps)('@testing_org/main@v1', 'org-from-config')).toEqual({
|
|
393
|
+
organizationId: 'testing_org',
|
|
394
|
+
name: 'main',
|
|
395
|
+
version: 'v1',
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
it('should fallback the organizationId from a config for the short destination syntax', () => {
|
|
399
|
+
expect((0, push_1.getDestinationProps)('main@v1', 'org-from-config')).toEqual({
|
|
400
|
+
organizationId: 'org-from-config',
|
|
401
|
+
name: 'main',
|
|
402
|
+
version: 'v1',
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
it('should fallback the organizationId from a config if no destination provided', () => {
|
|
406
|
+
expect((0, push_1.getDestinationProps)(undefined, 'org-from-config')).toEqual({
|
|
407
|
+
organizationId: 'org-from-config',
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
it('should return empty organizationId if there is no one found', () => {
|
|
411
|
+
expect((0, push_1.getDestinationProps)('main@v1', undefined)).toEqual({
|
|
412
|
+
organizationId: undefined,
|
|
413
|
+
name: 'main',
|
|
414
|
+
version: 'v1',
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
it('should return organizationId from destination string', () => {
|
|
418
|
+
expect((0, push_1.getDestinationProps)('@test-org/main@main-v1', undefined)).toEqual({
|
|
419
|
+
organizationId: 'test-org',
|
|
420
|
+
name: 'main',
|
|
421
|
+
version: 'main-v1',
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
it('should return organizationId, version and empty name from destination string', () => {
|
|
425
|
+
expect((0, push_1.getDestinationProps)('@test_org/@main_v1', undefined)).toEqual({
|
|
426
|
+
organizationId: 'test_org',
|
|
427
|
+
name: '',
|
|
428
|
+
version: 'main_v1',
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
it('should validate organizationId with space and version with dot', () => {
|
|
432
|
+
expect((0, push_1.getDestinationProps)('@test org/simple_name@main.v1', undefined)).toEqual({
|
|
433
|
+
organizationId: 'test org',
|
|
434
|
+
name: 'simple_name',
|
|
435
|
+
version: 'main.v1',
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
it('should not work with "@" in destination name', () => {
|
|
439
|
+
expect((0, push_1.getDestinationProps)('@test org/simple@name@main.v1', undefined)).toEqual({
|
|
440
|
+
organizationId: undefined,
|
|
441
|
+
name: undefined,
|
|
442
|
+
version: undefined,
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
describe('getApiRoot', () => {
|
|
447
|
+
let config = {
|
|
448
|
+
apis: {
|
|
449
|
+
'main@v1': {
|
|
450
|
+
root: 'openapi.yaml',
|
|
451
|
+
},
|
|
452
|
+
main: {
|
|
453
|
+
root: 'latest.yaml',
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
it('should resolve the correct api for a valid name & version', () => {
|
|
458
|
+
expect((0, push_1.getApiRoot)({ name: 'main', version: 'v1', config })).toEqual('openapi.yaml');
|
|
459
|
+
});
|
|
460
|
+
it('should resolve the latest version of api if there is no matching version', () => {
|
|
461
|
+
expect((0, push_1.getApiRoot)({ name: 'main', version: 'latest', config })).toEqual('latest.yaml');
|
|
462
|
+
});
|
|
463
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const abort_controller_1 = require("abort-controller");
|
|
4
|
+
const fetch_with_timeout_1 = require("../utils/fetch-with-timeout");
|
|
5
|
+
const node_fetch_1 = require("node-fetch");
|
|
6
|
+
const openapi_core_1 = require("@redocly/openapi-core");
|
|
7
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
8
|
+
jest.mock('node-fetch');
|
|
9
|
+
jest.mock('@redocly/openapi-core');
|
|
10
|
+
describe('fetchWithTimeout', () => {
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
global.setTimeout = jest.fn();
|
|
14
|
+
global.clearTimeout = jest.fn();
|
|
15
|
+
});
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
openapi_core_1.getProxyAgent.mockReturnValueOnce(undefined);
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
jest.clearAllMocks();
|
|
21
|
+
});
|
|
22
|
+
it('should call node-fetch with signal', async () => {
|
|
23
|
+
await (0, fetch_with_timeout_1.default)('url', { timeout: 1000 });
|
|
24
|
+
expect(global.setTimeout).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect(node_fetch_1.default).toHaveBeenCalledWith('url', {
|
|
26
|
+
signal: new abort_controller_1.default().signal,
|
|
27
|
+
agent: undefined,
|
|
28
|
+
});
|
|
29
|
+
expect(global.clearTimeout).toHaveBeenCalledTimes(1);
|
|
30
|
+
});
|
|
31
|
+
it('should call node-fetch with proxy agent', async () => {
|
|
32
|
+
openapi_core_1.getProxyAgent.mockRestore();
|
|
33
|
+
const proxyAgent = new https_proxy_agent_1.HttpsProxyAgent('http://localhost');
|
|
34
|
+
openapi_core_1.getProxyAgent.mockReturnValueOnce(proxyAgent);
|
|
35
|
+
await (0, fetch_with_timeout_1.default)('url');
|
|
36
|
+
expect(node_fetch_1.default).toHaveBeenCalledWith('url', { agent: proxyAgent });
|
|
37
|
+
});
|
|
38
|
+
it('should call node-fetch without signal when timeout is not passed', async () => {
|
|
39
|
+
await (0, fetch_with_timeout_1.default)('url');
|
|
40
|
+
expect(global.setTimeout).not.toHaveBeenCalled();
|
|
41
|
+
expect(node_fetch_1.default).toHaveBeenCalledWith('url', { agent: undefined });
|
|
42
|
+
expect(global.clearTimeout).not.toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const ConfigFixture: {
|
|
2
|
+
configFile: null;
|
|
3
|
+
styleguide: {
|
|
4
|
+
addIgnore: jest.Mock<any, any>;
|
|
5
|
+
skipRules: jest.Mock<any, any>;
|
|
6
|
+
skipPreprocessors: jest.Mock<any, any>;
|
|
7
|
+
saveIgnore: jest.Mock<any, any>;
|
|
8
|
+
skipDecorators: jest.Mock<any, any>;
|
|
9
|
+
ignore: null;
|
|
10
|
+
decorators: {
|
|
11
|
+
oas2: {};
|
|
12
|
+
oas3_0: {};
|
|
13
|
+
oas3_1: {};
|
|
14
|
+
};
|
|
15
|
+
preprocessors: {
|
|
16
|
+
oas2: {};
|
|
17
|
+
oas3_0: {};
|
|
18
|
+
oas3_1: {};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigFixture = void 0;
|
|
4
|
+
exports.ConfigFixture = {
|
|
5
|
+
configFile: null,
|
|
6
|
+
styleguide: {
|
|
7
|
+
addIgnore: jest.fn(),
|
|
8
|
+
skipRules: jest.fn(),
|
|
9
|
+
skipPreprocessors: jest.fn(),
|
|
10
|
+
saveIgnore: jest.fn(),
|
|
11
|
+
skipDecorators: jest.fn(),
|
|
12
|
+
ignore: null,
|
|
13
|
+
decorators: {
|
|
14
|
+
oas2: {},
|
|
15
|
+
oas3_0: {},
|
|
16
|
+
oas3_1: {},
|
|
17
|
+
},
|
|
18
|
+
preprocessors: {
|
|
19
|
+
oas2: {},
|
|
20
|
+
oas3_0: {},
|
|
21
|
+
oas3_1: {},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|