Skip to content

Commit 2787b89

Browse files
author
Michael Hladky
committed
refactor: wip
1 parent 2eb3abd commit 2787b89

File tree

9 files changed

+58
-61
lines changed

9 files changed

+58
-61
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { afterEach, expect, vi } from 'vitest';
22
import { executorContext } from '@code-pushup/test-nx-utils';
33
import * as executeProcessModule from '../../internal/execute-process.js';
4-
import runAutorunExecutor from './executor.js';
4+
import runCliExecutor from './executor.js';
55
import * as utils from './utils.js';
66

7-
describe('runAutorunExecutor', () => {
8-
const parseAutorunExecutorOptionsSpy = vi.spyOn(
9-
utils,
10-
'parseAutorunExecutorOptions',
11-
);
7+
describe('runCliExecutor', () => {
8+
const parseCliExecutorOptionsSpy = vi.spyOn(utils, 'parseCliExecutorOptions');
129
const executeProcessSpy = vi.spyOn(executeProcessModule, 'executeProcess');
1310

1411
beforeEach(() => {
@@ -22,22 +19,22 @@ describe('runAutorunExecutor', () => {
2219
});
2320

2421
afterEach(() => {
25-
parseAutorunExecutorOptionsSpy.mockRestore();
22+
parseCliExecutorOptionsSpy.mockRestore();
2623
executeProcessSpy.mockReset();
2724
});
2825

2926
it('should normalize context, parse CLI options and execute command', async () => {
3027
expect(process.env).not.toHaveProperty('CP_VERBOSE', 'true');
31-
const output = await runAutorunExecutor(
28+
const output = await runCliExecutor(
3229
{ verbose: true },
3330
executorContext('utils'),
3431
);
3532
expect(output.success).toBe(true);
3633

37-
expect(parseAutorunExecutorOptionsSpy).toHaveBeenCalledTimes(1);
34+
expect(parseCliExecutorOptionsSpy).toHaveBeenCalledTimes(1);
3835

3936
//is context normalized
40-
expect(parseAutorunExecutorOptionsSpy).toHaveBeenCalledWith(
37+
expect(parseCliExecutorOptionsSpy).toHaveBeenCalledWith(
4138
{ verbose: true },
4239
expect.objectContaining({
4340
projectConfig: expect.objectContaining({ name: 'utils' }),
@@ -52,7 +49,7 @@ describe('runAutorunExecutor', () => {
5249
});
5350

5451
it('should forward env options to executeProcess', async () => {
55-
const output = await runAutorunExecutor(
52+
const output = await runCliExecutor(
5653
{
5754
verbose: true,
5855
env: { TEST_VALUE: '42' },

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { ExecutorContext } from '@nx/devkit';
22
import { executeProcess } from '../../internal/execute-process.js';
33
import { normalizeContext } from '../internal/context.js';
4-
import type { AutorunCommandExecutorOptions } from './schema.js';
5-
import { parseAutorunExecutorOptions } from './utils.js';
4+
import type { CliCommandExecutorOptions } from './schema.js';
5+
import { parseCliExecutorOptions } from './utils.js';
66

77
export type ExecutorOutput = {
88
success: boolean;
@@ -11,14 +11,14 @@ export type ExecutorOutput = {
1111
};
1212

1313
/* eslint-disable-next-line max-lines-per-function */
14-
export default async function runAutorunExecutor(
15-
terminalAndExecutorOptions: AutorunCommandExecutorOptions,
14+
export default async function runCliExecutor(
15+
terminalAndExecutorOptions: CliCommandExecutorOptions,
1616
context: ExecutorContext,
1717
): Promise<ExecutorOutput> {
1818
const { objectToCliArgs, formatCommandStatus, logger, stringifyError } =
1919
await import('@code-pushup/utils');
2020
const normalizedContext = normalizeContext(context);
21-
const cliArgumentObject = parseAutorunExecutorOptions(
21+
const cliArgumentObject = parseCliExecutorOptions(
2222
terminalAndExecutorOptions,
2323
normalizedContext,
2424
);

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { afterAll, afterEach, beforeEach, expect, vi } from 'vitest';
22
import { executorContext } from '@code-pushup/test-nx-utils';
33
import { MEMFS_VOLUME } from '@code-pushup/test-utils';
44
import * as executeProcessModule from '../../internal/execute-process.js';
5-
import runAutorunExecutor from './executor.js';
5+
import runCliExecutor from './executor.js';
66

7-
describe('runAutorunExecutor', () => {
7+
describe('runCliExecutor', () => {
88
const processEnvCP = Object.fromEntries(
99
Object.entries(process.env).filter(([k]) => k.startsWith('CP_')),
1010
);
@@ -41,7 +41,7 @@ describe('runAutorunExecutor', () => {
4141
});
4242

4343
it('should call executeProcess with return result', async () => {
44-
const output = await runAutorunExecutor({}, executorContext('utils'));
44+
const output = await runCliExecutor({}, executorContext('utils'));
4545
expect(output.success).toBe(true);
4646
expect(output.command).toMatch('npx @code-pushup/cli');
4747
expect(executeProcessSpy).toHaveBeenCalledWith({
@@ -52,7 +52,7 @@ describe('runAutorunExecutor', () => {
5252
});
5353

5454
it('should normalize context', async () => {
55-
const output = await runAutorunExecutor(
55+
const output = await runCliExecutor(
5656
{},
5757
{
5858
...executorContext('utils'),
@@ -70,7 +70,7 @@ describe('runAutorunExecutor', () => {
7070
});
7171

7272
it('should process executorOptions', async () => {
73-
const output = await runAutorunExecutor(
73+
const output = await runCliExecutor(
7474
{ output: 'code-pushup.config.json', persist: { filename: 'REPORT' } },
7575
executorContext('testing-utils'),
7676
);
@@ -80,7 +80,7 @@ describe('runAutorunExecutor', () => {
8080
});
8181

8282
it('should create command from context and options if no api key is set', async () => {
83-
const output = await runAutorunExecutor(
83+
const output = await runCliExecutor(
8484
{ persist: { filename: 'REPORT', format: ['md', 'json'] } },
8585
executorContext('core'),
8686
);
@@ -92,7 +92,7 @@ describe('runAutorunExecutor', () => {
9292

9393
it('should create command from context, options and arguments if api key is set', async () => {
9494
vi.stubEnv('CP_API_KEY', 'cp_1234567');
95-
const output = await runAutorunExecutor(
95+
const output = await runCliExecutor(
9696
{
9797
persist: { filename: 'REPORT', format: ['md', 'json'] },
9898
upload: { project: 'CLI' },
@@ -108,7 +108,7 @@ describe('runAutorunExecutor', () => {
108108
});
109109

110110
it('should set env var information if verbose is set', async () => {
111-
const output = await runAutorunExecutor(
111+
const output = await runCliExecutor(
112112
{
113113
verbose: true,
114114
},
@@ -133,7 +133,7 @@ describe('runAutorunExecutor', () => {
133133
});
134134

135135
it('should log CP_VERBOSE env var in dryRun information if verbose is set', async () => {
136-
const output = await runAutorunExecutor(
136+
const output = await runCliExecutor(
137137
{
138138
dryRun: true,
139139
verbose: true,
@@ -151,7 +151,7 @@ describe('runAutorunExecutor', () => {
151151
});
152152

153153
it('should log command if dryRun is set', async () => {
154-
await runAutorunExecutor({ dryRun: true }, executorContext('utils'));
154+
await runCliExecutor({ dryRun: true }, executorContext('utils'));
155155

156156
expect(logger.command).toHaveBeenCalledTimes(0);
157157
expect(logger.warn).toHaveBeenCalledTimes(1);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json-schema.org/schema",
3-
"$id": "AutorunExecutorOptions",
3+
"$id": "CliExecutorOptions",
44
"title": "CodePushup CLI autorun executor",
55
"description": "Executes the @code-pushup/cli autorun command See: https://github.com/code-pushup/cli/blob/main/packages/cli/README.md#autorun-command",
66
"type": "object",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import type {
88

99
export type PrintConfigOptions = { output?: string };
1010
export type PrintConfigCommandExecutorOptions = PrintConfigOptions;
11-
export type AutorunCommandExecutorOnlyOptions = ProjectExecutorOnlyOptions &
11+
export type CliCommandExecutorOnlyOptions = ProjectExecutorOnlyOptions &
1212
CollectExecutorOnlyOptions &
1313
GeneralExecutorOnlyOptions;
1414

15-
export type AutorunCommandExecutorOptions = Partial<
15+
export type CliCommandExecutorOptions = Partial<
1616
{
1717
upload: Partial<UploadConfig>;
1818
persist: Partial<PersistConfig>;
19-
} & AutorunCommandExecutorOnlyOptions &
19+
} & CliCommandExecutorOnlyOptions &
2020
GlobalExecutorOptions
2121
> &
2222
PrintConfigOptions;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { expect, vi } from 'vitest';
22
import type { UploadConfig } from '@code-pushup/models';
33
import { normalizedExecutorContext } from '../../../mock/utils/executor.js';
44
import * as config from '../internal/config.js';
5-
import { parseAutorunExecutorOptions } from './utils.js';
5+
import { parseCliExecutorOptions } from './utils.js';
66

7-
describe('parseAutorunExecutorOptions', () => {
7+
describe('parseCliExecutorOptions', () => {
88
const persistConfigSpy = vi.spyOn(config, 'persistConfig');
99
const uploadConfigSpy = vi.spyOn(config, 'uploadConfig');
1010
const globalConfigSpy = vi.spyOn(config, 'globalConfig');
@@ -17,7 +17,7 @@ describe('parseAutorunExecutorOptions', () => {
1717
});
1818

1919
it('should call child config functions with options', () => {
20-
parseAutorunExecutorOptions(
20+
parseCliExecutorOptions(
2121
{
2222
verbose: true,
2323
persist: { filename: 'my-name' },

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import {
55
} from '../internal/config.js';
66
import type { NormalizedExecutorContext } from '../internal/context.js';
77
import type {
8-
AutorunCommandExecutorOnlyOptions,
9-
AutorunCommandExecutorOptions,
8+
CliCommandExecutorOnlyOptions,
9+
CliCommandExecutorOptions,
1010
PrintConfigCommandExecutorOptions,
1111
} from './schema.js';
1212

13-
export function parseAutorunExecutorOnlyOptions(
14-
options: Partial<AutorunCommandExecutorOnlyOptions>,
15-
): AutorunCommandExecutorOnlyOptions {
13+
export function parseCliExecutorOnlyOptions(
14+
options: Partial<CliCommandExecutorOnlyOptions>,
15+
): CliCommandExecutorOnlyOptions {
1616
const { projectPrefix, dryRun, onlyPlugins, env, bin } = options;
1717
return {
1818
...(projectPrefix && { projectPrefix }),
@@ -32,10 +32,10 @@ export function parsePrintConfigExecutorOptions(
3232
};
3333
}
3434

35-
export function parseAutorunExecutorOptions(
36-
options: Partial<AutorunCommandExecutorOptions>,
35+
export function parseCliExecutorOptions(
36+
options: Partial<CliCommandExecutorOptions>,
3737
normalizedContext: NormalizedExecutorContext,
38-
): AutorunCommandExecutorOptions {
38+
): CliCommandExecutorOptions {
3939
const { projectPrefix, persist, upload, command, output } = options;
4040
const needsUploadParams =
4141
command === 'upload' || command === 'autorun' || command === undefined;
@@ -46,7 +46,7 @@ export function parseAutorunExecutorOptions(
4646
const hasApiToken = uploadCfg?.apiKey != null;
4747
return {
4848
...parsePrintConfigExecutorOptions(options),
49-
...parseAutorunExecutorOnlyOptions(options),
49+
...parseCliExecutorOnlyOptions(options),
5050
...globalConfig(options, normalizedContext),
5151
...(output ? { output } : {}),
5252
persist: persistConfig({ projectPrefix, ...persist }, normalizedContext),

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { type MockInstance, expect, vi } from 'vitest';
22
import { osAgnosticPath } from '@code-pushup/test-utils';
33
import type { Command } from '../internal/types.js';
44
import {
5-
parseAutorunExecutorOnlyOptions,
6-
parseAutorunExecutorOptions,
5+
parseCliExecutorOnlyOptions,
6+
parseCliExecutorOptions,
77
parsePrintConfigExecutorOptions,
88
} from './utils.js';
99

@@ -23,57 +23,57 @@ describe('parsePrintConfigExecutorOptions', () => {
2323
});
2424
});
2525

26-
describe('parseAutorunExecutorOnlyOptions', () => {
26+
describe('parseCliExecutorOnlyOptions', () => {
2727
it('should provide NO default projectPrefix', () => {
28-
expect(parseAutorunExecutorOnlyOptions({})).toStrictEqual(
28+
expect(parseCliExecutorOnlyOptions({})).toStrictEqual(
2929
expect.not.objectContaining({ projectPrefix: expect.anything() }),
3030
);
3131
});
3232

3333
it('should process given projectPrefix', () => {
34-
expect(
35-
parseAutorunExecutorOnlyOptions({ projectPrefix: 'cli' }),
36-
).toStrictEqual(expect.objectContaining({ projectPrefix: 'cli' }));
34+
expect(parseCliExecutorOnlyOptions({ projectPrefix: 'cli' })).toStrictEqual(
35+
expect.objectContaining({ projectPrefix: 'cli' }),
36+
);
3737
});
3838

3939
it('should provide NO default dryRun', () => {
40-
expect(parseAutorunExecutorOnlyOptions({})).toStrictEqual(
40+
expect(parseCliExecutorOnlyOptions({})).toStrictEqual(
4141
expect.not.objectContaining({ dryRun: expect.anything() }),
4242
);
4343
});
4444

4545
it('should process given dryRun', () => {
46-
expect(parseAutorunExecutorOnlyOptions({ dryRun: false })).toStrictEqual(
46+
expect(parseCliExecutorOnlyOptions({ dryRun: false })).toStrictEqual(
4747
expect.objectContaining({ dryRun: false }),
4848
);
4949
});
5050

5151
it('should provide default onlyPlugins', () => {
52-
expect(parseAutorunExecutorOnlyOptions({})).toStrictEqual(
52+
expect(parseCliExecutorOnlyOptions({})).toStrictEqual(
5353
expect.not.objectContaining({ onlyPlugins: ['json'] }),
5454
);
5555
});
5656

5757
it('should process given onlyPlugins', () => {
5858
expect(
59-
parseAutorunExecutorOnlyOptions({ onlyPlugins: ['md', 'json'] }),
59+
parseCliExecutorOnlyOptions({ onlyPlugins: ['md', 'json'] }),
6060
).toStrictEqual(expect.objectContaining({ onlyPlugins: ['md', 'json'] }));
6161
});
6262

6363
it('should log env variables options if given', async () => {
6464
expect(
65-
parseAutorunExecutorOnlyOptions({ env: { TEST_ENV_VAR: '42' } }),
65+
parseCliExecutorOnlyOptions({ env: { TEST_ENV_VAR: '42' } }),
6666
).toStrictEqual(expect.objectContaining({ env: { TEST_ENV_VAR: '42' } }));
6767
});
6868

6969
it('should process given bin', () => {
70-
expect(parseAutorunExecutorOnlyOptions({ bin: 'index.js' })).toStrictEqual(
70+
expect(parseCliExecutorOnlyOptions({ bin: 'index.js' })).toStrictEqual(
7171
expect.objectContaining({ bin: 'index.js' }),
7272
);
7373
});
7474
});
7575

76-
describe('parseAutorunExecutorOptions', () => {
76+
describe('parseCliExecutorOptions', () => {
7777
let processEnvSpy: MockInstance<[], NodeJS.ProcessEnv>;
7878

7979
beforeAll(() => {
@@ -86,7 +86,7 @@ describe('parseAutorunExecutorOptions', () => {
8686

8787
it('should leverage other config helper to assemble the executor config', () => {
8888
const projectName = 'my-app';
89-
const executorOptions = parseAutorunExecutorOptions(
89+
const executorOptions = parseCliExecutorOptions(
9090
{
9191
persist: {
9292
filename: 'from-options',
@@ -130,7 +130,7 @@ describe('parseAutorunExecutorOptions', () => {
130130
TSX_TSCONFIG_PATH: 'tsconfig.base.json',
131131
};
132132

133-
const executorOptions = parseAutorunExecutorOptions(
133+
const executorOptions = parseCliExecutorOptions(
134134
{ env },
135135
{
136136
projectName,
@@ -149,7 +149,7 @@ describe('parseAutorunExecutorOptions', () => {
149149
'should include upload config for command %s if API key is provided',
150150
command => {
151151
const projectName = 'my-app';
152-
const executorOptions = parseAutorunExecutorOptions(
152+
const executorOptions = parseCliExecutorOptions(
153153
{
154154
command,
155155
upload: {
@@ -178,7 +178,7 @@ describe('parseAutorunExecutorOptions', () => {
178178
'should not include upload config for command %s',
179179
command => {
180180
const projectName = 'my-app';
181-
const executorOptions = parseAutorunExecutorOptions(
181+
const executorOptions = parseCliExecutorOptions(
182182
{
183183
command,
184184
upload: {

packages/nx-plugin/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const plugin = {
1010

1111
export default plugin;
1212

13-
export type { AutorunCommandExecutorOptions } from './executors/cli/schema.js';
13+
export type { CliCommandExecutorOptions } from './executors/cli/schema.js';
1414
export { generateCodePushupConfig } from './generators/configuration/code-pushup-config.js';
1515
export { configurationGenerator } from './generators/configuration/generator.js';
1616
export type { ConfigurationGeneratorOptions } from './generators/configuration/schema.js';

0 commit comments

Comments
 (0)