@redocly/cli 1.18.1 → 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.
Files changed (91) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
  3. package/lib/__mocks__/@redocly/openapi-core.js +1 -0
  4. package/lib/__mocks__/fs.d.ts +0 -1
  5. package/lib/__mocks__/perf_hooks.d.ts +0 -1
  6. package/lib/__mocks__/redoc.d.ts +0 -1
  7. package/lib/__tests__/commands/build-docs.test.js +21 -23
  8. package/lib/__tests__/commands/bundle.test.js +21 -30
  9. package/lib/__tests__/commands/join.test.js +101 -70
  10. package/lib/__tests__/commands/lint.test.js +54 -54
  11. package/lib/__tests__/commands/push-region.test.js +24 -25
  12. package/lib/__tests__/commands/push.test.js +269 -170
  13. package/lib/__tests__/fetch-with-timeout.test.js +3 -12
  14. package/lib/__tests__/fixtures/config.d.ts +0 -1
  15. package/lib/__tests__/utils.test.js +32 -37
  16. package/lib/__tests__/wrapper.test.js +31 -20
  17. package/lib/cms/api/__tests__/api.client.test.js +29 -38
  18. package/lib/cms/api/api-client.d.ts +0 -2
  19. package/lib/cms/api/api-client.js +106 -127
  20. package/lib/cms/api/api-keys.js +1 -2
  21. package/lib/cms/api/domains.js +1 -2
  22. package/lib/cms/commands/__tests__/push-status.test.js +251 -162
  23. package/lib/cms/commands/__tests__/push.test.js +120 -102
  24. package/lib/cms/commands/__tests__/utils.test.js +12 -21
  25. package/lib/cms/commands/push-status.d.ts +3 -2
  26. package/lib/cms/commands/push-status.js +94 -106
  27. package/lib/cms/commands/push.d.ts +3 -2
  28. package/lib/cms/commands/push.js +66 -74
  29. package/lib/cms/commands/utils.js +20 -34
  30. package/lib/commands/build-docs/index.d.ts +2 -2
  31. package/lib/commands/build-docs/index.js +8 -17
  32. package/lib/commands/build-docs/utils.js +26 -38
  33. package/lib/commands/bundle.d.ts +2 -2
  34. package/lib/commands/bundle.js +70 -94
  35. package/lib/commands/join.d.ts +2 -2
  36. package/lib/commands/join.js +375 -388
  37. package/lib/commands/lint.d.ts +2 -2
  38. package/lib/commands/lint.js +64 -75
  39. package/lib/commands/login.d.ts +3 -2
  40. package/lib/commands/login.js +9 -21
  41. package/lib/commands/preview-docs/index.d.ts +2 -2
  42. package/lib/commands/preview-docs/index.js +92 -106
  43. package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
  44. package/lib/commands/preview-docs/preview-server/server.d.ts +0 -3
  45. package/lib/commands/preview-docs/preview-server/server.js +6 -6
  46. package/lib/commands/preview-project/index.d.ts +2 -1
  47. package/lib/commands/preview-project/index.js +5 -14
  48. package/lib/commands/push.d.ts +8 -11
  49. package/lib/commands/push.js +177 -195
  50. package/lib/commands/split/__tests__/index.test.js +31 -25
  51. package/lib/commands/split/index.d.ts +2 -1
  52. package/lib/commands/split/index.js +20 -33
  53. package/lib/commands/stats.d.ts +2 -2
  54. package/lib/commands/stats.js +34 -45
  55. package/lib/index.js +32 -46
  56. package/lib/types.d.ts +2 -2
  57. package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
  58. package/lib/utils/fetch-with-timeout.js +7 -12
  59. package/lib/utils/getCommandNameFromArgs.js +2 -4
  60. package/lib/utils/js-utils.js +6 -7
  61. package/lib/utils/miscellaneous.d.ts +4 -1
  62. package/lib/utils/miscellaneous.js +130 -152
  63. package/lib/utils/update-version-notifier.js +4 -13
  64. package/lib/wrapper.d.ts +9 -2
  65. package/lib/wrapper.js +27 -16
  66. package/package.json +3 -3
  67. package/src/__mocks__/@redocly/openapi-core.ts +1 -0
  68. package/src/__tests__/commands/build-docs.test.ts +5 -4
  69. package/src/__tests__/commands/join.test.ts +51 -51
  70. package/src/__tests__/commands/push-region.test.ts +10 -8
  71. package/src/__tests__/commands/push.test.ts +127 -102
  72. package/src/__tests__/utils.test.ts +1 -0
  73. package/src/__tests__/wrapper.test.ts +24 -2
  74. package/src/cms/commands/__tests__/push-status.test.ts +70 -56
  75. package/src/cms/commands/__tests__/push.test.ts +30 -24
  76. package/src/cms/commands/push-status.ts +8 -7
  77. package/src/cms/commands/push.ts +12 -9
  78. package/src/commands/build-docs/index.ts +10 -5
  79. package/src/commands/bundle.ts +14 -6
  80. package/src/commands/join.ts +6 -2
  81. package/src/commands/lint.ts +9 -3
  82. package/src/commands/login.ts +4 -2
  83. package/src/commands/preview-docs/index.ts +6 -1
  84. package/src/commands/preview-project/index.ts +5 -4
  85. package/src/commands/push.ts +13 -15
  86. package/src/commands/split/__tests__/index.test.ts +17 -6
  87. package/src/commands/split/index.ts +4 -2
  88. package/src/commands/stats.ts +4 -2
  89. package/src/utils/miscellaneous.ts +11 -1
  90. package/src/wrapper.ts +37 -11
  91. 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 miscellaneous_1 = require("../utils/miscellaneous");
