Skip to content

Commit f35f90c

Browse files
committed
test(ci-e2e): add e2e test for pull request flow in monorepo mode
1 parent 5e36323 commit f35f90c

File tree

4 files changed

+157
-5
lines changed

4 files changed

+157
-5
lines changed
File renamed without changes.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Code PushUp
2+
3+
🤨 Code PushUp report has both **improvements and regressions** – compared target commit `<commit-sha>` with source commit `<commit-sha>`.
4+
5+
## 💼 Project `api`
6+
7+
🥳 Code PushUp report has **improved**.
8+
9+
| 🏷️ Category | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
10+
| :------------------- | :--------------: | :-------------: | :------------------------------------------------------------: |
11+
| TypeScript migration | 🔴 0 | 🟡 **50** | ![↑ +50](https://img.shields.io/badge/%E2%86%91%20%2B50-green) |
12+
13+
<details>
14+
<summary>👍 <strong>1</strong> audit improved</summary>
15+
16+
### 🛡️ Audits
17+
18+
| 🔌 Plugin | 🛡️ Audit | 📏 Previous value | 📏 Current value | 🔄 Value change |
19+
| :------------------- | :--------------------------------------------------- | :---------------: | :------------------: | :--------------------------------------------------------------------------------: |
20+
| TypeScript migration | Source files converted from JavaScript to TypeScript | 🟥 0% converted | 🟨 **50% converted** | ![↑ +∞ %](https://img.shields.io/badge/%E2%86%91%20%2B%E2%88%9E%E2%80%89%25-green) |
21+
22+
</details>
23+
24+
## 💼 Project `web`
25+
26+
😟 Code PushUp report has **regressed**.
27+
28+
| 🏷️ Category | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
29+
| :------------------- | :--------------: | :-------------: | :----------------------------------------------------------------: |
30+
| TypeScript migration | 🟡 50 | 🔴 **0** | ![↓ −50](https://img.shields.io/badge/%E2%86%93%20%E2%88%9250-red) |
31+
32+
<details>
33+
<summary>👎 <strong>1</strong> audit regressed</summary>
34+
35+
### 🛡️ Audits
36+
37+
| 🔌 Plugin | 🛡️ Audit | 📏 Previous value | 📏 Current value | 🔄 Value change |
38+
| :------------------- | :--------------------------------------------------- | :---------------: | :-----------------: | :--------------------------------------------------------------------------------: |
39+
| TypeScript migration | Source files converted from JavaScript to TypeScript | 🟨 50% converted | 🟥 **0% converted** | ![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-red) |
40+
41+
</details>
42+
43+
## 💼 Project `ui`
44+
45+
🥳 Code PushUp report has **improved**.
46+
47+
| 🏷️ Category | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
48+
| :------------------- | :--------------: | :-------------: | :----------------------------------------------------------------: |
49+
| TypeScript migration | 🟡 67 | 🟢 **100** | ![↑ +33.3](https://img.shields.io/badge/%E2%86%91%20%2B33.3-green) |
50+
51+
<details>
52+
<summary>👍 <strong>1</strong> audit improved</summary>
53+
54+
### 🛡️ Audits
55+
56+
| 🔌 Plugin | 🛡️ Audit | 📏 Previous value | 📏 Current value | 🔄 Value change |
57+
| :------------------- | :--------------------------------------------------- | :---------------: | :-------------------: | :------------------------------------------------------------------------------: |
58+
| TypeScript migration | Source files converted from JavaScript to TypeScript | 🟨 67% converted | 🟩 **100% converted** | ![↑ +49.3 %](https://img.shields.io/badge/%E2%86%91%20%2B49.3%E2%80%89%25-green) |
59+
60+
</details>
61+
62+
---
63+
64+
2 other projects are unchanged.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('CI - standalone mode', () => {
119119
const md = await mdPromise;
120120
await expect(
121121
md.replace(/[\da-f]{40}/g, '`<commit-sha>`'),
122-
).toMatchFileSnapshot(join(TEST_SNAPSHOTS_DIR, 'report-diff.md'));
122+
).toMatchFileSnapshot(join(TEST_SNAPSHOTS_DIR, 'basic-report-diff.md'));
123123
});
124124
});
125125
});

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

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
import { readFile, rename, writeFile } from 'node:fs/promises';
12
import { join } from 'node:path';
23
import type { SimpleGit } from 'simple-git';
34
import { afterEach } from 'vitest';
4-
import { type Options, type RunResult, runInCI } from '@code-pushup/ci';
5+
import {
6+
type GitRefs,
7+
type Options,
8+
type ProjectRunResult,
9+
type RunResult,
10+
runInCI,
11+
} from '@code-pushup/ci';
12+
import { TEST_SNAPSHOTS_DIR } from '@code-pushup/test-utils';
513
import { readJsonFile } from '@code-pushup/utils';
6-
import { MOCK_API } from '../mocks/api';
14+
import { MOCK_API, MOCK_COMMENT } from '../mocks/api';
715
import { type TestRepo, setupTestRepo } from '../mocks/setup';
816

