@redocly/cli 1.34.3 → 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 +15 -16
- package/CHANGELOG.md +0 -770
- 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,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const openapi_core_1 = require("@redocly/openapi-core");
|
|
4
|
-
const bundle_1 = require("../../commands/bundle");
|
|
5
|
-
const miscellaneous_1 = require("../../utils/miscellaneous");
|
|
6
|
-
const wrapper_1 = require("../../wrapper");
|
|
7
|
-
jest.mock('@redocly/openapi-core');
|
|
8
|
-
jest.mock('../../utils/miscellaneous');
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
miscellaneous_1.getOutputFileName = jest.requireActual('../../utils/miscellaneous').getOutputFileName;
|
|
11
|
-
openapi_core_1.getMergedConfig.mockImplementation((config) => config);
|
|
12
|
-
describe('bundle', () => {
|
|
13
|
-
let processExitMock;
|
|
14
|
-
let exitCb;
|
|
15
|
-
let stderrWriteMock;
|
|
16
|
-
let stdoutWriteMock;
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
processExitMock = jest.spyOn(process, 'exit').mockImplementation();
|
|
19
|
-
jest.spyOn(process, 'once').mockImplementation((_e, cb) => {
|
|
20
|
-
exitCb = cb;
|
|
21
|
-
return process.on(_e, cb);
|
|
22
|
-
});
|
|
23
|
-
stderrWriteMock = jest.spyOn(process.stderr, 'write').mockImplementation(jest.fn());
|
|
24
|
-
stdoutWriteMock = jest.spyOn(process.stdout, 'write').mockImplementation(jest.fn());
|
|
25
|
-
});
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
openapi_core_1.bundle.mockClear();
|
|
28
|
-
openapi_core_1.getTotals.mockReset();
|
|
29
|
-
stderrWriteMock.mockRestore();
|
|
30
|
-
stdoutWriteMock.mockRestore();
|
|
31
|
-
});
|
|
32
|
-
it('bundles definitions', async () => {
|
|
33
|
-
const apis = ['foo.yaml', 'bar.yaml'];
|
|
34
|
-
await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
35
|
-
apis,
|
|
36
|
-
ext: 'yaml',
|
|
37
|
-
});
|
|
38
|
-
expect(openapi_core_1.bundle).toBeCalledTimes(apis.length);
|
|
39
|
-
});
|
|
40
|
-
it('exits with code 0 when bundles definitions', async () => {
|
|
41
|
-
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
42
|
-
await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
43
|
-
apis,
|
|
44
|
-
ext: 'yaml',
|
|
45
|
-
});
|
|
46
|
-
await exitCb?.();
|
|
47
|
-
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
48
|
-
});
|
|
49
|
-
it('exits with code 0 when bundles definitions w/o errors', async () => {
|
|
50
|
-
const apis = ['foo.yaml', 'bar.yaml', 'foobar.yaml'];
|
|
51
|
-
await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
52
|
-
apis,
|
|
53
|
-
ext: 'yaml',
|
|
54
|
-
});
|
|
55
|
-
await exitCb?.();
|
|
56
|
-
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
57
|
-
});
|
|
58
|
-
it('exits with code 1 when bundles definitions w/errors', async () => {
|
|
59
|
-
const apis = ['foo.yaml'];
|
|
60
|
-
openapi_core_1.getTotals.mockReturnValue({
|
|
61
|
-
errors: 1,
|
|
62
|
-
warnings: 0,
|
|
63
|
-
ignored: 0,
|
|
64
|
-
});
|
|
65
|
-
await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
66
|
-
apis,
|
|
67
|
-
ext: 'yaml',
|
|
68
|
-
});
|
|
69
|
-
await exitCb?.();
|
|
70
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
71
|
-
});
|
|
72
|
-
it('handleError is called when bundles an invalid definition', async () => {
|
|
73
|
-
const apis = ['invalid.json'];
|
|
74
|
-
openapi_core_1.bundle.mockImplementationOnce(() => {
|
|
75
|
-
throw new Error('Invalid definition');
|
|
76
|
-
});
|
|
77
|
-
await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
78
|
-
apis,
|
|
79
|
-
ext: 'json',
|
|
80
|
-
});
|
|
81
|
-
expect(miscellaneous_1.handleError).toHaveBeenCalledTimes(1);
|
|
82
|
-
expect(miscellaneous_1.handleError).toHaveBeenCalledWith(new Error('Invalid definition'), 'invalid.json');
|
|
83
|
-
});
|
|
84
|
-
it("handleError isn't called when bundles a valid definition", async () => {
|
|
85
|
-
const apis = ['foo.yaml'];
|
|
86
|
-
openapi_core_1.getTotals.mockReturnValue({
|
|
87
|
-
errors: 0,
|
|
88
|
-
warnings: 0,
|
|
89
|
-
ignored: 0,
|
|
90
|
-
});
|
|
91
|
-
await (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)({
|
|
92
|
-
apis,
|
|
93
|
-
ext: 'yaml',
|
|
94
|
-
});
|
|
95
|
-
expect(miscellaneous_1.handleError).toHaveBeenCalledTimes(0);
|
|
96
|
-
});
|
|
97
|
-
describe('per api output', () => {
|
|
98
|
-
it('should store bundled API descriptions in the output files described in the apis section of config IF no positional apis provided AND output is specified for both apis', async () => {
|
|
99
|
-
const apis = {
|
|
100
|
-
foo: {
|
|
101
|
-
root: 'foo.yaml',
|
|
102
|
-
output: 'output/foo.yaml',
|
|
103
|
-
},
|
|
104
|
-
bar: {
|
|
105
|
-
root: 'bar.yaml',
|
|
106
|
-
output: 'output/bar.json',
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
const config = {
|
|
110
|
-
apis,
|
|
111
|
-
styleguide: {
|
|
112
|
-
skipPreprocessors: jest.fn(),
|
|
113
|
-
skipDecorators: jest.fn(),
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
miscellaneous_1.getFallbackApisOrExit = jest
|
|
118
|
-
.fn()
|
|
119
|
-
.mockResolvedValueOnce(Object.entries(apis).map(([alias, { root, ...api }]) => ({ ...api, path: root, alias })));
|
|
120
|
-
openapi_core_1.getTotals.mockReturnValue({
|
|
121
|
-
errors: 0,
|
|
122
|
-
warnings: 0,
|
|
123
|
-
ignored: 0,
|
|
124
|
-
});
|
|
125
|
-
await (0, bundle_1.handleBundle)({
|
|
126
|
-
argv: { apis: [] }, // positional
|
|
127
|
-
version: 'test',
|
|
128
|
-
config,
|
|
129
|
-
});
|
|
130
|
-
expect(miscellaneous_1.saveBundle).toBeCalledTimes(2);
|
|
131
|
-
expect(miscellaneous_1.saveBundle).toHaveBeenNthCalledWith(1, 'output/foo.yaml', expect.any(String));
|
|
132
|
-
expect(miscellaneous_1.saveBundle).toHaveBeenNthCalledWith(2, 'output/bar.json', expect.any(String));
|
|
133
|
-
});
|
|
134
|
-
it('should store bundled API descriptions in the output files described in the apis section of config AND print the bundled api without the output specified to the terminal IF no positional apis provided AND output is specified for one api', async () => {
|
|
135
|
-
const apis = {
|
|
136
|
-
foo: {
|
|
137
|
-
root: 'foo.yaml',
|
|
138
|
-
output: 'output/foo.yaml',
|
|
139
|
-
},
|
|
140
|
-
bar: {
|
|
141
|
-
root: 'bar.yaml',
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
const config = {
|
|
145
|
-
apis,
|
|
146
|
-
styleguide: {
|
|
147
|
-
skipPreprocessors: jest.fn(),
|
|
148
|
-
skipDecorators: jest.fn(),
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
// @ts-ignore
|
|
152
|
-
miscellaneous_1.getFallbackApisOrExit = jest
|
|
153
|
-
.fn()
|
|
154
|
-
.mockResolvedValueOnce(Object.entries(apis).map(([alias, { root, ...api }]) => ({ ...api, path: root, alias })));
|
|
155
|
-
openapi_core_1.getTotals.mockReturnValue({
|
|
156
|
-
errors: 0,
|
|
157
|
-
warnings: 0,
|
|
158
|
-
ignored: 0,
|
|
159
|
-
});
|
|
160
|
-
await (0, bundle_1.handleBundle)({
|
|
161
|
-
argv: { apis: [] }, // positional
|
|
162
|
-
version: 'test',
|
|
163
|
-
config,
|
|
164
|
-
});
|
|
165
|
-
expect(miscellaneous_1.saveBundle).toBeCalledTimes(1);
|
|
166
|
-
expect(miscellaneous_1.saveBundle).toHaveBeenCalledWith('output/foo.yaml', expect.any(String));
|
|
167
|
-
expect(process.stdout.write).toHaveBeenCalledTimes(1);
|
|
168
|
-
});
|
|
169
|
-
it('should NOT store bundled API descriptions in the output files described in the apis section of config IF there is a positional api provided', async () => {
|
|
170
|
-
const apis = {
|
|
171
|
-
foo: {
|
|
172
|
-
root: 'foo.yaml',
|
|
173
|
-
output: 'output/foo.yaml',
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
const config = {
|
|
177
|
-
apis,
|
|
178
|
-
styleguide: {
|
|
179
|
-
skipPreprocessors: jest.fn(),
|
|
180
|
-
skipDecorators: jest.fn(),
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
// @ts-ignore
|
|
184
|
-
miscellaneous_1.getFallbackApisOrExit = jest.fn().mockResolvedValueOnce([{ path: 'openapi.yaml' }]);
|
|
185
|
-
openapi_core_1.getTotals.mockReturnValue({
|
|
186
|
-
errors: 0,
|
|
187
|
-
warnings: 0,
|
|
188
|
-
ignored: 0,
|
|
189
|
-
});
|
|
190
|
-
await (0, bundle_1.handleBundle)({
|
|
191
|
-
argv: { apis: ['openapi.yaml'] }, // positional
|
|
192
|
-
version: 'test',
|
|
193
|
-
config,
|
|
194
|
-
});
|
|
195
|
-
expect(miscellaneous_1.saveBundle).toBeCalledTimes(0);
|
|
196
|
-
expect(process.stdout.write).toHaveBeenCalledTimes(1);
|
|
197
|
-
});
|
|
198
|
-
it('should store bundled API descriptions in the directory specified in argv IF multiple positional apis provided AND --output specified', async () => {
|
|
199
|
-
const apis = {
|
|
200
|
-
foo: {
|
|
201
|
-
root: 'foo.yaml',
|
|
202
|
-
output: 'output/foo.yaml',
|
|
203
|
-
},
|
|
204
|
-
bar: {
|
|
205
|
-
root: 'bar.yaml',
|
|
206
|
-
output: 'output/bar.json',
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
const config = {
|
|
210
|
-
apis,
|
|
211
|
-
styleguide: {
|
|
212
|
-
skipPreprocessors: jest.fn(),
|
|
213
|
-
skipDecorators: jest.fn(),
|
|
214
|
-
},
|
|
215
|
-
};
|
|
216
|
-
// @ts-ignore
|
|
217
|
-
miscellaneous_1.getFallbackApisOrExit = jest
|
|
218
|
-
.fn()
|
|
219
|
-
.mockResolvedValueOnce(Object.entries(apis).map(([alias, { root, ...api }]) => ({ ...api, path: root, alias })));
|
|
220
|
-
openapi_core_1.getTotals.mockReturnValue({
|
|
221
|
-
errors: 0,
|
|
222
|
-
warnings: 0,
|
|
223
|
-
ignored: 0,
|
|
224
|
-
});
|
|
225
|
-
await (0, bundle_1.handleBundle)({
|
|
226
|
-
argv: { apis: ['foo.yaml', 'bar.yaml'], output: 'dist' }, // cli options
|
|
227
|
-
version: 'test',
|
|
228
|
-
config,
|
|
229
|
-
});
|
|
230
|
-
expect(miscellaneous_1.saveBundle).toBeCalledTimes(2);
|
|
231
|
-
expect(miscellaneous_1.saveBundle).toHaveBeenNthCalledWith(1, 'dist/foo.yaml', expect.any(String));
|
|
232
|
-
expect(miscellaneous_1.saveBundle).toHaveBeenNthCalledWith(2, 'dist/bar.yaml', expect.any(String));
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const colorette_1 = require("colorette");
|
|
4
|
-
const openapi_core_1 = require("@redocly/openapi-core");
|
|
5
|
-
const join_1 = require("../../commands/join");
|
|
6
|
-
const miscellaneous_1 = require("../../utils/miscellaneous");
|
|
7
|
-
const openapi_core_2 = require("../../__mocks__/@redocly/openapi-core");
|
|
8
|
-
const config_1 = require("../fixtures/config");
|
|
9
|
-
jest.mock('../../utils/miscellaneous');
|
|
10
|
-
jest.mock('colorette');
|
|
11
|
-
describe('handleJoin', () => {
|
|
12
|
-
const colloreteYellowMock = colorette_1.yellow;
|
|
13
|
-
colloreteYellowMock.mockImplementation((string) => string);
|
|
14
|
-
it('should call exitWithError because only one entrypoint', async () => {
|
|
15
|
-
await (0, join_1.handleJoin)({ argv: { apis: ['first.yaml'] }, config: {}, version: 'cli-version' });
|
|
16
|
-
expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`At least 2 APIs should be provided.`);
|
|
17
|
-
});
|
|
18
|
-
it('should call exitWithError if glob expands to less than 2 APIs', async () => {
|
|
19
|
-
miscellaneous_1.getFallbackApisOrExit.mockResolvedValueOnce([{ path: 'first.yaml' }]);
|
|
20
|
-
await (0, join_1.handleJoin)({
|
|
21
|
-
argv: { apis: ['*.yaml'] },
|
|
22
|
-
config: {},
|
|
23
|
-
version: 'cli-version',
|
|
24
|
-
});
|
|
25
|
-
expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`At least 2 APIs should be provided.`);
|
|
26
|
-
});
|
|
27
|
-
it('should proceed if glob expands to 2 or more APIs', async () => {
|
|
28
|
-
openapi_core_1.detectSpec.mockReturnValue('oas3_1');
|
|
29
|
-
miscellaneous_1.getFallbackApisOrExit.mockResolvedValueOnce([
|
|
30
|
-
{ path: 'first.yaml' },
|
|
31
|
-
{ path: 'second.yaml' },
|
|
32
|
-
]);
|
|
33
|
-
await (0, join_1.handleJoin)({
|
|
34
|
-
argv: { apis: ['*.yaml'] },
|
|
35
|
-
config: config_1.ConfigFixture,
|
|
36
|
-
version: 'cli-version',
|
|
37
|
-
});
|
|
38
|
-
expect(miscellaneous_1.exitWithError).not.toHaveBeenCalled();
|
|
39
|
-
});
|
|
40
|
-
it('should call exitWithError because passed all 3 options for tags', async () => {
|
|
41
|
-
await (0, join_1.handleJoin)({
|
|
42
|
-
argv: {
|
|
43
|
-
apis: ['first.yaml', 'second.yaml'],
|
|
44
|
-
'prefix-tags-with-info-prop': 'something',
|
|
45
|
-
'without-x-tag-groups': true,
|
|
46
|
-
'prefix-tags-with-filename': true,
|
|
47
|
-
},
|
|
48
|
-
config: {},
|
|
49
|
-
version: 'cli-version',
|
|
50
|
-
});
|
|
51
|
-
expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, prefix-tags-with-info-prop, without-x-tag-groups together.\nPlease choose only one!`);
|
|
52
|
-
});
|
|
53
|
-
it('should call exitWithError because passed all 2 options for tags', async () => {
|
|
54
|
-
await (0, join_1.handleJoin)({
|
|
55
|
-
argv: {
|
|
56
|
-
apis: ['first.yaml', 'second.yaml'],
|
|
57
|
-
'without-x-tag-groups': true,
|
|
58
|
-
'prefix-tags-with-filename': true,
|
|
59
|
-
},
|
|
60
|
-
config: {},
|
|
61
|
-
version: 'cli-version',
|
|
62
|
-
});
|
|
63
|
-
expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`You use prefix-tags-with-filename, without-x-tag-groups together.\nPlease choose only one!`);
|
|
64
|
-
});
|
|
65
|
-
it('should call exitWithError because Only OpenAPI 3.0 and OpenAPI 3.1 are supported', async () => {
|
|
66
|
-
openapi_core_1.detectSpec.mockReturnValueOnce('oas2_0');
|
|
67
|
-
await (0, join_1.handleJoin)({
|
|
68
|
-
argv: {
|
|
69
|
-
apis: ['first.yaml', 'second.yaml'],
|
|
70
|
-
},
|
|
71
|
-
config: config_1.ConfigFixture,
|
|
72
|
-
version: 'cli-version',
|
|
73
|
-
});
|
|
74
|
-
expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('Only OpenAPI 3.0 and OpenAPI 3.1 are supported: undefined.');
|
|
75
|
-
});
|
|
76
|
-
it('should call exitWithError if mixing OpenAPI 3.0 and 3.1', async () => {
|
|
77
|
-
openapi_core_1.detectSpec
|
|
78
|
-
.mockImplementationOnce(() => 'oas3_0')
|
|
79
|
-
.mockImplementationOnce(() => 'oas3_1');
|
|
80
|
-
await (0, join_1.handleJoin)({
|
|
81
|
-
argv: {
|
|
82
|
-
apis: ['first.yaml', 'second.yaml'],
|
|
83
|
-
},
|
|
84
|
-
config: config_1.ConfigFixture,
|
|
85
|
-
version: 'cli-version',
|
|
86
|
-
});
|
|
87
|
-
expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('All APIs must use the same OpenAPI version: undefined.');
|
|
88
|
-
});
|
|
89
|
-
it('should call writeToFileByExtension function', async () => {
|
|
90
|
-
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
91
|
-
await (0, join_1.handleJoin)({
|
|
92
|
-
argv: {
|
|
93
|
-
apis: ['first.yaml', 'second.yaml'],
|
|
94
|
-
},
|
|
95
|
-
config: config_1.ConfigFixture,
|
|
96
|
-
version: 'cli-version',
|
|
97
|
-
});
|
|
98
|
-
expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
|
|
99
|
-
});
|
|
100
|
-
it('should call writeToFileByExtension function for OpenAPI 3.1', async () => {
|
|
101
|
-
openapi_core_1.detectSpec.mockReturnValue('oas3_1');
|
|
102
|
-
await (0, join_1.handleJoin)({
|
|
103
|
-
argv: {
|
|
104
|
-
apis: ['first.yaml', 'second.yaml'],
|
|
105
|
-
},
|
|
106
|
-
config: config_1.ConfigFixture,
|
|
107
|
-
version: 'cli-version',
|
|
108
|
-
});
|
|
109
|
-
expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.yaml', expect.any(Boolean));
|
|
110
|
-
});
|
|
111
|
-
it('should call writeToFileByExtension function with custom output file', async () => {
|
|
112
|
-
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
113
|
-
await (0, join_1.handleJoin)({
|
|
114
|
-
argv: {
|
|
115
|
-
apis: ['first.yaml', 'second.yaml'],
|
|
116
|
-
output: 'output.yml',
|
|
117
|
-
},
|
|
118
|
-
config: config_1.ConfigFixture,
|
|
119
|
-
version: 'cli-version',
|
|
120
|
-
});
|
|
121
|
-
expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'output.yml', expect.any(Boolean));
|
|
122
|
-
});
|
|
123
|
-
it('should call writeToFileByExtension function with json file extension', async () => {
|
|
124
|
-
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
125
|
-
await (0, join_1.handleJoin)({
|
|
126
|
-
argv: {
|
|
127
|
-
apis: ['first.json', 'second.yaml'],
|
|
128
|
-
},
|
|
129
|
-
config: config_1.ConfigFixture,
|
|
130
|
-
version: 'cli-version',
|
|
131
|
-
});
|
|
132
|
-
expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith(expect.any(Object), 'openapi.json', expect.any(Boolean));
|
|
133
|
-
});
|
|
134
|
-
it('should call skipDecorators and skipPreprocessors', async () => {
|
|
135
|
-
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
136
|
-
await (0, join_1.handleJoin)({
|
|
137
|
-
argv: {
|
|
138
|
-
apis: ['first.yaml', 'second.yaml'],
|
|
139
|
-
},
|
|
140
|
-
config: config_1.ConfigFixture,
|
|
141
|
-
version: 'cli-version',
|
|
142
|
-
});
|
|
143
|
-
const config = (0, openapi_core_2.loadConfig)();
|
|
144
|
-
expect(config.styleguide.skipDecorators).toHaveBeenCalled();
|
|
145
|
-
expect(config.styleguide.skipPreprocessors).toHaveBeenCalled();
|
|
146
|
-
});
|
|
147
|
-
it('should handle join with prefix-components-with-info-prop and null values', async () => {
|
|
148
|
-
openapi_core_1.detectSpec.mockReturnValue('oas3_0');
|
|
149
|
-
await (0, join_1.handleJoin)({
|
|
150
|
-
argv: {
|
|
151
|
-
apis: ['first.yaml', 'second.yaml', 'third.yaml'],
|
|
152
|
-
'prefix-components-with-info-prop': 'title',
|
|
153
|
-
output: 'join-result.yaml',
|
|
154
|
-
},
|
|
155
|
-
config: config_1.ConfigFixture,
|
|
156
|
-
version: 'cli-version',
|
|
157
|
-
});
|
|
158
|
-
expect(miscellaneous_1.writeToFileByExtension).toHaveBeenCalledWith({
|
|
159
|
-
openapi: '3.0.0',
|
|
160
|
-
info: {
|
|
161
|
-
description: 'example test',
|
|
162
|
-
version: '1.0.0',
|
|
163
|
-
title: 'First API',
|
|
164
|
-
termsOfService: 'http://swagger.io/terms/',
|
|
165
|
-
license: {
|
|
166
|
-
name: 'Apache 2.0',
|
|
167
|
-
url: 'http://www.apache.org/licenses/LICENSE-2.0.html',
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
servers: [
|
|
171
|
-
{
|
|
172
|
-
url: 'http://localhost:8080',
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
url: 'https://api.server.test/v1',
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
tags: [
|
|
179
|
-
{
|
|
180
|
-
name: 'pet',
|
|
181
|
-
'x-displayName': 'pet',
|
|
182
|
-
},
|
|
183
|
-
],
|
|
184
|
-
paths: {
|
|
185
|
-
'/GETUser/{userId}': {
|
|
186
|
-
summary: 'get user by id',
|
|
187
|
-
description: 'user info',
|
|
188
|
-
servers: [
|
|
189
|
-
{
|
|
190
|
-
url: '/user',
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
url: '/pet',
|
|
194
|
-
description: 'pet server',
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
get: {
|
|
198
|
-
tags: ['pet'],
|
|
199
|
-
summary: 'Find pet by ID',
|
|
200
|
-
description: 'Returns a single pet',
|
|
201
|
-
operationId: 'getPetById',
|
|
202
|
-
servers: [
|
|
203
|
-
{
|
|
204
|
-
url: '/pet',
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
},
|
|
208
|
-
parameters: [
|
|
209
|
-
{
|
|
210
|
-
name: 'param1',
|
|
211
|
-
in: 'header',
|
|
212
|
-
schema: {
|
|
213
|
-
description: 'string',
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
],
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
components: {
|
|
220
|
-
schemas: {
|
|
221
|
-
Third_API_SchemaWithNull: {
|
|
222
|
-
type: 'string',
|
|
223
|
-
default: null,
|
|
224
|
-
nullable: true,
|
|
225
|
-
},
|
|
226
|
-
Third_API_SchemaWithRef: {
|
|
227
|
-
type: 'object',
|
|
228
|
-
properties: {
|
|
229
|
-
schemaType: {
|
|
230
|
-
type: 'string',
|
|
231
|
-
enum: ['foo'],
|
|
232
|
-
},
|
|
233
|
-
foo: {
|
|
234
|
-
$ref: '#/components/schemas/Third_API_SchemaWithNull',
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
Third_API_SchemaWithDiscriminator: {
|
|
239
|
-
discriminator: {
|
|
240
|
-
propertyName: 'schemaType',
|
|
241
|
-
mapping: {
|
|
242
|
-
foo: '#/components/schemas/Third_API_SchemaWithRef',
|
|
243
|
-
bar: '#/components/schemas/Third_API_SchemaWithNull',
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
oneOf: [
|
|
247
|
-
{
|
|
248
|
-
$ref: '#/components/schemas/Third_API_SchemaWithRef',
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
type: 'object',
|
|
252
|
-
properties: {
|
|
253
|
-
schemaType: {
|
|
254
|
-
type: 'string',
|
|
255
|
-
enum: ['bar'],
|
|
256
|
-
},
|
|
257
|
-
bar: {
|
|
258
|
-
type: 'string',
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
},
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
'x-tagGroups': [
|
|
267
|
-
{
|
|
268
|
-
name: 'First API',
|
|
269
|
-
tags: ['pet'],
|
|
270
|
-
},
|
|
271
|
-
],
|
|
272
|
-
}, 'join-result.yaml', true);
|
|
273
|
-
});
|
|
274
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const lint_1 = require("../../commands/lint");
|
|
4
|
-
const openapi_core_1 = require("@redocly/openapi-core");
|
|
5
|
-
const miscellaneous_1 = require("../../utils/miscellaneous");
|
|
6
|
-
const config_1 = require("../fixtures/config");
|
|
7
|
-
const perf_hooks_1 = require("perf_hooks");
|
|
8
|
-
const wrapper_1 = require("../../wrapper");
|
|
9
|
-
const colorette_1 = require("colorette");
|
|
10
|
-
jest.mock('@redocly/openapi-core');
|
|
11
|
-
jest.mock('../../utils/miscellaneous');
|
|
12
|
-
jest.mock('perf_hooks');
|
|
13
|
-
jest.mock('../../utils/update-version-notifier', () => ({
|
|
14
|
-
version: '1.0.0',
|
|
15
|
-
}));
|
|
16
|
-
const argvMock = {
|
|
17
|
-
apis: ['openapi.yaml'],
|
|
18
|
-
'lint-config': 'off',
|
|
19
|
-
format: 'codeframe',
|
|
20
|
-
};
|
|
21
|
-
describe('handleLint', () => {
|
|
22
|
-
let processExitMock;
|
|
23
|
-
let exitCb;
|
|
24
|
-
const getMergedConfigMock = openapi_core_1.getMergedConfig;
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
27
|
-
perf_hooks_1.performance.now.mockImplementation(() => 42);
|
|
28
|
-
processExitMock = jest.spyOn(process, 'exit').mockImplementation();
|
|
29
|
-
jest.spyOn(process, 'once').mockImplementation((_e, cb) => {
|
|
30
|
-
exitCb = cb;
|
|
31
|
-
return process.on(_e, cb);
|
|
32
|
-
});
|
|
33
|
-
getMergedConfigMock.mockReturnValue(config_1.ConfigFixture);
|
|
34
|
-
openapi_core_1.doesYamlFileExist.mockImplementation((path) => path === 'redocly.yaml');
|
|
35
|
-
});
|
|
36
|
-
afterEach(() => {
|
|
37
|
-
getMergedConfigMock.mockReset();
|
|
38
|
-
});
|
|
39
|
-
describe('loadConfig and getEntrypoints stage', () => {
|
|
40
|
-
it('should fail if config file does not exist', async () => {
|
|
41
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({ ...argvMock, config: 'config.yaml' });
|
|
42
|
-
expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('Please provide a valid path to the configuration file.');
|
|
43
|
-
});
|
|
44
|
-
it('should call loadConfigAndHandleErrors and getFallbackApisOrExit', async () => {
|
|
45
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
46
|
-
expect(miscellaneous_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
|
|
47
|
-
configPath: undefined,
|
|
48
|
-
customExtends: undefined,
|
|
49
|
-
processRawConfig: undefined,
|
|
50
|
-
});
|
|
51
|
-
expect(miscellaneous_1.getFallbackApisOrExit).toHaveBeenCalled();
|
|
52
|
-
});
|
|
53
|
-
it('should call loadConfig with args if such exist', async () => {
|
|
54
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({
|
|
55
|
-
...argvMock,
|
|
56
|
-
config: 'redocly.yaml',
|
|
57
|
-
extends: ['some/path'],
|
|
58
|
-
});
|
|
59
|
-
expect(miscellaneous_1.loadConfigAndHandleErrors).toHaveBeenCalledWith({
|
|
60
|
-
configPath: 'redocly.yaml',
|
|
61
|
-
customExtends: ['some/path'],
|
|
62
|
-
processRawConfig: undefined,
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
it('should call mergedConfig with clear ignore if `generate-ignore-file` argv', async () => {
|
|
66
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({ ...argvMock, 'generate-ignore-file': true });
|
|
67
|
-
expect(getMergedConfigMock).toHaveBeenCalled();
|
|
68
|
-
});
|
|
69
|
-
it('should check if ruleset exist', async () => {
|
|
70
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
71
|
-
expect(miscellaneous_1.checkIfRulesetExist).toHaveBeenCalledTimes(1);
|
|
72
|
-
});
|
|
73
|
-
it('should fail if apis not provided', async () => {
|
|
74
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({ ...argvMock, apis: [] });
|
|
75
|
-
expect(miscellaneous_1.getFallbackApisOrExit).toHaveBeenCalledTimes(1);
|
|
76
|
-
expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith('No APIs were provided.');
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
describe('loop through entrypoints and lint stage', () => {
|
|
80
|
-
it('should call getMergedConfig and lint ', async () => {
|
|
81
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
82
|
-
expect(perf_hooks_1.performance.now).toHaveBeenCalled();
|
|
83
|
-
expect(getMergedConfigMock).toHaveBeenCalled();
|
|
84
|
-
expect(openapi_core_1.lint).toHaveBeenCalled();
|
|
85
|
-
});
|
|
86
|
-
it('should call skipRules,skipPreprocessors and addIgnore with argv', async () => {
|
|
87
|
-
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
88
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({
|
|
89
|
-
...argvMock,
|
|
90
|
-
'skip-preprocessor': ['preprocessor'],
|
|
91
|
-
'skip-rule': ['rule'],
|
|
92
|
-
'generate-ignore-file': true,
|
|
93
|
-
});
|
|
94
|
-
expect(config_1.ConfigFixture.styleguide.skipRules).toHaveBeenCalledWith(['rule']);
|
|
95
|
-
expect(config_1.ConfigFixture.styleguide.skipPreprocessors).toHaveBeenCalledWith(['preprocessor']);
|
|
96
|
-
});
|
|
97
|
-
it('should call formatProblems and getExecutionTime with argv', async () => {
|
|
98
|
-
openapi_core_1.lint.mockResolvedValueOnce(['problem']);
|
|
99
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)({ ...argvMock, 'max-problems': 2, format: 'stylish' });
|
|
100
|
-
expect(openapi_core_1.getTotals).toHaveBeenCalledWith(['problem']);
|
|
101
|
-
expect(openapi_core_1.formatProblems).toHaveBeenCalledWith(['problem'], {
|
|
102
|
-
format: 'stylish',
|
|
103
|
-
maxProblems: 2,
|
|
104
|
-
totals: { errors: 0 },
|
|
105
|
-
version: '1.0.0',
|
|
106
|
-
});
|
|
107
|
-
expect(miscellaneous_1.getExecutionTime).toHaveBeenCalledWith(42);
|
|
108
|
-
});
|
|
109
|
-
it('should catch error in handleError if something fails', async () => {
|
|
110
|
-
openapi_core_1.lint.mockRejectedValueOnce('error');
|
|
111
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
112
|
-
expect(miscellaneous_1.handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe('erros and warning handle after lint stage', () => {
|
|
116
|
-
it('should call printLintTotals and printLintTotals', async () => {
|
|
117
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
118
|
-
expect(miscellaneous_1.printUnusedWarnings).toHaveBeenCalled();
|
|
119
|
-
});
|
|
120
|
-
it('should call exit with 0 if no errors', async () => {
|
|
121
|
-
miscellaneous_1.loadConfigAndHandleErrors.mockImplementation(() => {
|
|
122
|
-
return { ...config_1.ConfigFixture };
|
|
123
|
-
});
|
|
124
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
125
|
-
await exitCb?.();
|
|
126
|
-
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
127
|
-
});
|
|
128
|
-
it('should exit with 1 if total errors > 0', async () => {
|
|
129
|
-
openapi_core_1.getTotals.mockReturnValueOnce({ errors: 1 });
|
|
130
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
131
|
-
await exitCb?.();
|
|
132
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
133
|
-
});
|
|
134
|
-
it('should use recommended fallback if no config', async () => {
|
|
135
|
-
openapi_core_1.getMergedConfig.mockImplementation(() => {
|
|
136
|
-
return {
|
|
137
|
-
styleguide: {
|
|
138
|
-
recommendedFallback: true,
|
|
139
|
-
rules: {},
|
|
140
|
-
skipRules: jest.fn(),
|
|
141
|
-
skipPreprocessors: jest.fn(),
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
await (0, wrapper_1.commandWrapper)(lint_1.handleLint)(argvMock);
|
|
146
|
-
expect(process.stderr.write).toHaveBeenCalledWith(`No configurations were provided -- using built in ${(0, colorette_1.blue)('recommended')} configuration by default.\n\n`);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|