Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
statements: 84,
branches: 74,
functions: 84,
lines: 85,
lines: 84,
},
},
testMatch: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],
Expand Down
29 changes: 9 additions & 20 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
notifyUpdateCliVersion,
version,
} from './utils/update-version-notifier';
import { commandWrapper } from './wrapper';
import { type CommandArgs, commandWrapper } from './wrapper';
import { previewProject } from './commands/preview-project';
import { handleTranslations } from './commands/translations';
import { handleEject } from './commands/eject';
Expand All @@ -31,7 +31,7 @@ import type { Arguments } from 'yargs';
import type { OutputFormat, RuleSeverity } from '@redocly/openapi-core';
import type { BuildDocsArgv } from './commands/build-docs/types';
import type { PushStatusOptions } from './reunite/commands/push-status';
import type { PushArguments } from './types';
import type { CommandOptions, PushArguments } from './types';
import type { EjectOptions } from './commands/eject';

dotenv.config({ path: path.resolve(__dirname, '../.env') });
Expand Down Expand Up @@ -915,11 +915,6 @@ yargs
describe: 'JSON file output name',
type: 'string',
},
residency: {
describe: 'Residency of Reunite application. Defaults to US.',
type: 'string',
default: 'us',
},
'client-cert': {
describe: 'Mutual TLS client certificate',
type: 'string',
Expand Down Expand Up @@ -964,21 +959,15 @@ yargs
'Generate config with populated values from description using success criteria',
type: 'boolean',
},
residency: {
describe: 'Residency of Reunite application. Defaults to US.',
type: 'string',
default: 'us',
},
});
},
async (argv) => {
process.env.REDOCLY_CLI_COMMAND = 'generate-arazzo';
const { handleGenerate } = await import('@redocly/respect-core');
commandWrapper(
handleGenerate as (wrapperArgs: CommandArgs<CommandOptions>) => Promise<unknown>
)(argv);
}
// async (argv) => {
// try {
// await handleGenerate(argv as GenerateConfigFileArgv);
// } catch {
// logger.error(`❌ Auto config generation failed.`);
// process.exit(1);
// }
// },
)
.completion('completion', 'Generate autocomplete script for `redocly` command.')
.demandCommand(1)
Expand Down
26 changes: 18 additions & 8 deletions packages/respect-core/src/handlers/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ import { writeFileSync } from 'fs';
import { stringifyYaml } from '../utils/yaml';
import { generateTestConfig } from '../modules/test-config-generator';
import { DefaultLogger } from '../utils/logger/logger';
import { exitWithError } from '../utils/exit-with-error';
import { type CommandArgs } from '../types';

import type { GenerateConfigFileArgv } from '../types';
export type GenerateArazzoFileOptions = {
descriptionPath: string;
'output-file'?: string;
extended?: boolean;
};

const logger = DefaultLogger.getInstance();