917
describe('CI - monorepo mode (Nx)', () => {
@@ -39,7 +47,7 @@ describe('CI - monorepo mode (Nx)', () => {
3947
),
4048
).resolves.toEqual({
4149
mode: 'monorepo',
42-
projects: expect.arrayContaining([
50+
projects: expect.arrayContaining<ProjectRunResult>([
4351
{
4452
name: 'api',
4553
files: {
@@ -87,5 +95,85 @@ describe('CI - monorepo mode (Nx)', () => {
8795
});
8896
});
8997

90-
// TODO: pull request event
98+
describe('pull request event', () => {
99+
let refs: GitRefs;
100+
101+
beforeEach(async () => {
102+
await git.checkoutLocalBranch('feature-1');
103+
104+
await rename(
105+
join(repo.baseDir, 'apps/api/src/index.js'),
106+
join(repo.baseDir, 'apps/api/src/index.ts'),
107+
);
108+
await rename(
109+
join(repo.baseDir, 'apps/web/src/index.ts'),
110+
join(repo.baseDir, 'apps/web/src/index.js'),
111+
);
112+
await rename(
113+
join(repo.baseDir, 'libs/ui/code-pushup.config.js'),
114+
join(repo.baseDir, 'libs/ui/code-pushup.config.ts'),
115+
);
116+
await writeFile(
117+
join(repo.baseDir, 'libs/ui/project.json'),
118+
(
119+
await readFile(join(repo.baseDir, 'libs/ui/project.json'), 'utf8')
120+
).replace('code-pushup.config.js', 'code-pushup.config.ts'),
121+
);
122+
123+
await git.add('.');
124+
await git.commit('Convert JS->TS for api and ui, TS->JS for web');
125+
126+
refs = {
127+
head: { ref: 'feature-1', sha: await git.revparse('feature-1') },
128+
base: { ref: 'main', sha: await git.revparse('main') },
129+
};
130+
});
131+
132+
it('should compare reports for all projects, detect new issues and merge into Markdown comment', async () => {
133+
await expect(runInCI(refs, MOCK_API, options, git)).resolves.toEqual({
134+
mode: 'monorepo',
135+
commentId: MOCK_COMMENT.id,
136+
diffPath: join(repo.baseDir, '.code-pushup/merged-report-diff.md'),
137+
projects: expect.arrayContaining<ProjectRunResult>([
138+
{
139+
name: 'web',
140+
files: {
141+
report: {
142+
json: join(repo.baseDir, 'apps/web/.code-pushup/report.json'),
143+
md: join(repo.baseDir, 'apps/web/.code-pushup/report.md'),
144+
},
145+
diff: {
146+
json: join(
147+
repo.baseDir,
148+
'apps/web/.code-pushup/report-diff.json',
149+
),
150+
md: join(repo.baseDir, 'apps/web/.code-pushup/report-diff.md'),
151+
},
152+
},
153+
newIssues: [
154+
{
155+
message: 'Use .ts file extension instead of .js',
156+
severity: 'warning',
157+
source: { file: 'apps/web/src/index.js' },
158+
plugin: expect.objectContaining({ slug: 'ts-migration' }),
159+
audit: expect.objectContaining({ slug: 'ts-files' }),
160+
},
161+
],
162+
},
163+
]),
164+
} satisfies RunResult);
165+
166+
const mdPromise = readFile(
167+
join(repo.baseDir, '.code-pushup/merged-report-diff.md'),
168+
'utf8',
169+
);
170+
await expect(mdPromise).resolves.toBeTruthy();
171+
const md = await mdPromise;
172+
await expect(
173+
md.replace(/[\da-f]{40}/g, '`<commit-sha>`'),
174+
).toMatchFileSnapshot(
175+
join(TEST_SNAPSHOTS_DIR, 'nx-monorepo-report-diff.md'),
176+
);
177+
});
178+
});
91179
});

0 commit comments

Comments
 (0)