Skip to content

Commit 7b53bb0

Browse files
fix(nx-plugin): process output argument (#1105)
Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com>
1 parent 8040d3e commit 7b53bb0

File tree

6 files changed

+64
-3
lines changed

6 files changed

+64
-3
lines changed

e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,31 @@ describe('executor command', () => {
116116
).rejects.toThrow('');
117117
});
118118

119+
it('should execute print-config executor with output', async () => {
120+
const cwd = path.join(testFileDir, 'execute-print-config-command');
121+
await addTargetToWorkspace(tree, { cwd, project });
122+
123+
const { stdout, code } = await executeProcess({
124+
command: 'npx',
125+
args: [
126+
'nx',
127+
'run',
128+
`${project}:code-pushup`,
129+
'print-config',
130+
'--output=code-pushup.config.json',
131+
],
132+
cwd,
133+
});
134+
135+
expect(code).toBe(0);
136+
const cleanStdout = removeColorCodes(stdout);
137+
expect(cleanStdout).toContain('nx run my-lib:code-pushup print-config');
138+
139+
await expect(
140+
readJsonFile(path.join(cwd, 'code-pushup.config.json')),
141+
).resolves.not.toThrow();
142+
});
143+
119144
it('should execute print-config executor with api key', async () => {
120145
const cwd = path.join(testFileDir, 'execute-print-config-command');
121146
await addTargetToWorkspace(tree, { cwd, project });

packages/nx-plugin/src/executors/cli/executor.unit.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ describe('runAutorunExecutor', () => {
8080

8181
it('should process executorOptions', async () => {
8282
const output = await runAutorunExecutor(
83-
{ persist: { filename: 'REPORT' } },
83+
{ output: 'code-pushup.config.json', persist: { filename: 'REPORT' } },
8484
executorContext('testing-utils'),
8585
);
8686
expect(output.success).toBe(true);
87-
expect(output.command).toMatch('--persist.filename="REPORT"');
87+
expect(output.command).toContain('--output="code-pushup.config.json"');
88+
expect(output.command).toContain('--persist.filename="REPORT"');
8889
});
8990

9091
it('should create command from context and options if no api key is set', async () => {

packages/nx-plugin/src/executors/cli/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
"type": "string",
4545
"description": "Prefix for project name"
4646
},
47+
"output": {
48+
"type": "string",
49+
"description": "Config output path of print-config command"
50+
},
4751
"persist": {
4852
"type": "object",
4953
"properties": {

packages/nx-plugin/src/executors/cli/schema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type {
66
ProjectExecutorOnlyOptions,
77
} from '../internal/types.js';
88

9+
export type PrintConfigOptions = { output?: string };
10+
export type PrintConfigCommandExecutorOptions = PrintConfigOptions;
911
export type AutorunCommandExecutorOnlyOptions = ProjectExecutorOnlyOptions &
1012
CollectExecutorOnlyOptions &
1113
GeneralExecutorOnlyOptions;
@@ -16,4 +18,5 @@ export type AutorunCommandExecutorOptions = Partial<
1618
persist: Partial<PersistConfig>;
1719
} & AutorunCommandExecutorOnlyOptions &
1820
GlobalExecutorOptions
19-
>;
21+
> &
22+
PrintConfigOptions;

packages/nx-plugin/src/executors/cli/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { NormalizedExecutorContext } from '../internal/context.js';
77
import type {
88
AutorunCommandExecutorOnlyOptions,
99
AutorunCommandExecutorOptions,
10+
PrintConfigCommandExecutorOptions,
1011
} from './schema.js';
1112

1213
export function parseAutorunExecutorOnlyOptions(
@@ -20,6 +21,15 @@ export function parseAutorunExecutorOnlyOptions(
2021
};
2122
}
2223

24+
export function parsePrintConfigExecutorOptions(
25+
options: Partial<PrintConfigCommandExecutorOptions>,
26+
): PrintConfigCommandExecutorOptions {
27+
const { output } = options;
28+
return {
29+
...(output && { output }),
30+
};
31+
}
32+
2333
export function parseAutorunExecutorOptions(
2434
options: Partial<AutorunCommandExecutorOptions>,
2535
normalizedContext: NormalizedExecutorContext,
@@ -33,6 +43,7 @@ export function parseAutorunExecutorOptions(
3343
);
3444
const hasApiToken = uploadCfg?.apiKey != null;
3545
return {
46+
...parsePrintConfigExecutorOptions(options),
3647
...parseAutorunExecutorOnlyOptions(options),
3748
...globalConfig(options, normalizedContext),
3849
persist: persistConfig({ projectPrefix, ...persist }, normalizedContext),

packages/nx-plugin/src/executors/cli/utils.unit.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,25 @@ import {
55
mergeExecutorOptions,
66
parseAutorunExecutorOnlyOptions,
77
parseAutorunExecutorOptions,
8+
parsePrintConfigExecutorOptions,
89
} from './utils.js';
910

11+
describe('parsePrintConfigExecutorOptions', () => {
12+
it('should provide NO default output path', () => {
13+
expect(parsePrintConfigExecutorOptions({})).toStrictEqual(
14+
expect.not.objectContaining({ output: expect.anything() }),
15+
);
16+
});
17+
18+
it('should process given output path', () => {
19+
expect(
20+
parsePrintConfigExecutorOptions({ output: 'code-pushup.config.json' }),
21+
).toStrictEqual(
22+
expect.objectContaining({ output: 'code-pushup.config.json' }),
23+
);
24+
});
25+
});
26+
1027
describe('parseAutorunExecutorOnlyOptions', () => {
1128
it('should provide NO default projectPrefix', () => {
1229
expect(parseAutorunExecutorOnlyOptions({})).toStrictEqual(

0 commit comments

Comments
 (0)