Skip to content

Commit 10506cf

Browse files
committed
test: adjust test env paths
1 parent 4526688 commit 10506cf

File tree

23 files changed

+788
-110
lines changed

23 files changed

+788
-110
lines changed

e2e/ci-e2e/mocks/fixtures/code-pushup.config.ts renamed to e2e/ci-e2e/mocks/fixtures/ci-test-repo/code-pushup.config.ts

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello, world!")

e2e/ci-e2e/tests/ci.e2e.test.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
copyFile,
3-
mkdir,
4-
readFile,
5-
rename,
6-
rm,
7-
writeFile,
8-
} from 'node:fs/promises';
1+
import { cp, readFile, rename } from 'node:fs/promises';
92
import { dirname, join } from 'node:path';
103
import { fileURLToPath } from 'node:url';
114
import {
@@ -14,6 +7,7 @@ import {
147
type SimpleGit,
158
simpleGit,
169
} from 'simple-git';
10+
import { afterEach } from 'vitest';
1711
import {
1812
type Comment,
1913
type GitRefs,
@@ -22,41 +16,42 @@ import {
2216
type RunResult,
2317
runInCI,
2418
} from '@code-pushup/ci';
25-
import { initGitRepo } from '@code-pushup/test-utils';
19+
import { nxTargetProject } from '@code-pushup/test-nx-utils';
20+
import { teardownTestFolder } from '@code-pushup/test-setup';
21+
import {
22+
E2E_ENVIRONMENTS_DIR,
23+
TEST_OUTPUT_DIR,
24+
TEST_SNAPSHOTS_DIR,
25+
initGitRepo,
26+
} from '@code-pushup/test-utils';
2627

2728
describe('CI package', () => {
2829
const fixturesDir = join(
2930
fileURLToPath(dirname(import.meta.url)),
3031
'..',
3132
'mocks',
3233
'fixtures',
34+
'ci-test-repo',
3335
);
34-
const workDir = join(
36+
const ciSetupRepoDir = join(
3537
process.cwd(),
36-
'tmp',
37-
'e2e',
38-
'ci-e2e',
39-
'__test__',
38+
E2E_ENVIRONMENTS_DIR,
39+
nxTargetProject(),
40+
TEST_OUTPUT_DIR,
4041
'ci-test-repo',
4142
);
42-
const outputDir = join(workDir, '.code-pushup');
43+
const outputDir = join(ciSetupRepoDir, '.code-pushup');
4344

4445
const options = {
45-
directory: workDir,
46+
directory: ciSetupRepoDir,
4647
} satisfies Options;
4748

4849
let git: SimpleGit;
4950

5051
beforeEach(async () => {
51-
await rm(workDir, { recursive: true, force: true });
52-
await mkdir(workDir, { recursive: true });
53-
await copyFile(
54-
join(fixturesDir, 'code-pushup.config.ts'),
55-
join(workDir, 'code-pushup.config.ts'),
56-
);
57-
await writeFile(join(workDir, 'index.js'), 'console.log("Hello, world!")');
52+
await cp(fixturesDir, ciSetupRepoDir, { recursive: true });
5853

59-
git = await initGitRepo(simpleGit, { baseDir: workDir });
54+
git = await initGitRepo(simpleGit, { baseDir: ciSetupRepoDir });
6055

6156
vi.spyOn(git, 'fetch').mockResolvedValue({} as FetchResult);
6257
vi.spyOn(git, 'diffSummary').mockResolvedValue({
@@ -69,8 +64,12 @@ describe('CI package', () => {
6964
await git.commit('Initial commit');
7065
});
7166

67+
afterEach(async () => {
68+
await teardownTestFolder(ciSetupRepoDir);
69+
});
70+
7271
afterAll(async () => {
73-
await rm(workDir, { recursive: true, force: true });
72+
await teardownTestFolder(ciSetupRepoDir);
7473
});
7574

7675
describe('push event', () => {
@@ -138,7 +137,10 @@ describe('CI package', () => {
138137
beforeEach(async () => {
139138
await git.checkoutLocalBranch('feature-1');
140139

141-
await rename(join(workDir, 'index.js'), join(workDir, 'index.ts'));
140+
await rename(
141+
join(ciSetupRepoDir, 'index.js'),
142+
join(ciSetupRepoDir, 'index.ts'),
143+
);
142144

143145
await git.add('index.ts');
144146
await git.commit('Convert JS file to TS');
@@ -177,7 +179,7 @@ describe('CI package', () => {
177179
const md = await mdPromise;
178180
await expect(
179181
md.replace(/[\da-f]{40}/g, '`<commit-sha>`'),
180-
).toMatchFileSnapshot('__snapshots__/report-diff.md');
182+
).toMatchFileSnapshot(join(TEST_SNAPSHOTS_DIR, 'report-diff.md'));
181183
});
182184
});
183185
});

e2e/cli-e2e/mocks/fixtures/existing-reports/.code-pushup/.gitkeep

Whitespace-only changes.

e2e/cli-e2e/tests/collect.e2e.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { cp } from 'node:fs/promises';
22
import { join } from 'node:path';
33
import { afterEach, beforeAll, describe, expect, it } from 'vitest';
4+
import { nxTargetProject } from '@code-pushup/test-nx-utils';
45
import { teardownTestFolder } from '@code-pushup/test-setup';
6+
import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR } from '@code-pushup/test-utils';
57
import { executeProcess, readTextFile } from '@code-pushup/utils';
68

79
describe('CLI collect', () => {
810
const dummyPluginTitle = 'Dummy Plugin';
911
const dummyAuditTitle = 'Dummy Audit';
1012
const fixtureDummyDir = join(
1113
'e2e',
12-
'cli-e2e',
14+
nxTargetProject(),
1315
'mocks',
1416
'fixtures',
1517
'dummy-setup',
1618
);
17-
const envRoot = join('tmp', 'e2e', 'cli-e2e');
18-
const testFileDir = join(envRoot, 'collect');
19+
const testFileDir = join(
20+
E2E_ENVIRONMENTS_DIR,
21+
nxTargetProject(),
22+
TEST_OUTPUT_DIR,
23+
'collect',
24+
);
1925
const dummyDir = join(testFileDir, 'dummy-setup');
2026
const dummyOutputDir = join(dummyDir, '.code-pushup');
2127

e2e/cli-e2e/tests/compare.e2e.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@ import { cp } from 'node:fs/promises';
22
import { join } from 'node:path';
33
import { beforeAll } from 'vitest';
44
import type { ReportsDiff } from '@code-pushup/models';
5+
import { nxTargetProject } from '@code-pushup/test-nx-utils';
56
import { teardownTestFolder } from '@code-pushup/test-setup';
7+
import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR } from '@code-pushup/test-utils';
68
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
79

810
describe('CLI compare', () => {
911
const fixtureDummyDir = join(
1012
'e2e',
11-
'cli-e2e',
13+
nxTargetProject(),
1214
'mocks',
1315
'fixtures',
1416
'existing-reports',
1517
);
1618

17-
const envRoot = join('tmp', 'e2e', 'cli-e2e');
18-
const testFileDir = join(envRoot, '__test__', 'compare');
19+
const testFileDir = join(
20+
E2E_ENVIRONMENTS_DIR,
21+
nxTargetProject(),
22+
TEST_OUTPUT_DIR,
23+
'compare',
24+
);
1925
const existingDir = join(testFileDir, 'existing-reports');
2026
const existingOutputDir = join(existingDir, '.code-pushup');
2127

e2e/cli-e2e/tests/help.e2e.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { join } from 'node:path';
2-
import { removeColorCodes } from '@code-pushup/test-utils';
2+
import { nxTargetProject } from '@code-pushup/test-nx-utils';
3+
import {
4+
E2E_ENVIRONMENTS_DIR,
5+
removeColorCodes,
6+
} from '@code-pushup/test-utils';
37
import { executeProcess } from '@code-pushup/utils';
48

59
describe('CLI help', () => {
6-
const envRoot = join('tmp', 'e2e', 'cli-e2e');
10+
const envRoot = join(E2E_ENVIRONMENTS_DIR, nxTargetProject());
711

812
it('should print help with help command', async () => {
913
const { code, stdout, stderr } = await executeProcess({

e2e/cli-e2e/tests/print-config.e2e.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import { cp } from 'node:fs/promises';
22
import { join } from 'node:path';
33
import { beforeAll, expect } from 'vitest';
4+
import { nxTargetProject } from '@code-pushup/test-nx-utils';
45
import { teardownTestFolder } from '@code-pushup/test-setup';
6+
import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR } from '@code-pushup/test-utils';
57
import { executeProcess } from '@code-pushup/utils';
68

79
describe('CLI print-config', () => {
810
const extensions = ['js', 'mjs', 'ts'] as const;
911
const fixtureDummyDir = join(
1012
'e2e',
11-
'cli-e2e',
13+
nxTargetProject(),
1214
'mocks',
1315
'fixtures',
1416
'dummy-setup',
1517
);
16-
const envRoot = join('tmp', 'e2e', 'cli-e2e');
17-
const testFileDir = join(envRoot, 'print-config');
18+
19+
const testFileDir = join(
20+
E2E_ENVIRONMENTS_DIR,
21+
nxTargetProject(),
22+
TEST_OUTPUT_DIR,
23+
'print-config',
24+
);
1825
const testFileDummySetup = join(testFileDir, 'dummy-setup');
1926
const configFilePath = (ext: (typeof extensions)[number]) =>
2027
join(process.cwd(), testFileDummySetup, `code-pushup.config.${ext}`);

e2e/create-cli-e2e/tests/init.e2e.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import { dirname, join, relative } from 'node:path';
22
import { afterEach, expect } from 'vitest';
3+
import { nxTargetProject } from '@code-pushup/test-nx-utils';
34
import { teardownTestFolder } from '@code-pushup/test-setup';
4-
import { createNpmWorkspace, removeColorCodes } from '@code-pushup/test-utils';
5+
import {
6+
E2E_ENVIRONMENTS_DIR,
7+
TEST_OUTPUT_DIR,
8+
createNpmWorkspace,
9+
removeColorCodes,
10+
} from '@code-pushup/test-utils';
511
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
612

713
describe('create-cli-inti', () => {
8-
const workspaceRoot = 'tmp/e2e/create-cli-e2e';
9-
const baseDir = 'tmp/e2e/create-cli-e2e/__test__/init';
14+
const workspaceRoot = join(E2E_ENVIRONMENTS_DIR, nxTargetProject());
15+
const testFileDir = join(workspaceRoot, TEST_OUTPUT_DIR, 'init');
1016

1117
afterEach(async () => {
12-
await teardownTestFolder(baseDir);
18+
await teardownTestFolder(testFileDir);
1319
});
1420

1521
it('should execute package correctly over npm exec', async () => {
16-
const cwd = join(baseDir, 'npm-exec');
22+
const cwd = join(testFileDir, 'npm-exec');
1723
const userconfig = relative(cwd, join(workspaceRoot, '.npmrc'));
1824
await createNpmWorkspace(cwd);
1925
const { code, stdout } = await executeProcess({
@@ -53,7 +59,7 @@ describe('create-cli-inti', () => {
5359
});
5460

5561
it('should execute package correctly over npm init', async () => {
56-
const cwd = join(baseDir, 'npm-init');
62+
const cwd = join(testFileDir, 'npm-init');
5763
const userconfig = relative(cwd, join(workspaceRoot, '.npmrc'));
5864

5965
await createNpmWorkspace(cwd);
@@ -95,7 +101,7 @@ describe('create-cli-inti', () => {
95101
});
96102

97103
it('should produce an executable setup when running npm init', async () => {
98-
const cwd = join(baseDir, 'npm-init-executable');
104+
const cwd = join(testFileDir, 'npm-init-executable');
99105
const userconfig = relative(cwd, join(workspaceRoot, '.npmrc'));
100106

101107
await createNpmWorkspace(cwd);

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ import { generateCodePushupConfig } from '@code-pushup/nx-plugin';
66
import {
77
generateWorkspaceAndProject,
88
materializeTree,
9+
nxTargetProject,
910
} from '@code-pushup/test-nx-utils';
1011
import { teardownTestFolder } from '@code-pushup/test-setup';
11-
import { osAgnosticPath, removeColorCodes } from '@code-pushup/test-utils';
12+
import {
13+
E2E_ENVIRONMENTS_DIR,
14+
TEST_OUTPUT_DIR,
15+
osAgnosticPath,
16+
removeColorCodes,
17+
} from '@code-pushup/test-utils';
1218
import { executeProcess, readJsonFile } from '@code-pushup/utils';
1319

1420
function relativePathToCwd(testDir: string): string {
@@ -61,18 +67,23 @@ async function addTargetToWorkspace(
6167
describe('executor command', () => {
6268
let tree: Tree;
6369
const project = 'my-lib';
64-
const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/executor/cli';
70+
const testFileDir = join(
71+
E2E_ENVIRONMENTS_DIR,
72+
nxTargetProject(),
73+
TEST_OUTPUT_DIR,
74+
'executor-cli',
75+
);
6576

6677
beforeEach(async () => {
6778
tree = await generateWorkspaceAndProject(project);
6879
});
6980

7081
afterEach(async () => {
71-
await teardownTestFolder(baseDir);
82+
await teardownTestFolder(testFileDir);
7283
});
7384

7485
it('should execute no specific command by default', async () => {
75-
const cwd = join(baseDir, 'execute-default-command');
86+
const cwd = join(testFileDir, 'execute-default-command');
7687
await addTargetToWorkspace(tree, { cwd, project });
7788
const { stdout, code } = await executeProcess({
7889
command: 'npx',
@@ -86,7 +97,7 @@ describe('executor command', () => {
8697
});
8798

8899
it('should execute print-config executor', async () => {
89-
const cwd = join(baseDir, 'execute-print-config-command');
100+
const cwd = join(testFileDir, 'execute-print-config-command');
90101
await addTargetToWorkspace(tree, { cwd, project });
91102

92103
const { stdout, code } = await executeProcess({
@@ -105,7 +116,7 @@ describe('executor command', () => {
105116
});
106117

107118
it('should execute collect executor and add report to sub folder named by project', async () => {
108-
const cwd = join(baseDir, 'execute-collect-command');
119+
const cwd = join(testFileDir, 'execute-collect-command');
109120
await addTargetToWorkspace(tree, { cwd, project });
110121

111122
const { stdout, code } = await executeProcess({

0 commit comments

Comments
 (0)