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
25 changes: 25 additions & 0 deletions e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ describe('executor command', () => {
).rejects.toThrow('');
});

it('should execute print-config executor with output', async () => {
const cwd = path.join(testFileDir, 'execute-print-config-command');
await addTargetToWorkspace(tree, { cwd, project });

const { stdout, code } = await executeProcess({
command: 'npx',
args: [
'nx',
'run',
`${project}:code-pushup`,
'print-config',
'--output=code-pushup.config.json',
],
cwd,
});

expect(code).toBe(0);
const cleanStdout = removeColorCodes(stdout);
expect(cleanStdout).toContain('nx run my-lib:code-pushup print-config');

await expect(
readJsonFile(path.join(cwd, 'code-pushup.config.json')),
).resolves.not.toThrow();
});

it('should execute print-config executor with api key', async () => {
const cwd = path.join(testFileDir, 'execute-print-config-command');
await addTargetToWorkspace(tree, { cwd, project });
Expand Down
5 changes: 3 additions & 2 deletions packages/nx-plugin/src/executors/cli/executor.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ describe('runAutorunExecutor', () => {

it('should process executorOptions', async () => {
const output = await runAutorunExecutor(
{ persist: { filename: 'REPORT' } },
{ output: 'code-pushup.config.json', persist: { filename: 'REPORT' } },
executorContext('testing-utils'),
);
expect(output.success).toBe(true);
expect(output.command).toMatch('--persist.filename="REPORT"');
expect(output.command).toContain('--output="code-pushup.config.json"');
expect(output.command).toContain('--persist.filename="REPORT"');
});

it('should create command from context and options if no api key is set', async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/nx-plugin/src/executors/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
"type": "string",
"description": "Prefix for project name"
},
"output": {
"type": "string",
"description": "Config output path of print-config command"
},
"persist": {
"type": "object",
"properties": {
Expand Down
5 changes: 4 additions & 1 deletion packages/nx-plugin/src/executors/cli/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type {
ProjectExecutorOnlyOptions,
} from '../internal/types.js';

export type PrintConfigOptions = { output?: string };
export type PrintConfigCommandExecutorOptions = PrintConfigOptions;
export type AutorunCommandExecutorOnlyOptions = ProjectExecutorOnlyOptions &
CollectExecutorOnlyOptions &
GeneralExecutorOnlyOptions;
Expand All @@ -16,4 +18,5 @@ export type AutorunCommandExecutorOptions = Partial<
persist: Partial<PersistConfig>;
} & AutorunCommandExecutorOnlyOptions &
GlobalExecutorOptions
>;
> &
PrintConfigOptions;
11 changes: 11 additions & 0 deletions packages/nx-plugin/src/executors/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { NormalizedExecutorContext } from '../internal/context.js';
import type {
AutorunCommandExecutorOnlyOptions,
AutorunCommandExecutorOptions,
PrintConfigCommandExecutorOptions,
} from './schema.js';

export function parseAutorunExecutorOnlyOptions(
Expand All @@ -20,6 +21,15 @@ export function parseAutorunExecutorOnlyOptions(
};
}

export function parsePrintConfigExecutorOptions(
options: Partial<PrintConfigCommandExecutorOptions>,
): PrintConfigCommandExecutorOptions {
const { output } = options;
return {
...(output && { output }),
};
}

export function parseAutorunExecutorOptions(
options: Partial<AutorunCommandExecutorOptions>,
normalizedContext: NormalizedExecutorContext,
Expand All @@ -33,6 +43,7 @@ export function parseAutorunExecutorOptions(
);
const hasApiToken = uploadCfg?.apiKey != null;
return {
...parsePrintConfigExecutorOptions(options),
...parseAutorunExecutorOnlyOptions(options),
...globalConfig(options, normalizedContext),
persist: persistConfig({ projectPrefix, ...persist }, normalizedContext),
Expand Down
17 changes: 17 additions & 0 deletions packages/nx-plugin/src/executors/cli/utils.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@ import {
mergeExecutorOptions,
parseAutorunExecutorOnlyOptions,
parseAutorunExecutorOptions,
parsePrintConfigExecutorOptions,
} from './utils.js';

describe('parsePrintConfigExecutorOptions', () => {
it('should provide NO default output path', () => {
expect(parsePrintConfigExecutorOptions({})).toStrictEqual(
expect.not.objectContaining({ output: expect.anything() }),
);
});

it('should process given output path', () => {
expect(
parsePrintConfigExecutorOptions({ output: 'code-pushup.config.json' }),
).toStrictEqual(
expect.objectContaining({ output: 'code-pushup.config.json' }),
);
});
});

describe('parseAutorunExecutorOnlyOptions', () => {
it('should provide NO default projectPrefix', () => {
expect(parseAutorunExecutorOnlyOptions({})).toStrictEqual(
Expand Down
Loading