Skip to content

Commit 3b3d25d

Browse files
author
John Doe
committed
refactor: reuse utils logic
1 parent f0680e2 commit 3b3d25d

File tree

6 files changed

+43
-393
lines changed

6 files changed

+43
-393
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1-
import { afterEach, expect, vi } from 'vitest';
1+
import { afterEach, beforeEach, expect, vi } from 'vitest';
22
import { executorContext } from '@code-pushup/test-nx-utils';
3-
import * as executeProcessModule from '../../internal/execute-process.js';
43
import runAutorunExecutor from './executor.js';
54
import * as utils from './utils.js';
65

6+
const { executeProcessSpy } = vi.hoisted(() => ({
7+
executeProcessSpy: vi.fn().mockResolvedValue({
8+
code: 0,
9+
stdout: '',
10+
stderr: '',
11+
date: new Date().toISOString(),
12+
duration: 100,
13+
}),
14+
}));
15+
16+
vi.mock('@code-pushup/utils', async () => {
17+
const utils = await vi.importActual('@code-pushup/utils');
18+
return {
19+
...utils,
20+
executeProcess: executeProcessSpy,
21+
};
22+
});
23+
724
describe('runAutorunExecutor', () => {
825
const parseAutorunExecutorOptionsSpy = vi.spyOn(
926
utils,
1027
'parseAutorunExecutorOptions',
1128
);
12-
const executeProcessSpy = vi.spyOn(executeProcessModule, 'executeProcess');
1329

1430
beforeEach(() => {
31+
executeProcessSpy.mockClear();
1532
executeProcessSpy.mockResolvedValue({
1633
bin: 'npx ...',
1734
code: 0,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { type ExecutorContext, logger } from '@nx/devkit';
2-
import { isVerbose } from '@code-pushup/utils';
3-
import { executeProcess } from '../../internal/execute-process.js';
42
import {
53
createCliCommandObject,
64
createCliCommandString,
@@ -42,10 +40,10 @@ export default async function runAutorunExecutor(
4240
logger.warn(`DryRun execution of: ${commandString}`);
4341
} else {
4442
try {
43+
const { executeProcess } = await import('@code-pushup/utils');
4544
await executeProcess({
4645
...createCliCommandObject({ command, args: cliArgumentObject, bin }),
4746
...(context.cwd ? { cwd: context.cwd } : {}),
48-
...(isVerbose() || verbose ? { verbose: true } : {}),
4947
});
5048
} catch (error) {
5149
logger.error(error);

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

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

7+
const { executeProcessSpy } = vi.hoisted(() => ({
8+
executeProcessSpy: vi.fn().mockResolvedValue({
9+
code: 0,
10+
stdout: '',
11+
stderr: '',
12+
date: new Date().toISOString(),
13+
duration: 100,
14+
}),
15+
}));
16+
17+
vi.mock('@code-pushup/utils', async () => {
18+
const utils = await vi.importActual('@code-pushup/utils');
19+
return {
20+
...utils,
21+
executeProcess: executeProcessSpy,
22+
};
23+
});
24+
825
describe('runAutorunExecutor', () => {
926
const processEnvCP = Object.fromEntries(
1027
Object.entries(process.env).filter(([k]) => k.startsWith('CP_')),
1128
);
1229
const loggerInfoSpy = vi.spyOn(logger, 'info');
1330
const loggerWarnSpy = vi.spyOn(logger, 'warn');
14-
const executeProcessSpy = vi.spyOn(executeProcessModule, 'executeProcess');
1531

1632
beforeAll(() => {
1733
Object.entries(process.env)
@@ -25,6 +41,7 @@ describe('runAutorunExecutor', () => {
2541

2642
beforeEach(() => {
2743
vi.unstubAllEnvs();
44+
executeProcessSpy.mockClear();
2845
executeProcessSpy.mockResolvedValue({
2946
bin: 'npx ...',
3047
code: 0,

packages/nx-plugin/src/internal/command.ts

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)