@redocly/cli 1.34.4 → 2.0.0-next.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/README.md +34 -3
- package/bin/cli.js +1 -1
- package/lib/auth/device-flow.d.ts +1 -0
- package/lib/auth/device-flow.d.ts.map +1 -0
- package/lib/auth/device-flow.js +15 -17
- package/lib/auth/device-flow.js.map +1 -0
- package/lib/auth/oauth-client.d.ts +1 -0
- package/lib/auth/oauth-client.d.ts.map +1 -0
- package/lib/auth/oauth-client.js +21 -23
- package/lib/auth/oauth-client.js.map +1 -0
- package/lib/commands/auth.d.ts +3 -5
- package/lib/commands/auth.d.ts.map +1 -0
- package/lib/commands/auth.js +19 -44
- package/lib/commands/auth.js.map +1 -0
- package/lib/commands/build-docs/index.d.ts +4 -3
- package/lib/commands/build-docs/index.d.ts.map +1 -0
- package/lib/commands/build-docs/index.js +23 -24
- package/lib/commands/build-docs/index.js.map +1 -0
- package/lib/commands/build-docs/types.d.ts +2 -1
- package/lib/commands/build-docs/types.d.ts.map +1 -0
- package/lib/commands/build-docs/types.js +2 -2
- package/lib/commands/build-docs/types.js.map +1 -0
- package/lib/commands/build-docs/utils.d.ts +3 -2
- package/lib/commands/build-docs/utils.d.ts.map +1 -0
- package/lib/commands/build-docs/utils.js +35 -37
- package/lib/commands/build-docs/utils.js.map +1 -0
- package/lib/commands/bundle.d.ts +6 -3
- package/lib/commands/bundle.d.ts.map +1 -0
- package/lib/commands/bundle.js +34 -38
- package/lib/commands/bundle.js.map +1 -0
- package/lib/commands/eject.d.ts +3 -2
- package/lib/commands/eject.d.ts.map +1 -0
- package/lib/commands/eject.js +11 -13
- package/lib/commands/eject.js.map +1 -0
- package/lib/commands/join.d.ts +4 -3
- package/lib/commands/join.d.ts.map +1 -0
- package/lib/commands/join.js +79 -81
- package/lib/commands/join.js.map +1 -0
- package/lib/commands/lint.d.ts +8 -6
- package/lib/commands/lint.d.ts.map +1 -0
- package/lib/commands/lint.js +53 -62
- package/lib/commands/lint.js.map +1 -0
- package/lib/commands/preview-project/constants.d.ts +2 -1
- package/lib/commands/preview-project/constants.d.ts.map +1 -0
- package/lib/commands/preview-project/constants.js +4 -6
- package/lib/commands/preview-project/constants.js.map +1 -0
- package/lib/commands/preview-project/index.d.ts +3 -2
- package/lib/commands/preview-project/index.d.ts.map +1 -0
- package/lib/commands/preview-project/index.js +21 -23
- package/lib/commands/preview-project/index.js.map +1 -0
- package/lib/commands/preview-project/types.d.ts +3 -2
- package/lib/commands/preview-project/types.d.ts.map +1 -0
- package/lib/commands/preview-project/types.js +2 -2
- package/lib/commands/preview-project/types.js.map +1 -0
- package/lib/commands/split/index.d.ts +4 -3
- package/lib/commands/split/index.d.ts.map +1 -0
- package/lib/commands/split/index.js +53 -57
- package/lib/commands/split/index.js.map +1 -0
- package/lib/commands/split/types.d.ts +2 -2
- package/lib/commands/split/types.d.ts.map +1 -0
- package/lib/commands/split/types.js +11 -13
- package/lib/commands/split/types.js.map +1 -0
- package/lib/commands/stats.d.ts +3 -2
- package/lib/commands/stats.d.ts.map +1 -0
- package/lib/commands/stats.js +21 -24
- package/lib/commands/stats.js.map +1 -0
- package/lib/commands/translations.d.ts +3 -2
- package/lib/commands/translations.d.ts.map +1 -0
- package/lib/commands/translations.js +11 -13
- package/lib/commands/translations.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +109 -239
- package/lib/index.js.map +1 -0
- package/lib/otel.d.ts +2 -1
- package/lib/otel.d.ts.map +1 -0
- package/lib/otel.js +22 -23
- package/lib/otel.js.map +1 -0
- package/lib/reunite/api/api-client.d.ts +4 -3
- package/lib/reunite/api/api-client.d.ts.map +1 -0
- package/lib/reunite/api/api-client.js +14 -20
- package/lib/reunite/api/api-client.js.map +1 -0
- package/lib/reunite/api/api-keys.d.ts +2 -1
- package/lib/reunite/api/api-keys.d.ts.map +1 -0
- package/lib/reunite/api/api-keys.js +4 -20
- package/lib/reunite/api/api-keys.js.map +1 -0
- package/lib/reunite/api/domains.d.ts +5 -2
- package/lib/reunite/api/domains.d.ts.map +1 -0
- package/lib/reunite/api/domains.js +6 -15
- package/lib/reunite/api/domains.js.map +1 -0
- package/lib/reunite/api/index.d.ts +4 -3
- package/lib/reunite/api/index.d.ts.map +1 -0
- package/lib/reunite/api/index.js +4 -19
- package/lib/reunite/api/index.js.map +1 -0
- package/lib/reunite/api/types.d.ts +1 -0
- package/lib/reunite/api/types.d.ts.map +1 -0
- package/lib/reunite/api/types.js +2 -2
- package/lib/reunite/api/types.js.map +1 -0
- package/lib/reunite/commands/push-status.d.ts +6 -5
- package/lib/reunite/commands/push-status.d.ts.map +1 -0
- package/lib/reunite/commands/push-status.js +31 -37
- package/lib/reunite/commands/push-status.js.map +1 -0
- package/lib/reunite/commands/push.d.ts +6 -6
- package/lib/reunite/commands/push.d.ts.map +1 -0
- package/lib/reunite/commands/push.js +31 -40
- package/lib/reunite/commands/push.js.map +1 -0
- package/lib/reunite/commands/utils.d.ts +4 -3
- package/lib/reunite/commands/utils.d.ts.map +1 -0
- package/lib/reunite/commands/utils.js +9 -12
- package/lib/reunite/commands/utils.js.map +1 -0
- package/lib/reunite/utils.d.ts +1 -0
- package/lib/reunite/utils.d.ts.map +1 -0
- package/lib/reunite/utils.js +2 -5
- package/lib/reunite/utils.js.map +1 -0
- package/lib/types.d.ts +15 -27
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -5
- package/lib/types.js.map +1 -0
- package/lib/utils/assert-node-version.d.ts +1 -0
- package/lib/utils/assert-node-version.d.ts.map +1 -0
- package/lib/utils/assert-node-version.js +8 -10
- package/lib/utils/assert-node-version.js.map +1 -0
- package/lib/utils/error.d.ts +4 -0
- package/lib/utils/error.d.ts.map +1 -0
- package/lib/utils/error.js +8 -0
- package/lib/utils/error.js.map +1 -0
- package/lib/utils/fetch-with-timeout.d.ts +1 -0
- package/lib/utils/fetch-with-timeout.d.ts.map +1 -0
- package/lib/utils/fetch-with-timeout.js +6 -8
- package/lib/utils/fetch-with-timeout.js.map +1 -0
- package/lib/utils/{getCommandNameFromArgs.d.ts → get-command-name-from-args.d.ts} +1 -0
- package/lib/utils/get-command-name-from-args.d.ts.map +1 -0
- package/lib/utils/get-command-name-from-args.js +4 -0
- package/lib/utils/get-command-name-from-args.js.map +1 -0
- package/lib/utils/js-utils.d.ts +1 -0
- package/lib/utils/js-utils.d.ts.map +1 -0
- package/lib/utils/js-utils.js +8 -12
- package/lib/utils/js-utils.js.map +1 -0
- package/lib/utils/miscellaneous.d.ts +9 -48
- package/lib/utils/miscellaneous.d.ts.map +1 -0
- package/lib/utils/miscellaneous.js +131 -269
- package/lib/utils/miscellaneous.js.map +1 -0
- package/lib/utils/package.d.ts +2 -0
- package/lib/utils/package.d.ts.map +1 -0
- package/lib/utils/package.js +4 -0
- package/lib/utils/package.js.map +1 -0
- package/lib/utils/platform.d.ts +1 -0
- package/lib/utils/platform.d.ts.map +1 -0
- package/lib/utils/platform.js +5 -9
- package/lib/utils/platform.js.map +1 -0
- package/lib/utils/proxy-agent.d.ts +3 -0
- package/lib/utils/proxy-agent.d.ts.map +1 -0
- package/lib/utils/proxy-agent.js +6 -0
- package/lib/utils/proxy-agent.js.map +1 -0
- package/lib/utils/spinner.d.ts +1 -0
- package/lib/utils/spinner.d.ts.map +1 -0
- package/lib/utils/spinner.js +8 -10
- package/lib/utils/spinner.js.map +1 -0
- package/lib/utils/telemetry.d.ts +40 -0
- package/lib/utils/telemetry.d.ts.map +1 -0
- package/lib/utils/telemetry.js +138 -0
- package/lib/utils/telemetry.js.map +1 -0
- package/lib/utils/update-version-notifier.d.ts +1 -1
- package/lib/utils/update-version-notifier.d.ts.map +1 -0
- package/lib/utils/update-version-notifier.js +35 -38
- package/lib/utils/update-version-notifier.js.map +1 -0
- package/lib/utils/validate-positive-number.d.ts +2 -0
- package/lib/utils/validate-positive-number.d.ts.map +1 -0
- package/lib/utils/validate-positive-number.js +13 -0
- package/lib/utils/validate-positive-number.js.map +1 -0
- package/lib/wrapper.d.ts +3 -3
- package/lib/wrapper.d.ts.map +1 -0
- package/lib/wrapper.js +39 -26
- package/lib/wrapper.js.map +1 -0
- package/package.json +16 -17
- package/CHANGELOG.md +0 -777
- package/lib/__mocks__/@redocly/openapi-core.d.ts +0 -99
- package/lib/__mocks__/@redocly/openapi-core.js +0 -84
- package/lib/__mocks__/documents.d.ts +0 -150
- package/lib/__mocks__/documents.js +0 -123
- package/lib/__mocks__/fs.d.ts +0 -8
- package/lib/__mocks__/fs.js +0 -9
- package/lib/__mocks__/perf_hooks.d.ts +0 -3
- package/lib/__mocks__/perf_hooks.js +0 -6
- package/lib/__mocks__/redoc.d.ts +0 -6
- package/lib/__mocks__/redoc.js +0 -5
- package/lib/__tests__/commands/build-docs.test.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +0 -54
- package/lib/__tests__/commands/bundle.test.d.ts +0 -1
- package/lib/__tests__/commands/bundle.test.js +0 -235
- package/lib/__tests__/commands/join.test.d.ts +0 -1
- package/lib/__tests__/commands/join.test.js +0 -274
- package/lib/__tests__/commands/lint.test.d.ts +0 -1
- package/lib/__tests__/commands/lint.test.js +0 -149
- package/lib/__tests__/commands/push-region.test.d.ts +0 -1
- package/lib/__tests__/commands/push-region.test.js +0 -90
- package/lib/__tests__/commands/push.test.d.ts +0 -1
- package/lib/__tests__/commands/push.test.js +0 -496
- package/lib/__tests__/fetch-with-timeout.test.d.ts +0 -1
- package/lib/__tests__/fetch-with-timeout.test.js +0 -64
- package/lib/__tests__/fixtures/config.d.ts +0 -21
- package/lib/__tests__/fixtures/config.js +0 -24
- package/lib/__tests__/spinner.test.d.ts +0 -1
- package/lib/__tests__/spinner.test.js +0 -43
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -651
- package/lib/__tests__/wrapper.test.d.ts +0 -1
- package/lib/__tests__/wrapper.test.js +0 -76
- package/lib/auth/__tests__/device-flow.test.d.ts +0 -1
- package/lib/auth/__tests__/device-flow.test.js +0 -62
- package/lib/auth/__tests__/oauth-client.test.d.ts +0 -1
- package/lib/auth/__tests__/oauth-client.test.js +0 -93
- package/lib/commands/preview-docs/index.d.ts +0 -12
- package/lib/commands/preview-docs/index.js +0 -127
- package/lib/commands/preview-docs/preview-server/default.hbs +0 -24
- package/lib/commands/preview-docs/preview-server/hot.js +0 -59
- package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/lib/commands/preview-docs/preview-server/preview-server.d.ts +0 -5
- package/lib/commands/preview-docs/preview-server/preview-server.js +0 -113
- package/lib/commands/preview-docs/preview-server/server.d.ts +0 -22
- package/lib/commands/preview-docs/preview-server/server.js +0 -85
- package/lib/commands/push.d.ts +0 -44
- package/lib/commands/push.js +0 -301
- package/lib/commands/split/__tests__/index.test.d.ts +0 -1
- package/lib/commands/split/__tests__/index.test.js +0 -91
- package/lib/reunite/api/__tests__/api-keys.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api-keys.test.js +0 -26
- package/lib/reunite/api/__tests__/api.client.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api.client.test.js +0 -337
- package/lib/reunite/api/__tests__/domains.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/domains.test.js +0 -32
- package/lib/reunite/commands/__tests__/push-status.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push-status.test.js +0 -563
- package/lib/reunite/commands/__tests__/push.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push.test.js +0 -315
- package/lib/reunite/commands/__tests__/utils.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/utils.test.js +0 -51
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -43
- package/lib/utils/__mocks__/miscellaneous.js +0 -24
- package/lib/utils/getCommandNameFromArgs.js +0 -6
- package/src/__mocks__/@redocly/openapi-core.ts +0 -88
- package/src/__mocks__/documents.ts +0 -124
- package/src/__mocks__/fs.ts +0 -6
- package/src/__mocks__/perf_hooks.ts +0 -3
- package/src/__mocks__/redoc.ts +0 -2
- package/src/__tests__/commands/build-docs.test.ts +0 -59
- package/src/__tests__/commands/bundle.test.ts +0 -285
- package/src/__tests__/commands/join.test.ts +0 -334
- package/src/__tests__/commands/lint.test.ts +0 -190
- package/src/__tests__/commands/push-region.test.ts +0 -104
- package/src/__tests__/commands/push.test.ts +0 -553
- package/src/__tests__/fetch-with-timeout.test.ts +0 -81
- package/src/__tests__/fixtures/config.ts +0 -21
- package/src/__tests__/fixtures/openapi.json +0 -0
- package/src/__tests__/fixtures/openapi.yaml +0 -0
- package/src/__tests__/fixtures/redocly.yaml +0 -0
- package/src/__tests__/spinner.test.ts +0 -51
- package/src/__tests__/utils.test.ts +0 -781
- package/src/__tests__/wrapper.test.ts +0 -91
- package/src/auth/__tests__/device-flow.test.ts +0 -73
- package/src/auth/__tests__/oauth-client.test.ts +0 -117
- package/src/auth/device-flow.ts +0 -175
- package/src/auth/oauth-client.ts +0 -111
- package/src/commands/auth.ts +0 -66
- package/src/commands/build-docs/index.ts +0 -55
- package/src/commands/build-docs/template.hbs +0 -23
- package/src/commands/build-docs/types.ts +0 -25
- package/src/commands/build-docs/utils.ts +0 -110
- package/src/commands/bundle.ts +0 -154
- package/src/commands/eject.ts +0 -42
- package/src/commands/join.ts +0 -794
- package/src/commands/lint.ts +0 -169
- package/src/commands/preview-docs/index.ts +0 -183
- package/src/commands/preview-docs/preview-server/default.hbs +0 -24
- package/src/commands/preview-docs/preview-server/hot.js +0 -59
- package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/src/commands/preview-docs/preview-server/preview-server.ts +0 -159
- package/src/commands/preview-docs/preview-server/server.ts +0 -92
- package/src/commands/preview-project/constants.ts +0 -23
- package/src/commands/preview-project/index.ts +0 -71
- package/src/commands/preview-project/types.ts +0 -12
- package/src/commands/push.ts +0 -470
- package/src/commands/split/__tests__/fixtures/samples.json +0 -61
- package/src/commands/split/__tests__/fixtures/spec.json +0 -70
- package/src/commands/split/__tests__/fixtures/webhooks.json +0 -85
- package/src/commands/split/__tests__/index.test.ts +0 -156
- package/src/commands/split/index.ts +0 -397
- package/src/commands/split/types.ts +0 -60
- package/src/commands/stats.ts +0 -140
- package/src/commands/translations.ts +0 -32
- package/src/custom.d.ts +0 -1
- package/src/index.ts +0 -970
- package/src/otel.ts +0 -59
- package/src/reunite/api/__tests__/api-keys.test.ts +0 -37
- package/src/reunite/api/__tests__/api.client.test.ts +0 -452
- package/src/reunite/api/__tests__/domains.test.ts +0 -41
- package/src/reunite/api/api-client.ts +0 -381
- package/src/reunite/api/api-keys.ts +0 -26
- package/src/reunite/api/domains.ts +0 -23
- package/src/reunite/api/index.ts +0 -3
- package/src/reunite/api/types.ts +0 -108
- package/src/reunite/commands/__tests__/push-status.test.ts +0 -653
- package/src/reunite/commands/__tests__/push.test.ts +0 -385
- package/src/reunite/commands/__tests__/utils.test.ts +0 -62
- package/src/reunite/commands/push-status.ts +0 -325
- package/src/reunite/commands/push.ts +0 -235
- package/src/reunite/commands/utils.ts +0 -66
- package/src/reunite/utils.ts +0 -1
- package/src/types.ts +0 -64
- package/src/utils/__mocks__/miscellaneous.ts +0 -24
- package/src/utils/assert-node-version.ts +0 -19
- package/src/utils/fetch-with-timeout.ts +0 -30
- package/src/utils/getCommandNameFromArgs.ts +0 -5
- package/src/utils/js-utils.ts +0 -24
- package/src/utils/miscellaneous.ts +0 -729
- package/src/utils/platform.ts +0 -31
- package/src/utils/spinner.ts +0 -50
- package/src/utils/update-version-notifier.ts +0 -115
- package/src/wrapper.ts +0 -77
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { handlePush } from '../push';
|
|
4
|
-
import { ReuniteApi, ReuniteApiError } from '../../api';
|
|
5
|
-
|
|
6
|
-
const remotes = {
|
|
7
|
-
push: jest.fn(),
|
|
8
|
-
upsert: jest.fn(),
|
|
9
|
-
getDefaultBranch: jest.fn(),
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
jest.mock('@redocly/openapi-core', () => ({
|
|
13
|
-
slash: jest.fn().mockImplementation((p) => p),
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
jest.mock('../../api', () => ({
|
|
17
|
-
...jest.requireActual('../../api'),
|
|
18
|
-
ReuniteApi: jest.fn().mockImplementation(function (this: any, ...args) {
|
|
19
|
-
this.remotes = remotes;
|
|
20
|
-
this.reportSunsetWarnings = jest.fn();
|
|
21
|
-
}),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
describe('handlePush()', () => {
|
|
25
|
-
let pathResolveSpy: jest.SpyInstance;
|
|
26
|
-
let pathRelativeSpy: jest.SpyInstance;
|
|
27
|
-
let pathDirnameSpy: jest.SpyInstance;
|
|
28
|
-
let fsStatSyncSpy: jest.SpyInstance;
|
|
29
|
-
let fsReaddirSyncSpy: jest.SpyInstance;
|
|
30
|
-
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
remotes.getDefaultBranch.mockResolvedValueOnce('test-default-branch');
|
|
33
|
-
remotes.upsert.mockResolvedValueOnce({ id: 'test-remote-id', mountPath: 'test-mount-path' });
|
|
34
|
-
remotes.push.mockResolvedValueOnce({ branchName: 'uploaded-to-branch', id: 'test-id' });
|
|
35
|
-
|
|
36
|
-
jest.spyOn(fs, 'createReadStream').mockReturnValue('stream' as any);
|
|
37
|
-
|
|
38
|
-
pathResolveSpy = jest.spyOn(path, 'resolve');
|
|
39
|
-
pathRelativeSpy = jest.spyOn(path, 'relative');
|
|
40
|
-
pathDirnameSpy = jest.spyOn(path, 'dirname');
|
|
41
|
-
fsStatSyncSpy = jest.spyOn(fs, 'statSync');
|
|
42
|
-
fsReaddirSyncSpy = jest.spyOn(fs, 'readdirSync');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
afterEach(() => {
|
|
46
|
-
pathResolveSpy.mockRestore();
|
|
47
|
-
pathRelativeSpy.mockRestore();
|
|
48
|
-
pathDirnameSpy.mockRestore();
|
|
49
|
-
fsStatSyncSpy.mockRestore();
|
|
50
|
-
fsReaddirSyncSpy.mockRestore();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should upload files', async () => {
|
|
54
|
-
const mockConfig = { apis: {} } as any;
|
|
55
|
-
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
56
|
-
|
|
57
|
-
fsStatSyncSpy.mockReturnValueOnce({
|
|
58
|
-
isDirectory() {
|
|
59
|
-
return false;
|
|
60
|
-
},
|
|
61
|
-
} as any);
|
|
62
|
-
|
|
63
|
-
pathResolveSpy.mockImplementationOnce((p) => p);
|
|
64
|
-
pathRelativeSpy.mockImplementationOnce((_, p) => p);
|
|
65
|
-
pathDirnameSpy.mockImplementation((_: string) => '.');
|
|
66
|
-
|
|
67
|
-
await handlePush({
|
|
68
|
-
argv: {
|
|
69
|
-
domain: 'test-domain',
|
|
70
|
-
'mount-path': 'test-mount-path',
|
|
71
|
-
organization: 'test-org',
|
|
72
|
-
project: 'test-project',
|
|
73
|
-
branch: 'test-branch',
|
|
74
|
-
namespace: 'test-namespace',
|
|
75
|
-
repository: 'test-repository',
|
|
76
|
-
'commit-sha': 'test-commit-sha',
|
|
77
|
-
'commit-url': 'test-commit-url',
|
|
78
|
-
'default-branch': 'test-branch',
|
|
79
|
-
'created-at': 'test-created-at',
|
|
80
|
-
author: 'TestAuthor <test-author@mail.com>',
|
|
81
|
-
message: 'Test message',
|
|
82
|
-
files: ['test-file'],
|
|
83
|
-
'max-execution-time': 10,
|
|
84
|
-
},
|
|
85
|
-
config: mockConfig,
|
|
86
|
-
version: 'cli-version',
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
expect(remotes.getDefaultBranch).toHaveBeenCalledWith('test-org', 'test-project');
|
|
90
|
-
expect(remotes.upsert).toHaveBeenCalledWith('test-org', 'test-project', {
|
|
91
|
-
mountBranchName: 'test-default-branch',
|
|
92
|
-
mountPath: 'test-mount-path',
|
|
93
|
-
});
|
|
94
|
-
expect(remotes.push).toHaveBeenCalledWith(
|
|
95
|
-
'test-org',
|
|
96
|
-
'test-project',
|
|
97
|
-
{
|
|
98
|
-
isMainBranch: true,
|
|
99
|
-
remoteId: 'test-remote-id',
|
|
100
|
-
commit: {
|
|
101
|
-
message: 'Test message',
|
|
102
|
-
branchName: 'test-branch',
|
|
103
|
-
createdAt: 'test-created-at',
|
|
104
|
-
namespace: 'test-namespace',
|
|
105
|
-
repository: 'test-repository',
|
|
106
|
-
sha: 'test-commit-sha',
|
|
107
|
-
url: 'test-commit-url',
|
|
108
|
-
author: {
|
|
109
|
-
name: 'TestAuthor',
|
|
110
|
-
email: 'test-author@mail.com',
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
[
|
|
115
|
-
{
|
|
116
|
-
path: 'test-file',
|
|
117
|
-
stream: 'stream',
|
|
118
|
-
},
|
|
119
|
-
]
|
|
120
|
-
);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('should return push id', async () => {
|
|
124
|
-
const mockConfig = { apis: {} } as any;
|
|
125
|
-
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
126
|
-
|
|
127
|
-
fsStatSyncSpy.mockReturnValueOnce({
|
|
128
|
-
isDirectory() {
|
|
129
|
-
return false;
|
|
130
|
-
},
|
|
131
|
-
} as any);
|
|
132
|
-
|
|
133
|
-
pathResolveSpy.mockImplementationOnce((p) => p);
|
|
134
|
-
pathRelativeSpy.mockImplementationOnce((_, p) => p);
|
|
135
|
-
pathDirnameSpy.mockImplementation((_: string) => '.');
|
|
136
|
-
|
|
137
|
-
const result = await handlePush({
|
|
138
|
-
argv: {
|
|
139
|
-
domain: 'test-domain',
|
|
140
|
-
'mount-path': 'test-mount-path',
|
|
141
|
-
organization: 'test-org',
|
|
142
|
-
project: 'test-project',
|
|
143
|
-
branch: 'test-branch',
|
|
144
|
-
namespace: 'test-namespace',
|
|
145
|
-
repository: 'test-repository',
|
|
146
|
-
'commit-sha': 'test-commit-sha',
|
|
147
|
-
'commit-url': 'test-commit-url',
|
|
148
|
-
'default-branch': 'test-branch',
|
|
149
|
-
'created-at': 'test-created-at',
|
|
150
|
-
author: 'TestAuthor <test-author@mail.com>',
|
|
151
|
-
message: 'Test message',
|
|
152
|
-
files: ['test-file'],
|
|
153
|
-
'max-execution-time': 10,
|
|
154
|
-
},
|
|
155
|
-
config: mockConfig,
|
|
156
|
-
version: 'cli-version',
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
expect(result).toEqual({ pushId: 'test-id' });
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('should collect files from directory and preserve file structure', async () => {
|
|
163
|
-
const mockConfig = { apis: {} } as any;
|
|
164
|
-
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
165
|
-
|
|
166
|
-
/*
|
|
167
|
-
├── app
|
|
168
|
-
│ ├── index.html
|
|
169
|
-
├── openapi.yaml
|
|
170
|
-
└── some-ref.yaml
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
fsStatSyncSpy.mockImplementation(
|
|
174
|
-
(filePath) =>
|
|
175
|
-
({
|
|
176
|
-
isDirectory() {
|
|
177
|
-
return filePath === 'test-folder' || filePath === 'test-folder/app';
|
|
178
|
-
},
|
|
179
|
-
} as any)
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
fsReaddirSyncSpy.mockImplementation((dirPath): any => {
|
|
183
|
-
if (dirPath === 'test-folder') {
|
|
184
|
-
return ['app', 'another-ref.yaml', 'openapi.yaml'];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (dirPath === 'test-folder/app') {
|
|
188
|
-
return ['index.html'];
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
throw new Error('Not a directory');
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
await handlePush({
|
|
195
|
-
argv: {
|
|
196
|
-
domain: 'test-domain',
|
|
197
|
-
'mount-path': 'test-mount-path',
|
|
198
|
-
organization: 'test-org',
|
|
199
|
-
project: 'test-project',
|
|
200
|
-
branch: 'test-branch',
|
|
201
|
-
author: 'TestAuthor <test-author@mail.com>',
|
|
202
|
-
message: 'Test message',
|
|
203
|
-
'default-branch': 'main',
|
|
204
|
-
files: ['test-folder'],
|
|
205
|
-
'max-execution-time': 10,
|
|
206
|
-
},
|
|
207
|
-
config: mockConfig,
|
|
208
|
-
version: 'cli-version',
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
expect(remotes.push).toHaveBeenCalledWith(
|
|
212
|
-
expect.anything(),
|
|
213
|
-
expect.anything(),
|
|
214
|
-
expect.anything(),
|
|
215
|
-
[
|
|
216
|
-
{
|
|
217
|
-
path: 'app/index.html',
|
|
218
|
-
stream: 'stream',
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
{
|
|
222
|
-
path: 'another-ref.yaml',
|
|
223
|
-
stream: 'stream',
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
path: 'openapi.yaml',
|
|
227
|
-
stream: 'stream',
|
|
228
|
-
},
|
|
229
|
-
]
|
|
230
|
-
);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('should not upload files if no files passed', async () => {
|
|
234
|
-
const mockConfig = { apis: {} } as any;
|
|
235
|
-
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
236
|
-
|
|
237
|
-
await handlePush({
|
|
238
|
-
argv: {
|
|
239
|
-
domain: 'test-domain',
|
|
240
|
-
'mount-path': 'test-mount-path',
|
|
241
|
-
organization: 'test-org',
|
|
242
|
-
project: 'test-project',
|
|
243
|
-
branch: 'test-branch',
|
|
244
|
-
author: 'TestAuthor <test-author@mail.com>',
|
|
245
|
-
message: 'Test message',
|
|
246
|
-
'default-branch': 'main',
|
|
247
|
-
files: [],
|
|
248
|
-
'max-execution-time': 10,
|
|
249
|
-
},
|
|
250
|
-
config: mockConfig,
|
|
251
|
-
version: 'cli-version',
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
expect(remotes.getDefaultBranch).not.toHaveBeenCalled();
|
|
255
|
-
expect(remotes.upsert).not.toHaveBeenCalled();
|
|
256
|
-
expect(remotes.push).not.toHaveBeenCalled();
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('should get organization from config if not passed', async () => {
|
|
260
|
-
const mockConfig = { organization: 'test-org-from-config', apis: {} } as any;
|
|
261
|
-
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
262
|
-
|
|
263
|
-
fsStatSyncSpy.mockReturnValueOnce({
|
|
264
|
-
isDirectory() {
|
|
265
|
-
return false;
|
|
266
|
-
},
|
|
267
|
-
} as any);
|
|
268
|
-
|
|
269
|
-
pathResolveSpy.mockImplementationOnce((p) => p);
|
|
270
|
-
pathRelativeSpy.mockImplementationOnce((_, p) => p);
|
|
271
|
-
pathDirnameSpy.mockImplementation((_: string) => '.');
|
|
272
|
-
|
|
273
|
-
await handlePush({
|
|
274
|
-
argv: {
|
|
275
|
-
domain: 'test-domain',
|
|
276
|
-
'mount-path': 'test-mount-path',
|
|
277
|
-
project: 'test-project',
|
|
278
|
-
branch: 'test-branch',
|
|
279
|
-
author: 'TestAuthor <test-author@mail.com>',
|
|
280
|
-
message: 'Test message',
|
|
281
|
-
files: ['test-file'],
|
|
282
|
-
'default-branch': 'main',
|
|
283
|
-
'max-execution-time': 10,
|
|
284
|
-
},
|
|
285
|
-
config: mockConfig,
|
|
286
|
-
version: 'cli-version',
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
expect(remotes.getDefaultBranch).toHaveBeenCalledWith(
|
|
290
|
-
'test-org-from-config',
|
|
291
|
-
expect.anything()
|
|
292
|
-
);
|
|
293
|
-
expect(remotes.upsert).toHaveBeenCalledWith(
|
|
294
|
-
'test-org-from-config',
|
|
295
|
-
expect.anything(),
|
|
296
|
-
expect.anything()
|
|
297
|
-
);
|
|
298
|
-
expect(remotes.push).toHaveBeenCalledWith(
|
|
299
|
-
'test-org-from-config',
|
|
300
|
-
expect.anything(),
|
|
301
|
-
expect.anything(),
|
|
302
|
-
expect.anything()
|
|
303
|
-
);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it('should get domain from env if not passed', async () => {
|
|
307
|
-
const mockConfig = { organization: 'test-org-from-config', apis: {} } as any;
|
|
308
|
-
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
309
|
-
process.env.REDOCLY_DOMAIN = 'test-domain-from-env';
|
|
310
|
-
|
|
311
|
-
fsStatSyncSpy.mockReturnValueOnce({
|
|
312
|
-
isDirectory() {
|
|
313
|
-
return false;
|
|
314
|
-
},
|
|
315
|
-
} as any);
|
|
316
|
-
|
|
317
|
-
pathResolveSpy.mockImplementationOnce((p) => p);
|
|
318
|
-
pathRelativeSpy.mockImplementationOnce((_, p) => p);
|
|
319
|
-
pathDirnameSpy.mockImplementation((_: string) => '.');
|
|
320
|
-
|
|
321
|
-
await handlePush({
|
|
322
|
-
argv: {
|
|
323
|
-
'mount-path': 'test-mount-path',
|
|
324
|
-
project: 'test-project',
|
|
325
|
-
branch: 'test-branch',
|
|
326
|
-
'default-branch': 'main',
|
|
327
|
-
author: 'TestAuthor <test-author@mail.com>',
|
|
328
|
-
message: 'Test message',
|
|
329
|
-
files: ['test-file'],
|
|
330
|
-
'max-execution-time': 10,
|
|
331
|
-
},
|
|
332
|
-
config: mockConfig,
|
|
333
|
-
version: 'cli-version',
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
expect(ReuniteApi).toBeCalledWith({
|
|
337
|
-
domain: 'test-domain-from-env',
|
|
338
|
-
apiKey: 'test-api-key',
|
|
339
|
-
version: 'cli-version',
|
|
340
|
-
command: 'push',
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it('should print error message', async () => {
|
|
345
|
-
const mockConfig = { apis: {} } as any;
|
|
346
|
-
process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
|
|
347
|
-
|
|
348
|
-
remotes.push.mockRestore();
|
|
349
|
-
remotes.push.mockRejectedValueOnce(new ReuniteApiError('Deprecated.', 412));
|
|
350
|
-
|
|
351
|
-
fsStatSyncSpy.mockReturnValueOnce({
|
|
352
|
-
isDirectory() {
|
|
353
|
-
return false;
|
|
354
|
-
},
|
|
355
|
-
} as any);
|
|
356
|
-
|
|
357
|
-
pathResolveSpy.mockImplementationOnce((p) => p);
|
|
358
|
-
pathRelativeSpy.mockImplementationOnce((_, p) => p);
|
|
359
|
-
pathDirnameSpy.mockImplementation((_: string) => '.');
|
|
360
|
-
|
|
361
|
-
expect(
|
|
362
|
-
handlePush({
|
|
363
|
-
argv: {
|
|
364
|
-
domain: 'test-domain',
|
|
365
|
-
'mount-path': 'test-mount-path',
|
|
366
|
-
organization: 'test-org',
|
|
367
|
-
project: 'test-project',
|
|
368
|
-
branch: 'test-branch',
|
|
369
|
-
namespace: 'test-namespace',
|
|
370
|
-
repository: 'test-repository',
|
|
371
|
-
'commit-sha': 'test-commit-sha',
|
|
372
|
-
'commit-url': 'test-commit-url',
|
|
373
|
-
'default-branch': 'test-branch',
|
|
374
|
-
'created-at': 'test-created-at',
|
|
375
|
-
author: 'TestAuthor <test-author@mail.com>',
|
|
376
|
-
message: 'Test message',
|
|
377
|
-
files: ['test-file'],
|
|
378
|
-
'max-execution-time': 10,
|
|
379
|
-
},
|
|
380
|
-
config: mockConfig,
|
|
381
|
-
version: 'cli-version',
|
|
382
|
-
})
|
|
383
|
-
).rejects.toThrow('✗ File upload failed. Reason: Deprecated.');
|
|
384
|
-
});
|
|
385
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { retryUntilConditionMet } from '../utils';
|
|
2
|
-
|
|
3
|
-
jest.mock('@redocly/openapi-core', () => ({
|
|
4
|
-
pause: jest.requireActual('@redocly/openapi-core').pause,
|
|
5
|
-
}));
|
|
6
|
-
|
|
7
|
-
describe('retryUntilConditionMet()', () => {
|
|
8
|
-
it('should retry until condition meet and return result', async () => {
|
|
9
|
-
const operation = jest
|
|
10
|
-
.fn()
|
|
11
|
-
.mockResolvedValueOnce({ status: 'pending' })
|
|
12
|
-
.mockResolvedValueOnce({ status: 'pending' })
|
|
13
|
-
.mockResolvedValueOnce({ status: 'done' });
|
|
14
|
-
|
|
15
|
-
const data = await retryUntilConditionMet({
|
|
16
|
-
operation,
|
|
17
|
-
condition: (result: any) => result?.status === 'done',
|
|
18
|
-
retryIntervalMs: 100,
|
|
19
|
-
retryTimeoutMs: 1000,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
expect(data).toEqual({ status: 'done' });
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should throw error if condition not meet for desired timeout', async () => {
|
|
26
|
-
const operation = jest.fn().mockResolvedValue({ status: 'pending' });
|
|
27
|
-
|
|
28
|
-
await expect(
|
|
29
|
-
retryUntilConditionMet({
|
|
30
|
-
operation,
|
|
31
|
-
condition: (result: any) => result?.status === 'done',
|
|
32
|
-
retryIntervalMs: 100,
|
|
33
|
-
retryTimeoutMs: 1000,
|
|
34
|
-
})
|
|
35
|
-
).rejects.toThrow('Timeout exceeded.');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should call "onConditionNotMet" and "onRetry" callbacks', async () => {
|
|
39
|
-
const operation = jest
|
|
40
|
-
.fn()
|
|
41
|
-
.mockResolvedValueOnce({ status: 'pending' })
|
|
42
|
-
.mockResolvedValueOnce({ status: 'pending' })
|
|
43
|
-
.mockResolvedValueOnce({ status: 'done' });
|
|
44
|
-
|
|
45
|
-
const onConditionNotMet = jest.fn();
|
|
46
|
-
const onRetry = jest.fn();
|
|
47
|
-
|
|
48
|
-
const data = await retryUntilConditionMet({
|
|
49
|
-
operation,
|
|
50
|
-
condition: (result: any) => result?.status === 'done',
|
|
51
|
-
retryIntervalMs: 100,
|
|
52
|
-
retryTimeoutMs: 1000,
|
|
53
|
-
onConditionNotMet,
|
|
54
|
-
onRetry,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
expect(data).toEqual({ status: 'done' });
|
|
58
|
-
|
|
59
|
-
expect(onConditionNotMet).toHaveBeenCalledTimes(2);
|
|
60
|
-
expect(onRetry).toHaveBeenCalledTimes(2);
|
|
61
|
-
});
|
|
62
|
-
});
|