@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,190 +0,0 @@
|
|
|
1
|
-
import { handleLint, LintOptions } from '../../commands/lint';
|
|
2
|
-
import {
|
|
3
|
-
getMergedConfig,
|
|
4
|
-
lint,
|
|
5
|
-
getTotals,
|
|
6
|
-
formatProblems,
|
|
7
|
-
doesYamlFileExist,
|
|
8
|
-
} from '@redocly/openapi-core';
|
|
9
|
-
import {
|
|
10
|
-
getFallbackApisOrExit,
|
|
11
|
-
getExecutionTime,
|
|
12
|
-
printUnusedWarnings,
|
|
13
|
-
handleError,
|
|
14
|
-
exitWithError,
|
|
15
|
-
loadConfigAndHandleErrors,
|
|
16
|
-
checkIfRulesetExist,
|
|
17
|
-
} from '../../utils/miscellaneous';
|
|
18
|
-
import { ConfigFixture } from '../fixtures/config';
|
|
19
|
-
import { performance } from 'perf_hooks';
|
|
20
|
-
import { commandWrapper } from '../../wrapper';
|
|
21
|
-
import { Arguments } from 'yargs';
|
|
22
|
-
import { blue } from 'colorette';
|
|
23
|
-
|
|
24
|
-
jest.mock('@redocly/openapi-core');
|
|
25
|
-
jest.mock('../../utils/miscellaneous');
|
|
26
|
-
jest.mock('perf_hooks');
|
|
27
|
-
|
|
28
|
-
jest.mock('../../utils/update-version-notifier', () => ({
|
|
29
|
-
version: '1.0.0',
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
const argvMock = {
|
|
33
|
-
apis: ['openapi.yaml'],
|
|
34
|
-
'lint-config': 'off',
|
|
35
|
-
format: 'codeframe',
|
|
36
|
-
} as Arguments<LintOptions>;
|
|
37
|
-
|
|
38
|
-
describe('handleLint', () => {
|
|
39
|
-
let processExitMock: jest.SpyInstance;
|
|
40
|
-
let exitCb: any;
|
|
41
|
-
const getMergedConfigMock = getMergedConfig as jest.Mock<any, any>;
|
|
42
|
-
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
45
|
-
(performance.now as jest.Mock<any, any>).mockImplementation(() => 42);
|
|
46
|
-
processExitMock = jest.spyOn(process, 'exit').mockImplementation();
|
|
47
|
-
jest.spyOn(process, 'once').mockImplementation((_e, cb) => {
|
|
48
|
-
exitCb = cb;
|
|
49
|
-
return process.on(_e, cb);
|
|
50
|
-
});
|
|
51
|
-
getMergedConfigMock.mockReturnValue(ConfigFixture);
|
|
52
|
-
(doesYamlFileExist as jest.Mock<any, any>).mockImplementation(
|
|
53
|
-
(path) => path === 'redocly.yaml'
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
afterEach(() => {
|
|
58
|
-
getMergedConfigMock.mockReset();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('loadConfig and getEntrypoints stage', () => {
|
|
62
|
-
it('should fail if config file does not exist', async () => {
|
|
63
|
-
await commandWrapper(handleLint)({ ...argvMock, config: 'config.yaml' });
|
|
64
|
-
expect(exitWithError).toHaveBeenCalledWith(
|
|
65
|
-
'Please provide a valid path to the configuration file.'
|
|
66
|
-
);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should call loadConfigAndHandleErrors and getFallbackApisOrExit', async () => {
|
|
70
|
-
await commandWrapper(handleLint)(argvMock);
|
|
71
|
-
expect(loadConfigAndHandleErrors).toHaveBeenCalledWith({
|
|
72
|
-
configPath: undefined,
|
|
73
|
-
customExtends: undefined,
|
|
74
|
-
processRawConfig: undefined,
|
|
75
|
-
});
|
|
76
|
-
expect(getFallbackApisOrExit).toHaveBeenCalled();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should call loadConfig with args if such exist', async () => {
|
|
80
|
-
await commandWrapper(handleLint)({
|
|
81
|
-
...argvMock,
|
|
82
|
-
config: 'redocly.yaml',
|
|
83
|
-
extends: ['some/path'],
|
|
84
|
-
});
|
|
85
|
-
expect(loadConfigAndHandleErrors).toHaveBeenCalledWith({
|
|
86
|
-
configPath: 'redocly.yaml',
|
|
87
|
-
customExtends: ['some/path'],
|
|
88
|
-
processRawConfig: undefined,
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should call mergedConfig with clear ignore if `generate-ignore-file` argv', async () => {
|
|
93
|
-
await commandWrapper(handleLint)({ ...argvMock, 'generate-ignore-file': true });
|
|
94
|
-
expect(getMergedConfigMock).toHaveBeenCalled();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should check if ruleset exist', async () => {
|
|
98
|
-
await commandWrapper(handleLint)(argvMock);
|
|
99
|
-
expect(checkIfRulesetExist).toHaveBeenCalledTimes(1);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should fail if apis not provided', async () => {
|
|
103
|
-
await commandWrapper(handleLint)({ ...argvMock, apis: [] });
|
|
104
|
-
expect(getFallbackApisOrExit).toHaveBeenCalledTimes(1);
|
|
105
|
-
expect(exitWithError).toHaveBeenCalledWith('No APIs were provided.');
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('loop through entrypoints and lint stage', () => {
|
|
110
|
-
it('should call getMergedConfig and lint ', async () => {
|
|
111
|
-
await commandWrapper(handleLint)(argvMock);
|
|
112
|
-
expect(performance.now).toHaveBeenCalled();
|
|
113
|
-
expect(getMergedConfigMock).toHaveBeenCalled();
|
|
114
|
-
expect(lint).toHaveBeenCalled();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should call skipRules,skipPreprocessors and addIgnore with argv', async () => {
|
|
118
|
-
(lint as jest.Mock<any, any>).mockResolvedValueOnce(['problem']);
|
|
119
|
-
await commandWrapper(handleLint)({
|
|
120
|
-
...argvMock,
|
|
121
|
-
'skip-preprocessor': ['preprocessor'],
|
|
122
|
-
'skip-rule': ['rule'],
|
|
123
|
-
'generate-ignore-file': true,
|
|
124
|
-
});
|
|
125
|
-
expect(ConfigFixture.styleguide.skipRules).toHaveBeenCalledWith(['rule']);
|
|
126
|
-
expect(ConfigFixture.styleguide.skipPreprocessors).toHaveBeenCalledWith(['preprocessor']);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should call formatProblems and getExecutionTime with argv', async () => {
|
|
130
|
-
(lint as jest.Mock<any, any>).mockResolvedValueOnce(['problem']);
|
|
131
|
-
await commandWrapper(handleLint)({ ...argvMock, 'max-problems': 2, format: 'stylish' });
|
|
132
|
-
expect(getTotals).toHaveBeenCalledWith(['problem']);
|
|
133
|
-
expect(formatProblems).toHaveBeenCalledWith(['problem'], {
|
|
134
|
-
format: 'stylish',
|
|
135
|
-
maxProblems: 2,
|
|
136
|
-
totals: { errors: 0 },
|
|
137
|
-
version: '1.0.0',
|
|
138
|
-
});
|
|
139
|
-
expect(getExecutionTime).toHaveBeenCalledWith(42);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should catch error in handleError if something fails', async () => {
|
|
143
|
-
(lint as jest.Mock<any, any>).mockRejectedValueOnce('error');
|
|
144
|
-
await commandWrapper(handleLint)(argvMock);
|
|
145
|
-
expect(handleError).toHaveBeenCalledWith('error', 'openapi.yaml');
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe('erros and warning handle after lint stage', () => {
|
|
150
|
-
it('should call printLintTotals and printLintTotals', async () => {
|
|
151
|
-
await commandWrapper(handleLint)(argvMock);
|
|
152
|
-
expect(printUnusedWarnings).toHaveBeenCalled();
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('should call exit with 0 if no errors', async () => {
|
|
156
|
-
(loadConfigAndHandleErrors as jest.Mock).mockImplementation(() => {
|
|
157
|
-
return { ...ConfigFixture };
|
|
158
|
-
});
|
|
159
|
-
await commandWrapper(handleLint)(argvMock);
|
|
160
|
-
await exitCb?.();
|
|
161
|
-
expect(processExitMock).toHaveBeenCalledWith(0);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('should exit with 1 if total errors > 0', async () => {
|
|
165
|
-
(getTotals as jest.Mock<any, any>).mockReturnValueOnce({ errors: 1 });
|
|
166
|
-
await commandWrapper(handleLint)(argvMock);
|
|
167
|
-
await exitCb?.();
|
|
168
|
-
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('should use recommended fallback if no config', async () => {
|
|
172
|
-
(getMergedConfig as jest.Mock).mockImplementation(() => {
|
|
173
|
-
return {
|
|
174
|
-
styleguide: {
|
|
175
|
-
recommendedFallback: true,
|
|
176
|
-
rules: {},
|
|
177
|
-
skipRules: jest.fn(),
|
|
178
|
-
skipPreprocessors: jest.fn(),
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
});
|
|
182
|
-
await commandWrapper(handleLint)(argvMock);
|
|
183
|
-
expect(process.stderr.write).toHaveBeenCalledWith(
|
|
184
|
-
`No configurations were provided -- using built in ${blue(
|
|
185
|
-
'recommended'
|
|
186
|
-
)} configuration by default.\n\n`
|
|
187
|
-
);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
});
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { getMergedConfig } from '@redocly/openapi-core';
|
|
2
|
-
import { handlePush } from '../../commands/push';
|
|
3
|
-
import { promptClientToken } from '../../commands/auth';
|
|
4
|
-
import { ConfigFixture } from '../fixtures/config';
|
|
5
|
-
import { Readable } from 'node:stream';
|
|
6
|
-
|
|
7
|
-
// Mock fs operations
|
|
8
|
-
jest.mock('fs', () => ({
|
|
9
|
-
...jest.requireActual('fs'),
|
|
10
|
-
createReadStream: () => {
|
|
11
|
-
const readable = new Readable();
|
|
12
|
-
readable.push('test data');
|
|
13
|
-
readable.push(null);
|
|
14
|
-
return readable;
|
|
15
|
-
},
|
|
16
|
-
statSync: () => ({ size: 9 }),
|
|
17
|
-
readFileSync: () => Buffer.from('test data'),
|
|
18
|
-
existsSync: () => false,
|
|
19
|
-
readdirSync: () => [],
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
(getMergedConfig as jest.Mock).mockImplementation((config) => config);
|
|
23
|
-
|
|
24
|
-
// Mock OpenAPI core
|
|
25
|
-
jest.mock('@redocly/openapi-core');
|
|
26
|
-
jest.mock('../../commands/auth');
|
|
27
|
-
jest.mock('../../utils/miscellaneous');
|
|
28
|
-
|
|
29
|
-
const mockPromptClientToken = promptClientToken as jest.MockedFunction<typeof promptClientToken>;
|
|
30
|
-
|
|
31
|
-
describe('push-with-region', () => {
|
|
32
|
-
const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
|
|
33
|
-
redoclyClient.isAuthorizedWithRedoclyByRegion = jest.fn().mockResolvedValue(false);
|
|
34
|
-
|
|
35
|
-
const originalFetch = fetch;
|
|
36
|
-
|
|
37
|
-
beforeAll(() => {
|
|
38
|
-
// Mock global fetch
|
|
39
|
-
global.fetch = jest.fn(() =>
|
|
40
|
-
Promise.resolve({
|
|
41
|
-
ok: true,
|
|
42
|
-
status: 200,
|
|
43
|
-
json: () => Promise.resolve({}),
|
|
44
|
-
headers: new Headers(),
|
|
45
|
-
statusText: 'OK',
|
|
46
|
-
redirected: false,
|
|
47
|
-
type: 'default',
|
|
48
|
-
url: '',
|
|
49
|
-
clone: () => ({} as Response),
|
|
50
|
-
body: new ReadableStream(),
|
|
51
|
-
bodyUsed: false,
|
|
52
|
-
arrayBuffer: async () => new ArrayBuffer(0),
|
|
53
|
-
blob: async () => new Blob(),
|
|
54
|
-
formData: async () => new FormData(),
|
|
55
|
-
text: async () => '',
|
|
56
|
-
} as Response)
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
afterAll(() => {
|
|
61
|
-
global.fetch = originalFetch;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
beforeEach(() => {
|
|
65
|
-
jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should call login with default domain when region is US', async () => {
|
|
69
|
-
redoclyClient.domain = 'redocly.com';
|
|
70
|
-
await handlePush({
|
|
71
|
-
argv: {
|
|
72
|
-
upsert: true,
|
|
73
|
-
api: 'spec.json',
|
|
74
|
-
destination: '@org/my-api@1.0.0',
|
|
75
|
-
branchName: 'test',
|
|
76
|
-
},
|
|
77
|
-
config: ConfigFixture as any,
|
|
78
|
-
version: 'cli-version',
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
expect(mockPromptClientToken).toBeCalledTimes(1);
|
|
82
|
-
expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should call login with EU domain when region is EU', async () => {
|
|
86
|
-
redoclyClient.domain = 'eu.redocly.com';
|
|
87
|
-
// Update config for EU region
|
|
88
|
-
const euConfig = { ...ConfigFixture, region: 'eu' };
|
|
89
|
-
|
|
90
|
-
await handlePush({
|
|
91
|
-
argv: {
|
|
92
|
-
upsert: true,
|
|
93
|
-
api: 'spec.json',
|
|
94
|
-
destination: '@org/my-api@1.0.0',
|
|
95
|
-
branchName: 'test',
|
|
96
|
-
},
|
|
97
|
-
config: euConfig as any,
|
|
98
|
-
version: 'cli-version',
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
expect(mockPromptClientToken).toBeCalledTimes(1);
|
|
102
|
-
expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
|
|
103
|
-
});
|
|
104
|
-
});
|