Skip to content

Commit 8be5833

Browse files
committed
refactor: fix upload config handling
1 parent dee46b3 commit 8be5833

File tree

4 files changed

+77
-17
lines changed

4 files changed

+77
-17
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ async function addTargetToWorkspace(
4747
codeStrings: 'customPlugin()',
4848
},
4949
],
50-
// The upload test is skipped as it requires the @code-pushup/portal-client dependency
51-
upload: {
52-
server: 'https://dummy-server.dev',
53-
organization: 'dummy-organization',
54-
apiKey: 'dummy-api-key',
55-
project: 'dummy-project',
56-
},
5750
});
5851
await materializeTree(tree, cwd);
5952
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ export function parseAutorunExecutorOptions(
2020
options: Partial<AutorunCommandExecutorOptions>,
2121
normalizedContext: NormalizedExecutorContext,
2222
): AutorunCommandExecutorOptions {
23-
const { projectPrefix, persist, upload } = options;
23+
const { projectPrefix, persist, upload, command } = options;
24+
const needsUploadParams =
25+
command === 'upload' || command === 'autorun' || command === undefined;
2426
return {
2527
...parseAutorunExecutorOnlyOptions(options),
2628
...globalConfig(options, normalizedContext),
2729
persist: persistConfig({ projectPrefix, ...persist }, normalizedContext),
28-
upload: uploadConfig({ projectPrefix, ...upload }, normalizedContext),
30+
// @TODO This is a hack to avoid validation errors of upload config for commands that dont need it.
31+
// Fix: use utils and execute the core logic directly
32+
// Blocked by Nx plugins can't compile to es6
33+
upload: needsUploadParams
34+
? uploadConfig({ projectPrefix, ...upload }, normalizedContext)
35+
: undefined,
2936
};
3037
}

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type MockInstance, expect, vi } from 'vitest';
22
import { osAgnosticPath } from '@code-pushup/test-utils';
3+
import type { Command } from '../internal/types';
34
import {
45
parseAutorunExecutorOnlyOptions,
56
parseAutorunExecutorOptions,
@@ -93,4 +94,62 @@ describe('parseAutorunExecutorOptions', () => {
9394
osAgnosticPath('workspaceRoot/.code-pushup/my-app'),
9495
);
9596
});
97+
98+
it.each<Command | undefined>(['upload', 'autorun', undefined])(
99+
'should include upload config for command %s',
100+
command => {
101+
const projectName = 'my-app';
102+
const executorOptions = parseAutorunExecutorOptions(
103+
{
104+
command,
105+
upload: {
106+
organization: 'code-pushup',
107+
},
108+
},
109+
{
110+
projectName,
111+
workspaceRoot: 'workspaceRoot',
112+
projectConfig: {
113+
name: 'my-app',
114+
root: 'root',
115+
},
116+
},
117+
);
118+
119+
expect(executorOptions).toEqual(
120+
expect.objectContaining({
121+
upload: expect.any(Object),
122+
}),
123+
);
124+
},
125+
);
126+
127+
it.each<Command>(['collect'])(
128+
'should not include upload config for command %s',
129+
command => {
130+
const projectName = 'my-app';
131+
const executorOptions = parseAutorunExecutorOptions(
132+
{
133+
command,
134+
upload: {
135+
organization: 'code-pushup',
136+
},
137+
},
138+
{
139+
projectName,
140+
workspaceRoot: 'workspaceRoot',
141+
projectConfig: {
142+
name: 'my-app',
143+
root: 'root',
144+
},
145+
},
146+
);
147+
148+
expect(executorOptions).toEqual(
149+
expect.not.objectContaining({
150+
upload: expect.any(Object),
151+
}),
152+
);
153+
},
154+
);
96155
});

packages/nx-plugin/src/executors/internal/types.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ export type ProjectExecutorOnlyOptions = {
1919
/**
2020
* CLI types that apply globally for all commands.
2121
*/
22+
export type Command =
23+
| 'collect'
24+
| 'upload'
25+
| 'autorun'
26+
| 'print-config'
27+
| 'compare'
28+
| 'merge-diffs'
29+
| 'history';
2230
export type GlobalExecutorOptions = {
23-
command?:
24-
| 'collect'
25-
| 'upload'
26-
| 'autorun'
27-
| 'print-config'
28-
| 'compare'
29-
| 'merge-diffs'
30-
| 'history';
31+
command?: Command;
3132
bin?: string;
3233
verbose?: boolean;
3334
progress?: boolean;

0 commit comments

Comments
 (0)