export async function handleGenerate(argv: GenerateConfigFileArgv) {
logger.log(gray('\n Generating test configuration... \n'));
export async function handleGenerate({ argv }: CommandArgs<GenerateArazzoFileOptions>) {
try {
logger.log(gray('\n Generating test configuration... \n'));

const generatedConfig = await generateTestConfig(argv as GenerateConfigFileArgv);
const content = stringifyYaml(generatedConfig);
const generatedConfig = await generateTestConfig(argv);
const content = stringifyYaml(generatedConfig);

const fileName = argv?.outputFile || 'auto-generated.yaml';
writeFileSync(fileName, content);
const fileName = argv['output-file'] || 'auto-generated.arazzo.yaml';
writeFileSync(fileName, content);

logger.log('\n' + blue(`Config ${yellow(fileName)} successfully generated.`) + '\n');
logger.log('\n' + blue(`Config ${yellow(fileName)} successfully generated.`) + '\n');
} catch (_err) {
exitWithError('\n' + '❌ Auto config generation failed.');
}
}
23 changes: 4 additions & 19 deletions packages/respect-core/src/handlers/run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bgRed, red } from 'colorette';
import { red } from 'colorette';
import { type CollectFn } from '@redocly/openapi-core/src/utils';
import { runTestFile } from '../modules/flow-runner';
import {
displayErrors,
Expand All @@ -7,17 +8,8 @@ import {
calculateTotals,
} from '../modules/cli-output';
import { DefaultLogger } from '../utils/logger/logger';

import type { Config } from '@redocly/openapi-core';
import type { CollectFn } from '@redocly/openapi-core/src/utils';
import type { RunArgv } from '../types';

export type CommandArgs<T> = {
argv: T;
config: Config;
version: string;
collectSpecData?: CollectFn;
};
import { type CommandArgs, type RunArgv } from '../types';
import { exitWithError } from '../utils/exit-with-error';

export type RespectOptions = {
files: string[];
Expand All @@ -28,7 +20,6 @@ export type RespectOptions = {
verbose?: boolean;
'har-output'?: string;
'json-output'?: string;
residency?: string;
'client-cert'?: string;
'client-key'?: string;
'ca-cert'?: string;
Expand Down Expand Up @@ -113,9 +104,3 @@ async function runFile(

return { hasProblems, file: argv.file, workflows, argv };
}

const exitWithError = (message: string) => {
logger.error(bgRed(message));
logger.printNewLine();
throw new Error(message);
};
2 changes: 2 additions & 0 deletions packages/respect-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { handleGenerate, handleRun } from './handlers/index';
export type { GenerateArazzoFileOptions } from './handlers/generate';
export type { RespectOptions } from './handlers/run';
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ describe('createTestContext', () => {
const options: AppOptions = {
workflowPath: 'test.test.yaml',
workflow: undefined,
harLogsFile: 'har-output',
harOutput: 'har-output',
metadata: {},
verbose: false,
};
Expand Down Expand Up @@ -597,7 +597,7 @@ describe('createTestContext', () => {
input: JSON.stringify({ testInput: 'testValue' }),
workflow: undefined,
skip: undefined,
harLogsFile: 'har-output',
harOutput: 'har-output',
metadata: {},
verbose: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('generateTestConfig', () => {
expect(
await generateTestConfig({
descriptionPath: 'description.yaml',
outputFile: './final-test-location/output.yaml',
'output-file': './final-test-location/output.yaml',
extended: false,
})
).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function createTestContext(
secretFields: new Set<string>(),
mtlsCerts:
options.mutualTls?.clientCert || options.mutualTls?.clientKey || options.mutualTls?.caCert
? resolveMtlsCertificates(options.mutualTls)
? resolveMtlsCertificates(options.mutualTls, options.workflowPath)
: undefined,
severity: resolveSeverityConfiguration(options.severity),
apiClient,
Expand Down
14 changes: 7 additions & 7 deletions packages/respect-core/src/modules/flow-runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export async function runTestFile(
input,
skip,
server,
harOutput,
jsonOutput,
'har-output': harOutput,
'json-output': jsonOutput,
severity,
} = argv;

Expand All @@ -64,9 +64,9 @@ export async function runTestFile(
server,
severity,
mutualTls: {
clientCert: argv?.clientCert,
clientKey: argv?.clientKey,
caCert: argv?.caCert,
clientCert: argv['client-cert'],
clientKey: argv['client-key'],
caCert: argv['ca-cert'],
},
};

Expand Down Expand Up @@ -98,7 +98,7 @@ export async function runTestFile(
}

async function runWorkflows(testDescription: TestDescription, options: AppOptions) {
const harLogs = options.metadata?.harOutput && createHarLog();
const harLogs = options?.harOutput && createHarLog();
const apiClient = new ApiFetcher({
harLogs,
});
Expand All @@ -123,7 +123,7 @@ async function runWorkflows(testDescription: TestDescription, options: AppOption
}

// json logs should be composed after all workflows are run
const jsonLogs = options.jsonLogsFile ? composeJsonLogs(ctx) : undefined;
const jsonLogs = options.jsonOutput ? composeJsonLogs(ctx) : undefined;

return { ...ctx, harLogs, jsonLogs };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import * as path from 'path';
import { sortMethods } from '../../utils/sort';
import { bundleOpenApi } from '../description-parser';

import type {
OperationMethod,
TestDescription,
GenerateConfigFileArgv,
Workflow,
Step,
} from '../../types';
import type { OperationMethod, TestDescription, Workflow, Step } from '../../types';
import type { GenerateArazzoFileOptions } from '../../handlers/generate';

type WorkflowsFromDescriptionInput = {
descriptionPaths: any;
Expand Down Expand Up @@ -102,9 +97,9 @@ function resolveDescriptionNameFromPath(descriptionPath: string): string {

export async function generateTestConfig({
descriptionPath,
outputFile,
'output-file': outputFile,
extended,
}: GenerateConfigFileArgv) {
}: GenerateArazzoFileOptions) {
const { paths: pathsObject, info } = (await bundleOpenApi(descriptionPath, '')) || {};
const sourceDescriptionName = resolveDescriptionNameFromPath(descriptionPath);
const resolvedDescriptionPath = outputFile
Expand Down
30 changes: 13 additions & 17 deletions packages/respect-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import type { Faker } from './modules/faker';
import type { OperationDetails } from './modules/description-parser';
import type { RuleSeverity } from '@redocly/openapi-core/lib/config/types';
import type { ApiFetcher } from './utils/api-fetcher';
import type { RespectOptions } from './handlers/run';
import type { Config } from '@redocly/openapi-core';
import type { CollectFn } from '@redocly/openapi-core/src/utils';

export type OperationMethod = FromSchema<typeof operationMethod>;
export type ResponseContext = {
Expand Down Expand Up @@ -73,20 +76,19 @@ type AdditionalStepProps = {
};
export type Step = ArazzoStep & AdditionalStepProps;
export type Workflow = Omit<ArazzoWorkflow, 'steps'> & { steps: Step[]; time?: number };
export type RunArgv = {
export type RunArgv = Omit<RespectOptions, 'files'> & {
file: string;
testDescription?: TestDescription;
workflow?: string[];
skip?: string[];
verbose?: boolean;
harOutput?: string;
jsonOutput?: string;
input?: string | string[];
server?: string | string[];
severity?: string | string[];
clientCert?: NonNullable<TestContext['mtlsCerts']>['clientCert'];
clientKey?: NonNullable<TestContext['mtlsCerts']>['clientKey'];
caCert?: NonNullable<TestContext['mtlsCerts']>['caCert'];
};

export type CommandArgs<T> = {
argv: T;
config: Config;
version: string;
collectSpecData?: CollectFn;
};

export interface RequestContext {
Expand All @@ -108,8 +110,8 @@ export type AppOptions = {
workflow?: string | string[];
skip?: string | string[];
verbose?: boolean;
harLogsFile?: string;
jsonLogsFile?: string;
harOutput?: string;
jsonOutput?: string;
metadata?: Record<string, any>;
input?: string | string[];
server?: string | string[];
Expand Down Expand Up @@ -230,12 +232,6 @@ export type Check = {
additionalMessage?: string;
};

export type GenerateConfigFileArgv = {
descriptionPath: string;
outputFile?: string;
extended?: boolean;
};

export interface ResultsOfTests {
passed: number;
failed: number;
Expand Down
17 changes: 0 additions & 17 deletions packages/respect-core/src/utils/__tests__/get-reunite-url.test.ts

This file was deleted.

Loading
Loading