Skip to content

Commit cf29bc3

Browse files
authored
test: refactor old tests and cleanup test helpers (#873)
1 parent 3db30da commit cf29bc3

File tree

89 files changed

+661
-4385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+661
-4385
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ jobs:
120120
- name: Install dependencies
121121
run: npm ci
122122
- name: E2E test affected projects
123-
run: npx nx affected -t nxv-e2e --exclude cli-e2e --parallel=1
124-
- name: E2E test cli-e2e project (due to bugs in the setup it has to run last :( )
125-
run: npx nx run cli-e2e:e2e-old
123+
run: npx nx affected -t nxv-e2e --parallel=1
126124

127125
build:
128126
runs-on: ubuntu-latest

code-pushup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const config: CoreConfig = {
3737

3838
plugins: [
3939
fileSizePlugin({
40-
directory: './dist/examples/react-todos-app',
40+
directory: './dist/packages',
4141
pattern: /\.js$/,
4242
budget: 174_080, // 170 kB
4343
}),

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/code-pushup.config.js

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

e2e/cli-e2e/mocks/fixtures/code-pushup.config.mjs

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

e2e/cli-e2e/mocks/fixtures/code-pushup.config.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import dummyPlugin, { dummyCategory } from './dummy.plugin';
2+
3+
export default {
4+
plugins: [dummyPlugin()],
5+
categories: [dummyCategory],
6+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import dummyPlugin, { dummyCategory } from './dummy.plugin';
2+
3+
export default {
4+
plugins: [dummyPlugin()],
5+
categories: [dummyCategory],
6+
};

0 commit comments

Comments
 (0)