Skip to content

Commit f653376

Browse files
committed
fix(nx-plugin): adjust upload config handling
1 parent fc53905 commit f653376

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ describe('runAutorunExecutor', () => {
6969
expect(output.command).toMatch('--persist.filename="REPORT"');
7070
});
7171

72-
it('should create command from context, options and arguments', async () => {
73-
envSpy.mockReturnValue({ CP_PROJECT: 'CLI' });
72+
it('should create command from context, options and arguments if APIkey is set', async () => {
73+
envSpy.mockReturnValue({ CP_PROJECT: 'CLI', CP_API_KEY: '123456789' });
7474
const output = await runAutorunExecutor(
7575
{ persist: { filename: 'REPORT', format: ['md', 'json'] } },
7676
executorContext('core'),
@@ -80,6 +80,20 @@ describe('runAutorunExecutor', () => {
8080
'--persist.format="md" --persist.format="json"',
8181
);
8282
expect(output.command).toMatch('--upload.project="CLI"');
83+
expect(output.command).toMatch('--upload.apiKey="123456789"');
84+
});
85+
86+
it('should create command from context, options and arguments without upload if APIkey is not set', async () => {
87+
envSpy.mockReturnValue({ CP_PROJECT: 'CLI' });
88+
const output = await runAutorunExecutor(
89+
{ persist: { filename: 'REPORT', format: ['md', 'json'] } },
90+
executorContext('core'),
91+
);
92+
expect(output.command).toMatch('--persist.filename="REPORT"');
93+
expect(output.command).toMatch(
94+
'--persist.format="md" --persist.format="json"',
95+
);
96+
expect(output.command).not.toMatch('--upload.project="CLI"');
8397
});
8498

8599
it('should log information if verbose is set', async () => {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ export function parseAutorunExecutorOptions(
2727
const { projectPrefix, persist, upload, command } = options;
2828
const needsUploadParams =
2929
command === 'upload' || command === 'autorun' || command === undefined;
30+
const uploadCfg = uploadConfig(
31+
{ projectPrefix, ...upload },
32+
normalizedContext,
33+
);
34+
const hasApiToken = uploadCfg?.apiKey != null;
3035
return {
3136
...parseAutorunExecutorOnlyOptions(options),
3237
...globalConfig(options, normalizedContext),
3338
persist: persistConfig({ projectPrefix, ...persist }, normalizedContext),
3439
// @TODO This is a hack to avoid validation errors of upload config for commands that dont need it.
3540
// Fix: use utils and execute the core logic directly
3641
// Blocked by Nx plugins can't compile to es6
37-
upload: needsUploadParams
38-
? uploadConfig({ projectPrefix, ...upload }, normalizedContext)
39-
: undefined,
42+
...(needsUploadParams && hasApiToken ? { upload: uploadCfg } : {}),
4043
};
4144
}
4245

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ describe('parseAutorunExecutorOptions', () => {
8080
expect.objectContaining({
8181
progress: false,
8282
verbose: false,
83-
upload: { project: projectName },
8483
}),
8584
);
8685

@@ -98,14 +97,14 @@ describe('parseAutorunExecutorOptions', () => {
9897
});
9998

10099
it.each<Command | undefined>(['upload', 'autorun', undefined])(
101-
'should include upload config for command %s',
100+
'should include upload config for command %s if API key is provided',
102101
command => {
103102
const projectName = 'my-app';
104103
const executorOptions = parseAutorunExecutorOptions(
105104
{
106105
command,
107106
upload: {
108-
organization: 'code-pushup',
107+
apiKey: '123456789',
109108
},
110109
},
111110
{

0 commit comments

Comments
 (0)