13
4
  const openapi_core_1 = require("@redocly/openapi-core");
@@ -56,9 +47,9 @@ describe('pathToFilename', () => {
56
47
  });
57
48
  });
58
49
  describe('getFallbackApisOrExit', () => {
59
- it('should find alias by filename', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ it('should find alias by filename', async () => {
60
51
  fs_1.existsSync.mockImplementationOnce(() => true);
61
- const entry = yield (0, miscellaneous_1.getFallbackApisOrExit)(['./test.yaml'], {
52
+ const entry = await (0, miscellaneous_1.getFallbackApisOrExit)(['./test.yaml'], {
62
53
  apis: {
63
54
  main: {
64
55
  root: 'test.yaml',
@@ -66,7 +57,7 @@ describe('getFallbackApisOrExit', () => {
66
57
  },
67
58
  });
68
59
  expect(entry).toEqual([{ path: './test.yaml', alias: 'main' }]);
69
- }));
60
+ });
70
61
  });
71
62
  describe('printConfigLintTotals', () => {
72
63
  const totalProblemsMock = {
@@ -87,12 +78,12 @@ describe('printConfigLintTotals', () => {
87
78
  expect(redColoretteMocks).toHaveBeenCalledWith('❌ Your config has 1 error.');
88
79
  });
89
80
  it('should print warnign if no error', () => {
90
- (0, miscellaneous_1.printConfigLintTotals)(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0, warnings: 2 }));
81
+ (0, miscellaneous_1.printConfigLintTotals)({ ...totalProblemsMock, errors: 0, warnings: 2 });
91
82
  expect(process.stderr.write).toHaveBeenCalledWith('⚠️ Your config has 2 warnings.\n');
92
83
  expect(yellowColoretteMocks).toHaveBeenCalledWith('⚠️ Your config has 2 warnings.\n');
93
84
  });
94
85
  it('should print nothing if no error and no warnings', () => {
95
- const result = (0, miscellaneous_1.printConfigLintTotals)(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0 }));
86
+ const result = (0, miscellaneous_1.printConfigLintTotals)({ ...totalProblemsMock, errors: 0 });
96
87
  expect(result).toBeUndefined();
97
88
  expect(process.stderr.write).toHaveBeenCalledTimes(0);
98
89
  expect(yellowColoretteMocks).toHaveBeenCalledTimes(0);
@@ -118,34 +109,34 @@ describe('getFallbackApisOrExit', () => {
118
109
  afterEach(() => {
119
110
  jest.clearAllMocks();
120
111
  });
121
- it('should exit with error because no path provided', () => __awaiter(void 0, void 0, void 0, function* () {
112
+ it('should exit with error because no path provided', async () => {
122
113
  const apisConfig = {
123
114
  apis: {},
124
115
  };
125
116
  expect.assertions(1);
126
117
  try {
127
- yield (0, miscellaneous_1.getFallbackApisOrExit)([''], apisConfig);
118
+ await (0, miscellaneous_1.getFallbackApisOrExit)([''], apisConfig);
128
119
  }
129
120
  catch (e) {
130
121
  expect(e.message).toEqual('Path cannot be empty.');
131
122
  }
132
- }));
133
- it('should error if file from config do not exist', () => __awaiter(void 0, void 0, void 0, function* () {
123
+ });
124
+ it('should error if file from config do not exist', async () => {
134
125
  fs_1.existsSync.mockImplementationOnce(() => false);
135
126
  expect.assertions(3);
136
127
  try {
137
- yield (0, miscellaneous_1.getFallbackApisOrExit)(undefined, config);
128
+ await (0, miscellaneous_1.getFallbackApisOrExit)(undefined, config);
138
129
  }
139
130
  catch (e) {
140
131
  expect(process.stderr.write).toHaveBeenCalledWith('\nsomeFile.yaml does not exist or is invalid.\n\n');
141
132
  expect(process.stderr.write).toHaveBeenCalledWith('Please provide a valid path.\n\n');
142
133
  expect(e.message).toEqual('Please provide a valid path.');
143
134
  }
144
- }));
145
- it('should return valid array with results if such file exist', () => __awaiter(void 0, void 0, void 0, function* () {
135
+ });
136
+ it('should return valid array with results if such file exist', async () => {
146
137
  fs_1.existsSync.mockImplementationOnce(() => true);
147
138
  jest.spyOn(path, 'resolve').mockImplementationOnce((_, path) => path);
148
- const result = yield (0, miscellaneous_1.getFallbackApisOrExit)(undefined, config);
139
+ const result = await (0, miscellaneous_1.getFallbackApisOrExit)(undefined, config);
149
140
  expect(process.stderr.write).toHaveBeenCalledTimes(0);
150
141
  expect(process.exit).toHaveBeenCalledTimes(0);
151
142
  expect(result).toStrictEqual([
@@ -154,47 +145,50 @@ describe('getFallbackApisOrExit', () => {
154
145
  path: 'someFile.yaml',
155
146
  },
156
147
  ]);
157
- }));
158
- it('should exit with error in case if invalid path provided as args', () => __awaiter(void 0, void 0, void 0, function* () {
148
+ });
149
+ it('should exit with error in case if invalid path provided as args', async () => {
159
150
  const apisConfig = {
160
151
  apis: {},
161
152
  };
162
153
  fs_1.existsSync.mockImplementationOnce(() => false);
163
154
  expect.assertions(3);
164
155
  try {
165
- yield (0, miscellaneous_1.getFallbackApisOrExit)(['someFile.yaml'], apisConfig);
156
+ await (0, miscellaneous_1.getFallbackApisOrExit)(['someFile.yaml'], apisConfig);
166
157
  }
167
158
  catch (e) {
168
159
  expect(process.stderr.write).toHaveBeenCalledWith('\nsomeFile.yaml does not exist or is invalid.\n\n');
169
160
  expect(process.stderr.write).toHaveBeenCalledWith('Please provide a valid path.\n\n');
170
161
  expect(e.message).toEqual('Please provide a valid path.');
171
162
  }
172
- }));
173
- it('should exit with error in case if invalid 2 path provided as args', () => __awaiter(void 0, void 0, void 0, function* () {
163
+ });
164
+ it('should exit with error in case if invalid 2 path provided as args', async () => {
174
165
  const apisConfig = {
175
166
  apis: {},
176
167
  };
177
168
  fs_1.existsSync.mockImplementationOnce(() => false);
178
169
  expect.assertions(3);
179
170
  try {
180
- yield (0, miscellaneous_1.getFallbackApisOrExit)(['someFile.yaml', 'someFile2.yaml'], apisConfig);
171
+ await (0, miscellaneous_1.getFallbackApisOrExit)(['someFile.yaml', 'someFile2.yaml'], apisConfig);
181
172
  }
182
173
  catch (e) {
183
174
  expect(process.stderr.write).toHaveBeenCalledWith('\nsomeFile.yaml does not exist or is invalid.\n\n');
184
175
  expect(process.stderr.write).toHaveBeenCalledWith('Please provide a valid path.\n\n');
185
176
  expect(e.message).toEqual('Please provide a valid path.');
186
177
  }
187
- }));
188
- it('should exit with error if only one file exist ', () => __awaiter(void 0, void 0, void 0, function* () {
189
- const apisStub = Object.assign(Object.assign({}, apis), { notExist: {
178
+ });
179
+ it('should exit with error if only one file exist ', async () => {
180
+ const apisStub = {
181
+ ...apis,
182
+ notExist: {
190
183
  root: 'notExist.yaml',
191
184
  styleguide: {},
192
- } });
185
+ },
186
+ };
193
187
  const configStub = { apis: apisStub };
194
188
  const existSyncMock = fs_1.existsSync.mockImplementation((path) => path.endsWith('someFile.yaml'));
195
189
  expect.assertions(4);
196
190
  try {
197
- yield (0, miscellaneous_1.getFallbackApisOrExit)(undefined, configStub);
191
+ await (0, miscellaneous_1.getFallbackApisOrExit)(undefined, configStub);
198
192
  }
199
193
  catch (e) {
200
194
  expect(process.stderr.write).toHaveBeenCalledWith('\nnotExist.yaml does not exist or is invalid.\n\n');
@@ -203,8 +197,8 @@ describe('getFallbackApisOrExit', () => {
203
197
  expect(e.message).toEqual('Please provide a valid path.');
204
198
  }
205
199
  existSyncMock.mockClear();
206
- }));
207
- it('should work ok if it is url passed', () => __awaiter(void 0, void 0, void 0, function* () {
200
+ });
201
+ it('should work ok if it is url passed', async () => {
208
202
  fs_1.existsSync.mockImplementationOnce(() => false);
209
203
  openapi_core_1.isAbsoluteUrl.mockImplementation(() => true);
210
204
  const apisConfig = {
@@ -215,7 +209,7 @@ describe('getFallbackApisOrExit', () => {
215
209
  },
216
210
  },
217
211
  };
218
- const result = yield (0, miscellaneous_1.getFallbackApisOrExit)(undefined, apisConfig);
212
+ const result = await (0, miscellaneous_1.getFallbackApisOrExit)(undefined, apisConfig);
219
213
  expect(process.stderr.write).toHaveBeenCalledTimes(0);
220
214
  expect(result).toStrictEqual([
221
215
  {
@@ -223,7 +217,7 @@ describe('getFallbackApisOrExit', () => {
223
217
  path: 'https://someLinkt/petstore.yaml?main',
224
218
  },
225
219
  ]);
226
- }));
220
+ });
227
221
  });
228
222
  describe('langToExt', () => {
229
223
  it.each([
@@ -390,6 +384,7 @@ describe('checkIfRulesetExist', () => {
390
384
  oas3_0: {},
391
385
  oas3_1: {},
392
386
  async2: {},
387
+ async3: {},
393
388
  arazzo: {},
394
389
  };
395
390
  expect(() => (0, miscellaneous_1.checkIfRulesetExist)(rules)).toThrowError('⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/');
@@ -1,57 +1,68 @@
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 miscellaneous_1 = require("../utils/miscellaneous");
13
4
  const process = require("process");
14
5
  const wrapper_1 = require("../wrapper");
15
6
  const lint_1 = require("../commands/lint");
16
7
  const push_1 = require("../commands/push");
8
+ const openapi_core_1 = require("@redocly/openapi-core");
17
9
  jest.mock('node-fetch');
18
10
  jest.mock('../utils/miscellaneous', () => ({
19
11
  sendTelemetry: jest.fn(),
20
12
  loadConfigAndHandleErrors: jest.fn(),
21
13
  }));
22
14
  jest.mock('../commands/lint', () => ({
23
- handleLint: jest.fn(),
15
+ handleLint: jest.fn().mockImplementation(({ collectSpecData }) => {
16
+ collectSpecData({ openapi: '3.1.0' });
17
+ }),
24
18
  lintConfigCallback: jest.fn(),
25
19
  }));
26
20
  describe('commandWrapper', () => {
27
- it('should send telemetry if there is "telemetry: on" in the config', () => __awaiter(void 0, void 0, void 0, function* () {
21
+ it('should send telemetry if there is "telemetry: on" in the config', async () => {
22
+ miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
23
+ return { telemetry: 'on', styleguide: { recommendedFallback: true } };
24
+ });
25
+ openapi_core_1.detectSpec.mockImplementationOnce(() => {
26
+ return 'oas3_1';
27
+ });
28
+ process.env.REDOCLY_TELEMETRY = 'on';
29
+ const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
30
+ await wrappedHandler({});
31
+ expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
32
+ expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledTimes(1);
33
+ expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledWith({}, 0, false, 'oas3_1', 'openapi', '3.1.0');
34
+ });
35
+ it('should not collect spec version if the file is not parsed to json', async () => {
28
36
  miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
29
37
  return { telemetry: 'on', styleguide: { recommendedFallback: true } };
30
38
  });
39
+ lint_1.handleLint.mockImplementation(({ collectSpecData }) => {
40
+ collectSpecData();
41
+ });
31
42
  process.env.REDOCLY_TELEMETRY = 'on';
32
43
  const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
33
- yield wrappedHandler({});
44
+ await wrappedHandler({});
34
45
  expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
35
46
  expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledTimes(1);
36
- expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledWith({}, 0, false);
37
- }));
38
- it('should NOT send telemetry if there is "telemetry: off" in the config', () => __awaiter(void 0, void 0, void 0, function* () {
47
+ expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledWith({}, 0, false, undefined, undefined, undefined);
48
+ });
49
+ it('should NOT send telemetry if there is "telemetry: off" in the config', async () => {
39
50
  miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
40
51
  return { telemetry: 'off', styleguide: { recommendedFallback: true } };
41
52
  });
42
53
  process.env.REDOCLY_TELEMETRY = 'on';
43
54
  const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
44
- yield wrappedHandler({});
55
+ await wrappedHandler({});
45
56
  expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
46
57
  expect(miscellaneous_1.sendTelemetry).toHaveBeenCalledTimes(0);
47
- }));
48
- it('should pass files from arguments to config', () => __awaiter(void 0, void 0, void 0, function* () {
58
+ });
59
+ it('should pass files from arguments to config', async () => {
49
60
  const filesToPush = ['test1.yaml', 'test2.yaml'];
50
61
  const loadConfigMock = miscellaneous_1.loadConfigAndHandleErrors;
51
62
  const argv = {
52
63
  files: filesToPush,
53
64
  };
54
- yield (0, wrapper_1.commandWrapper)(push_1.handlePush)(argv);
65
+ await (0, wrapper_1.commandWrapper)(push_1.handlePush)(argv);
55
66
  expect(loadConfigMock).toHaveBeenCalledWith(expect.objectContaining({ files: filesToPush }));
56
- }));
67
+ });
57
68
  });
@@ -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 node_fetch_1 = require("node-fetch");
13
4
  const FormData = require("form-data");
@@ -28,14 +19,14 @@ describe('ApiClient', () => {
28
19
  beforeEach(() => {
29
20
  apiClient = new api_client_1.ReuniteApiClient(testDomain, testToken);
30
21
  });
31
- it('should get default project branch', () => __awaiter(void 0, void 0, void 0, function* () {
22
+ it('should get default project branch', async () => {
32
23
  mockFetchResponse({
33
24
  ok: true,
34
25
  json: jest.fn().mockResolvedValue({
35
26
  branchName: 'test-branch',
36
27
  }),
37
28
  });
38
- const result = yield apiClient.remotes.getDefaultBranch(testOrg, testProject);
29
+ const result = await apiClient.remotes.getDefaultBranch(testOrg, testProject);
39
30
  expect(node_fetch_1.default).toHaveBeenCalledWith(`${testDomain}/api/orgs/${testOrg}/projects/${testProject}/source`, {
40
31
  method: 'GET',
41
32
  headers: {
@@ -45,8 +36,8 @@ describe('ApiClient', () => {
45
36
  signal: expect.any(Object),
46
37
  });
47
38
  expect(result).toEqual('test-branch');
48
- }));
49
- it('should throw parsed error if response is not ok', () => __awaiter(void 0, void 0, void 0, function* () {
39
+ });
40
+ it('should throw parsed error if response is not ok', async () => {
50
41
  mockFetchResponse({
51
42
  ok: false,
52
43
  json: jest.fn().mockResolvedValue({
@@ -57,9 +48,9 @@ describe('ApiClient', () => {
57
48
  object: 'problem',
58
49
  }),
59
50
  });
60
- yield expect(apiClient.remotes.getDefaultBranch(testOrg, testProject)).rejects.toThrow(new Error('Failed to fetch default branch: Project source not found'));
61
- }));
62
- it('should throw statusText error if response is not ok', () => __awaiter(void 0, void 0, void 0, function* () {
51
+ await expect(apiClient.remotes.getDefaultBranch(testOrg, testProject)).rejects.toThrow(new Error('Failed to fetch default branch: Project source not found'));
52
+ });
53
+ it('should throw statusText error if response is not ok', async () => {
63
54
  mockFetchResponse({
64
55
  ok: false,
65
56
  statusText: 'Not found',
@@ -67,8 +58,8 @@ describe('ApiClient', () => {
67
58
  unknownField: 'unknown-error',
68
59
  }),
69
60
  });
70
- yield expect(apiClient.remotes.getDefaultBranch(testOrg, testProject)).rejects.toThrow(new Error('Failed to fetch default branch: Not found'));
71
- }));
61
+ await expect(apiClient.remotes.getDefaultBranch(testOrg, testProject)).rejects.toThrow(new Error('Failed to fetch default branch: Not found'));
62
+ });
72
63
  });
73
64
  describe('upsert()', () => {
74
65
  const remotePayload = {
@@ -79,7 +70,7 @@ describe('ApiClient', () => {
79
70
  beforeEach(() => {
80
71
  apiClient = new api_client_1.ReuniteApiClient(testDomain, testToken);
81
72
  });
82
- it('should upsert remote', () => __awaiter(void 0, void 0, void 0, function* () {
73
+ it('should upsert remote', async () => {
83
74
  const responseMock = {
84
75
  id: 'remote-id',
85
76
  type: 'CICD',
@@ -92,7 +83,7 @@ describe('ApiClient', () => {
92
83
  ok: true,
93
84
  json: jest.fn().mockResolvedValue(responseMock),
94
85
  });
95
- const result = yield apiClient.remotes.upsert(testOrg, testProject, remotePayload);
86
+ const result = await apiClient.remotes.upsert(testOrg, testProject, remotePayload);
96
87
  expect(node_fetch_1.default).toHaveBeenCalledWith(`${testDomain}/api/orgs/${testOrg}/projects/${testProject}/remotes`, {
97
88
  method: 'POST',
98
89
  headers: {
@@ -109,8 +100,8 @@ describe('ApiClient', () => {
109
100
  agent: undefined,
110
101
  });
111
102
  expect(result).toEqual(responseMock);
112
- }));
113
- it('should throw parsed error if response is not ok', () => __awaiter(void 0, void 0, void 0, function* () {
103
+ });
104
+ it('should throw parsed error if response is not ok', async () => {
114
105
  mockFetchResponse({
115
106
  ok: false,
116
107
  json: jest.fn().mockResolvedValue({
@@ -121,9 +112,9 @@ describe('ApiClient', () => {
121
112
  object: 'problem',
122
113
  }),
123
114
  });
124
- yield expect(apiClient.remotes.upsert(testOrg, testProject, remotePayload)).rejects.toThrow(new Error('Failed to upsert remote: Not allowed to mount remote outside of project content path: /docs'));
125
- }));
126
- it('should throw statusText error if response is not ok', () => __awaiter(void 0, void 0, void 0, function* () {
115
+ await expect(apiClient.remotes.upsert(testOrg, testProject, remotePayload)).rejects.toThrow(new Error('Failed to upsert remote: Not allowed to mount remote outside of project content path: /docs'));
116
+ });
117
+ it('should throw statusText error if response is not ok', async () => {
127
118
  mockFetchResponse({
128
119
  ok: false,
129
120
  statusText: 'Not found',
@@ -131,8 +122,8 @@ describe('ApiClient', () => {
131
122
  unknownField: 'unknown-error',
132
123
  }),
133
124
  });
134
- yield expect(apiClient.remotes.upsert(testOrg, testProject, remotePayload)).rejects.toThrow(new Error('Failed to upsert remote: Not found'));
135
- }));
125
+ await expect(apiClient.remotes.upsert(testOrg, testProject, remotePayload)).rejects.toThrow(new Error('Failed to upsert remote: Not found'));
126
+ });
136
127
  });
137
128
  describe('push()', () => {
138
129
  const testRemoteId = 'test-remote-id';
@@ -167,15 +158,15 @@ describe('ApiClient', () => {
167
158
  beforeEach(() => {
168
159
  apiClient = new api_client_1.ReuniteApiClient(testDomain, testToken);
169
160
  });
170
- it('should push to remote', () => __awaiter(void 0, void 0, void 0, function* () {
161
+ it('should push to remote', async () => {
171
162
  let passedFormData = new FormData();
172
- node_fetch_1.default.mockImplementationOnce((_, options) => __awaiter(void 0, void 0, void 0, function* () {
163
+ node_fetch_1.default.mockImplementationOnce(async (_, options) => {
173
164
  passedFormData = options.body;
174
165
  return {
175
166
  ok: true,
176
167
  json: jest.fn().mockResolvedValue(responseMock),
177
168
  };
178
- }));
169
+ });
179
170
  const formData = new FormData();
180
171
  formData.append('remoteId', testRemoteId);
181
172
  formData.append('commit[message]', pushPayload.commit.message);
@@ -183,7 +174,7 @@ describe('ApiClient', () => {
183
174
  formData.append('commit[author][email]', pushPayload.commit.author.email);
184
175
  formData.append('commit[branchName]', pushPayload.commit.branchName);
185
176
  formData.append('files[some-file.yaml]', filesMock[0].stream);
186
- const result = yield apiClient.remotes.push(testOrg, testProject, pushPayload, filesMock);
177
+ const result = await apiClient.remotes.push(testOrg, testProject, pushPayload, filesMock);
187
178
  expect(node_fetch_1.default).toHaveBeenCalledWith(`${testDomain}/api/orgs/${testOrg}/projects/${testProject}/pushes`, expect.objectContaining({
188
179
  method: 'POST',
189
180
  headers: {
@@ -192,8 +183,8 @@ describe('ApiClient', () => {
192
183
  }));
193
184
  expect(JSON.stringify(passedFormData).replace(new RegExp(passedFormData.getBoundary(), 'g'), '')).toEqual(JSON.stringify(formData).replace(new RegExp(formData.getBoundary(), 'g'), ''));
194
185
  expect(result).toEqual(responseMock);
195
- }));
196
- it('should throw parsed error if response is not ok', () => __awaiter(void 0, void 0, void 0, function* () {
186
+ });
187
+ it('should throw parsed error if response is not ok', async () => {
197
188
  mockFetchResponse({
198
189
  ok: false,
199
190
  json: jest.fn().mockResolvedValue({
@@ -204,9 +195,9 @@ describe('ApiClient', () => {
204
195
  object: 'problem',
205
196
  }),
206
197
  });
207
- yield expect(apiClient.remotes.push(testOrg, testProject, pushPayload, filesMock)).rejects.toThrow(new Error('Failed to push: Cannot push to remote'));
208
- }));
209
- it('should throw statusText error if response is not ok', () => __awaiter(void 0, void 0, void 0, function* () {
198
+ await expect(apiClient.remotes.push(testOrg, testProject, pushPayload, filesMock)).rejects.toThrow(new Error('Failed to push: Cannot push to remote'));
199
+ });
200
+ it('should throw statusText error if response is not ok', async () => {
210
201
  mockFetchResponse({
211
202
  ok: false,
212
203
  statusText: 'Not found',
@@ -214,7 +205,7 @@ describe('ApiClient', () => {
214
205
  unknownField: 'unknown-error',
215
206
  }),
216
207
  });
217
- yield expect(apiClient.remotes.push(testOrg, testProject, pushPayload, filesMock)).rejects.toThrow(new Error('Failed to push: Not found'));
218
- }));
208
+ await expect(apiClient.remotes.push(testOrg, testProject, pushPayload, filesMock)).rejects.toThrow(new Error('Failed to push: Not found'));
209
+ });
219
210
  });
220
211
  });
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { ReadStream } from 'fs';
4
2
  import type { ListRemotesResponse, PushResponse, UpsertRemoteResponse } from './types';
5
3
  declare class RemotesApiClient {