@redocly/cli 1.18.0 → 1.19.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.
- package/CHANGELOG.md +22 -0
- package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
- package/lib/__mocks__/@redocly/openapi-core.js +1 -0
- package/lib/__mocks__/fs.d.ts +0 -1
- package/lib/__mocks__/perf_hooks.d.ts +0 -1
- package/lib/__mocks__/redoc.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +21 -23
- package/lib/__tests__/commands/bundle.test.js +21 -30
- package/lib/__tests__/commands/join.test.js +101 -70
- package/lib/__tests__/commands/lint.test.js +54 -54
- package/lib/__tests__/commands/push-region.test.js +24 -25
- package/lib/__tests__/commands/push.test.js +269 -170
- package/lib/__tests__/fetch-with-timeout.test.js +3 -12
- package/lib/__tests__/fixtures/config.d.ts +0 -1
- package/lib/__tests__/utils.test.js +32 -37
- package/lib/__tests__/wrapper.test.js +31 -20
- package/lib/cms/api/__tests__/api.client.test.js +29 -38
- package/lib/cms/api/api-client.d.ts +0 -2
- package/lib/cms/api/api-client.js +106 -127
- package/lib/cms/api/api-keys.js +1 -2
- package/lib/cms/api/domains.js +1 -2
- package/lib/cms/commands/__tests__/push-status.test.js +251 -162
- package/lib/cms/commands/__tests__/push.test.js +120 -102
- package/lib/cms/commands/__tests__/utils.test.js +12 -21
- package/lib/cms/commands/push-status.d.ts +3 -2
- package/lib/cms/commands/push-status.js +94 -106
- package/lib/cms/commands/push.d.ts +3 -2
- package/lib/cms/commands/push.js +66 -75
- package/lib/cms/commands/utils.js +20 -34
- package/lib/commands/build-docs/index.d.ts +2 -2
- package/lib/commands/build-docs/index.js +8 -17
- package/lib/commands/build-docs/utils.js +26 -38
- package/lib/commands/bundle.d.ts +2 -2
- package/lib/commands/bundle.js +70 -94
- package/lib/commands/join.d.ts +2 -2
- package/lib/commands/join.js +377 -390
- package/lib/commands/lint.d.ts +2 -2
- package/lib/commands/lint.js +70 -78
- package/lib/commands/login.d.ts +3 -2
- package/lib/commands/login.js +9 -21
- package/lib/commands/preview-docs/index.d.ts +2 -2
- package/lib/commands/preview-docs/index.js +92 -106
- package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
- package/lib/commands/preview-docs/preview-server/server.d.ts +0 -3
- package/lib/commands/preview-docs/preview-server/server.js +6 -6
- package/lib/commands/preview-project/index.d.ts +2 -1
- package/lib/commands/preview-project/index.js +5 -14
- package/lib/commands/push.d.ts +8 -11
- package/lib/commands/push.js +177 -195
- package/lib/commands/split/__tests__/index.test.js +31 -25
- package/lib/commands/split/index.d.ts +2 -1
- package/lib/commands/split/index.js +22 -35
- package/lib/commands/stats.d.ts +2 -2
- package/lib/commands/stats.js +34 -45
- package/lib/index.js +32 -46
- package/lib/types.d.ts +2 -2
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
- package/lib/utils/fetch-with-timeout.js +7 -12
- package/lib/utils/getCommandNameFromArgs.js +2 -4
- package/lib/utils/js-utils.js +6 -7
- package/lib/utils/miscellaneous.d.ts +9 -5
- package/lib/utils/miscellaneous.js +150 -160
- package/lib/utils/update-version-notifier.js +4 -13
- package/lib/wrapper.d.ts +9 -2
- package/lib/wrapper.js +27 -16
- package/package.json +5 -3
- package/src/__mocks__/@redocly/openapi-core.ts +1 -0
- package/src/__tests__/commands/build-docs.test.ts +5 -4
- package/src/__tests__/commands/join.test.ts +51 -51
- package/src/__tests__/commands/push-region.test.ts +10 -8
- package/src/__tests__/commands/push.test.ts +127 -102
- package/src/__tests__/utils.test.ts +1 -0
- package/src/__tests__/wrapper.test.ts +24 -2
- package/src/cms/commands/__tests__/push-status.test.ts +70 -56
- package/src/cms/commands/__tests__/push.test.ts +30 -24
- package/src/cms/commands/push-status.ts +8 -7
- package/src/cms/commands/push.ts +19 -13
- package/src/commands/build-docs/index.ts +10 -5
- package/src/commands/bundle.ts +14 -6
- package/src/commands/join.ts +10 -6
- package/src/commands/lint.ts +20 -9
- package/src/commands/login.ts +4 -2
- package/src/commands/preview-docs/index.ts +6 -1
- package/src/commands/preview-project/index.ts +5 -4
- package/src/commands/push.ts +14 -16
- package/src/commands/split/__tests__/index.test.ts +17 -6
- package/src/commands/split/index.ts +6 -4
- package/src/commands/stats.ts +4 -2
- package/src/utils/miscellaneous.ts +55 -26
- package/src/wrapper.ts +37 -11
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
13
4
|
const push_1 = require("../../commands/push");
|
|
@@ -31,26 +22,34 @@ describe('push-with-region', () => {
|
|
|
31
22
|
beforeAll(() => {
|
|
32
23
|
jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
|
|
33
24
|
});
|
|
34
|
-
it('should call login with default domain when region is US', () =>
|
|
25
|
+
it('should call login with default domain when region is US', async () => {
|
|
35
26
|
redoclyClient.domain = 'redoc.ly';
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
});
|
|
42
37
|
expect(mockPromptClientToken).toBeCalledTimes(1);
|
|
43
38
|
expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
|
|
44
|
-
})
|
|
45
|
-
it('should call login with EU domain when region is EU', () =>
|
|
39
|
+
});
|
|
40
|
+
it('should call login with EU domain when region is EU', async () => {
|
|
46
41
|
redoclyClient.domain = 'eu.redocly.com';
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
});
|
|
53
52
|
expect(mockPromptClientToken).toBeCalledTimes(1);
|
|
54
53
|
expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
|
|
55
|
-
})
|
|
54
|
+
});
|
|
56
55
|
});
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const fs = require("fs");
|
|
13
4
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
@@ -30,16 +21,20 @@ describe('push', () => {
|
|
|
30
21
|
beforeEach(() => {
|
|
31
22
|
jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
|
|
32
23
|
});
|
|
33
|
-
it('pushes definition', () =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
});
|
|
43
38
|
expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(1);
|
|
44
39
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
45
40
|
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
@@ -54,43 +49,55 @@ describe('push', () => {
|
|
|
54
49
|
batchId: '123',
|
|
55
50
|
batchSize: 2,
|
|
56
51
|
});
|
|
57
|
-
})
|
|
58
|
-
it('fails if jobId value is an empty string', () =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
});
|
|
68
67
|
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
69
|
-
})
|
|
70
|
-
it('fails if batchSize value is less than 2', () =>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
});
|
|
80
83
|
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
81
|
-
})
|
|
82
|
-
it('push with --files', () =>
|
|
83
|
-
const mockConfig =
|
|
84
|
+
});
|
|
85
|
+
it('push with --files', async () => {
|
|
86
|
+
const mockConfig = { ...config_1.ConfigFixture, files: ['./resouces/1.md', './resouces/2.md'] };
|
|
84
87
|
fs.statSync.mockImplementation(() => {
|
|
85
88
|
return { isDirectory: () => false, size: 10 };
|
|
86
89
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
+
});
|
|
94
101
|
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
95
102
|
filePaths: ['filePath', 'filePath', 'filePath'],
|
|
96
103
|
isUpsert: true,
|
|
@@ -101,31 +108,39 @@ describe('push', () => {
|
|
|
101
108
|
version: '1.0.0',
|
|
102
109
|
});
|
|
103
110
|
expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(3);
|
|
104
|
-
})
|
|
105
|
-
it('push should fail if organization not provided', () =>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
+
});
|
|
115
126
|
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
116
127
|
expect(miscellaneous_1.exitWithError).toBeCalledWith(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
|
|
117
|
-
})
|
|
118
|
-
it('push should work with organization in config', () =>
|
|
119
|
-
const mockConfig =
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
});
|
|
129
144
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
130
145
|
expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
|
|
131
146
|
branch: 'test',
|
|
@@ -139,153 +154,237 @@ describe('push', () => {
|
|
|
139
154
|
batchId: '123',
|
|
140
155
|
batchSize: 2,
|
|
141
156
|
});
|
|
142
|
-
})
|
|
143
|
-
it('push should work if destination not provided but api in config is provided', () =>
|
|
144
|
-
const mockConfig =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
+
});
|
|
152
175
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
153
|
-
})
|
|
154
|
-
it('push should fail if apis not provided', () =>
|
|
176
|
+
});
|
|
177
|
+
it('push should fail if apis not provided', async () => {
|
|
155
178
|
const mockConfig = { organization: 'test_org', apis: {} };
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
+
});
|
|
163
190
|
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
164
191
|
expect(miscellaneous_1.exitWithError).toHaveBeenLastCalledWith('Api not found. Please make sure you have provided the correct data in the config file.');
|
|
165
|
-
})
|
|
166
|
-
it('push should fail if destination not provided', () =>
|
|
192
|
+
});
|
|
193
|
+
it('push should fail if destination not provided', async () => {
|
|
167
194
|
const mockConfig = { organization: 'test_org', apis: {} };
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
+
});
|
|
176
207
|
expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
|
|
177
208
|
expect(miscellaneous_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', () =>
|
|
209
|
+
});
|
|
210
|
+
it('push should fail if destination format is not valid', async () => {
|
|
180
211
|
const mockConfig = { organization: 'test_org', apis: {} };
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
+
});
|
|
189
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>')}.`);
|
|
190
|
-
})
|
|
191
|
-
it('push should work and encode name with spaces', () =>
|
|
225
|
+
});
|
|
226
|
+
it('push should work and encode name with spaces', async () => {
|
|
192
227
|
const encodeURIComponentSpy = jest.spyOn(global, 'encodeURIComponent');
|
|
193
|
-
const mockConfig =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
+
});
|
|
202
245
|
expect(encodeURIComponentSpy).toHaveReturnedWith('my%20test%20api');
|
|
203
246
|
expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
|
|
204
|
-
})
|
|
247
|
+
});
|
|
205
248
|
});
|
|
206
249
|
describe('transformPush', () => {
|
|
207
250
|
it('should adapt the existing syntax', () => {
|
|
208
251
|
const cb = jest.fn();
|
|
209
252
|
(0, push_1.transformPush)(cb)({
|
|
210
|
-
|
|
211
|
-
|
|
253
|
+
argv: {
|
|
254
|
+
apis: ['openapi.yaml', '@testing_org/main@v1'],
|
|
255
|
+
},
|
|
256
|
+
config: {},
|
|
257
|
+
version: 'cli-version',
|
|
258
|
+
});
|
|
212
259
|
expect(cb).toBeCalledWith({
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
260
|
+
argv: {
|
|
261
|
+
api: 'openapi.yaml',
|
|
262
|
+
destination: '@testing_org/main@v1',
|
|
263
|
+
},
|
|
264
|
+
config: {},
|
|
265
|
+
version: 'cli-version',
|
|
266
|
+
});
|
|
216
267
|
});
|
|
217
268
|
it('should adapt the existing syntax (including branchName)', () => {
|
|
218
269
|
const cb = jest.fn();
|
|
219
270
|
(0, push_1.transformPush)(cb)({
|
|
220
|
-
|
|
221
|
-
|
|
271
|
+
argv: {
|
|
272
|
+
apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
|
|
273
|
+
},
|
|
274
|
+
config: {},
|
|
275
|
+
version: 'cli-version',
|
|
276
|
+
});
|
|
222
277
|
expect(cb).toBeCalledWith({
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
278
|
+
argv: {
|
|
279
|
+
api: 'openapi.yaml',
|
|
280
|
+
destination: '@testing_org/main@v1',
|
|
281
|
+
branchName: 'other',
|
|
282
|
+
},
|
|
283
|
+
config: {},
|
|
284
|
+
version: 'cli-version',
|
|
285
|
+
});
|
|
227
286
|
});
|
|
228
287
|
it('should use --branch option firstly', () => {
|
|
229
288
|
const cb = jest.fn();
|
|
230
289
|
(0, push_1.transformPush)(cb)({
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
290
|
+
argv: {
|
|
291
|
+
apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
|
|
292
|
+
branch: 'priority-branch',
|
|
293
|
+
},
|
|
294
|
+
config: {},
|
|
295
|
+
version: 'cli-version',
|
|
296
|
+
});
|
|
234
297
|
expect(cb).toBeCalledWith({
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
298
|
+
argv: {
|
|
299
|
+
api: 'openapi.yaml',
|
|
300
|
+
destination: '@testing_org/main@v1',
|
|
301
|
+
branchName: 'priority-branch',
|
|
302
|
+
},
|
|
303
|
+
config: {},
|
|
304
|
+
version: 'cli-version',
|
|
305
|
+
});
|
|
239
306
|
});
|
|
240
307
|
it('should work for a destination only', () => {
|
|
241
308
|
const cb = jest.fn();
|
|
242
309
|
(0, push_1.transformPush)(cb)({
|
|
243
|
-
|
|
244
|
-
|
|
310
|
+
argv: {
|
|
311
|
+
apis: ['main@v1'],
|
|
312
|
+
},
|
|
313
|
+
config: {},
|
|
314
|
+
version: 'cli-version',
|
|
315
|
+
});
|
|
245
316
|
expect(cb).toBeCalledWith({
|
|
246
|
-
|
|
247
|
-
|
|
317
|
+
argv: {
|
|
318
|
+
destination: 'main@v1',
|
|
319
|
+
},
|
|
320
|
+
config: {},
|
|
321
|
+
version: 'cli-version',
|
|
322
|
+
});
|
|
248
323
|
});
|
|
249
324
|
it('should work for a api only', () => {
|
|
250
325
|
const cb = jest.fn();
|
|
251
326
|
(0, push_1.transformPush)(cb)({
|
|
252
|
-
|
|
253
|
-
|
|
327
|
+
argv: {
|
|
328
|
+
apis: ['test.yaml'],
|
|
329
|
+
},
|
|
330
|
+
config: {},
|
|
331
|
+
version: 'cli-version',
|
|
332
|
+
});
|
|
254
333
|
expect(cb).toBeCalledWith({
|
|
255
|
-
|
|
256
|
-
|
|
334
|
+
argv: {
|
|
335
|
+
api: 'test.yaml',
|
|
336
|
+
},
|
|
337
|
+
config: {},
|
|
338
|
+
version: 'cli-version',
|
|
339
|
+
});
|
|
257
340
|
});
|
|
258
341
|
it('should use destination from option', () => {
|
|
259
342
|
const cb = jest.fn();
|
|
260
343
|
(0, push_1.transformPush)(cb)({
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
344
|
+
argv: {
|
|
345
|
+
apis: ['test.yaml', 'test@v1'],
|
|
346
|
+
destination: 'main@v1',
|
|
347
|
+
},
|
|
348
|
+
config: {},
|
|
349
|
+
version: 'cli-version',
|
|
350
|
+
});
|
|
264
351
|
expect(cb).toBeCalledWith({
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
352
|
+
argv: {
|
|
353
|
+
destination: 'main@v1',
|
|
354
|
+
api: 'test.yaml',
|
|
355
|
+
},
|
|
356
|
+
config: {},
|
|
357
|
+
version: 'cli-version',
|
|
358
|
+
});
|
|
268
359
|
});
|
|
269
360
|
it('should use --job-id option firstly', () => {
|
|
270
361
|
const cb = jest.fn();
|
|
271
362
|
(0, push_1.transformPush)(cb)({
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
+
});
|
|
278
373
|
expect(cb).toBeCalledWith({
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
+
});
|
|
284
383
|
});
|
|
285
384
|
it('should accept no arguments at all', () => {
|
|
286
385
|
const cb = jest.fn();
|
|
287
|
-
(0, push_1.transformPush)(cb)({}, {});
|
|
288
|
-
expect(cb).toBeCalledWith({}, {});
|
|
386
|
+
(0, push_1.transformPush)(cb)({ argv: {}, config: {}, version: 'cli-version' });
|
|
387
|
+
expect(cb).toBeCalledWith({ argv: {}, config: {}, version: 'cli-version' });
|
|
289
388
|
});
|
|
290
389
|
});
|
|
291
390
|
describe('getDestinationProps', () => {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const abort_controller_1 = require("abort-controller");
|
|
13
4
|
const fetch_with_timeout_1 = require("../utils/fetch-with-timeout");
|
|
@@ -17,13 +8,13 @@ describe('fetchWithTimeout', () => {
|
|
|
17
8
|
afterEach(() => {
|
|
18
9
|
jest.clearAllMocks();
|
|
19
10
|
});
|
|
20
|
-
it('should call node-fetch with signal', () =>
|
|
11
|
+
it('should call node-fetch with signal', async () => {
|
|
21
12
|
// @ts-ignore
|
|
22
13
|
global.setTimeout = jest.fn();
|
|
23
14
|
global.clearTimeout = jest.fn();
|
|
24
|
-
|
|
15
|
+
await (0, fetch_with_timeout_1.default)('url');
|
|
25
16
|
expect(global.setTimeout).toHaveBeenCalledTimes(1);
|
|
26
17
|
expect(node_fetch_1.default).toHaveBeenCalledWith('url', { signal: new abort_controller_1.default().signal });
|
|
27
18
|
expect(global.clearTimeout).toHaveBeenCalledTimes(1);
|
|
28
|
-
})
|
|
19
|
+
});
|
|
29
20
|
});
|