|
1 | | -import { type Tree, updateProjectConfiguration } from '@nx/devkit'; |
| 1 | +import {type Tree, updateProjectConfiguration} from '@nx/devkit'; |
2 | 2 | import path from 'node:path'; |
3 | | -import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; |
4 | | -import { afterEach, expect } from 'vitest'; |
5 | | -import { |
6 | | - type AutorunCommandExecutorOptions, |
7 | | - generateCodePushupConfig, |
8 | | -} from '@code-pushup/nx-plugin'; |
9 | | -import { |
10 | | - generateWorkspaceAndProject, |
11 | | - materializeTree, |
12 | | - nxTargetProject, |
13 | | -} from '@code-pushup/test-nx-utils'; |
14 | | -import { |
15 | | - E2E_ENVIRONMENTS_DIR, |
16 | | - TEST_OUTPUT_DIR, |
17 | | - removeColorCodes, |
18 | | - teardownTestFolder, |
19 | | -} from '@code-pushup/test-utils'; |
20 | | -import { executeProcess, readJsonFile } from '@code-pushup/utils'; |
21 | | -import { INLINE_PLUGIN } from './inline-plugin.js'; |
| 3 | +import {readProjectConfiguration} from 'nx/src/generators/utils/project-configuration'; |
| 4 | +import {afterAll, afterEach, beforeEach, expect, vi} from 'vitest'; |
| 5 | +import {type AutorunCommandExecutorOptions, generateCodePushupConfig,} from '@code-pushup/nx-plugin'; |
| 6 | +import {generateWorkspaceAndProject, materializeTree, nxTargetProject,} from '@code-pushup/test-nx-utils'; |
| 7 | +import {E2E_ENVIRONMENTS_DIR, removeColorCodes, teardownTestFolder, TEST_OUTPUT_DIR,} from '@code-pushup/test-utils'; |
| 8 | +import {executeProcess, readJsonFile} from '@code-pushup/utils'; |
| 9 | +import {INLINE_PLUGIN} from './inline-plugin.js'; |
22 | 10 |
|
23 | 11 | async function addTargetToWorkspace( |
24 | 12 | tree: Tree, |
@@ -58,19 +46,32 @@ describe('executor command', () => { |
58 | 46 | TEST_OUTPUT_DIR, |
59 | 47 | 'executor-cli', |
60 | 48 | ); |
| 49 | + const processEnvCP = Object.fromEntries( |
| 50 | + Object.entries(process.env).filter(([k]) => k.startsWith('CP_')), |
| 51 | + ); |
| 52 | + |
| 53 | + /* eslint-disable functional/immutable-data, @typescript-eslint/no-dynamic-delete */ |
| 54 | + beforeAll(() => { |
| 55 | + Object.entries(process.env) |
| 56 | + .filter(([k]) => k.startsWith('CP_')) |
| 57 | + .forEach(([k]) => delete process.env[k]); |
| 58 | + }); |
61 | 59 |
|
62 | | - beforeEach(async () => { |
| 60 | + beforeEach(() => { |
| 61 | + vi.unstubAllEnvs(); |
63 | 62 | tree = await generateWorkspaceAndProject(project); |
64 | | - vi.stubEnv('CP_ORGANIZATION', ''); |
65 | | - vi.stubEnv('CP_PROJECT', ''); |
66 | | - vi.stubEnv('CP_SERVER', ''); |
67 | | - vi.stubEnv('CP_API_KEY', ''); |
68 | 63 | }); |
69 | 64 |
|
70 | 65 | afterEach(async () => { |
71 | 66 | await teardownTestFolder(testFileDir); |
72 | 67 | }); |
73 | 68 |
|
| 69 | + afterAll(() => { |
| 70 | + Object.entries(processEnvCP).forEach(([k, v]) => (process.env[k] = v)); |
| 71 | + }); |
| 72 | + /* eslint-enable functional/immutable-data, @typescript-eslint/no-dynamic-delete */ |
| 73 | + |
| 74 | + |
74 | 75 | it('should execute no specific command by default', async () => { |
75 | 76 | const cwd = path.join(testFileDir, 'execute-default-command'); |
76 | 77 | await addTargetToWorkspace(tree, { cwd, project }); |
|
0 commit comments