-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbasic.e2e.test.ts
More file actions
149 lines (136 loc) · 4.05 KB
/
basic.e2e.test.ts
File metadata and controls
149 lines (136 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { readFile, rename } from 'node:fs/promises';
import path from 'node:path';
import type { SimpleGit } from 'simple-git';
import { afterEach } from 'vitest';
import {
type GitRefs,
type Options,
type RunResult,
runInCI,
} from '@code-pushup/ci';
import { TEST_SNAPSHOTS_DIR } from '@code-pushup/test-utils';
import { MOCK_API, MOCK_COMMENT } from '../mocks/api.js';
import { type TestRepo, setupTestRepo } from '../mocks/setup.js';
describe('CI - standalone mode', () => {
let repo: TestRepo;
let git: SimpleGit;
let options: Options;
beforeEach(async () => {
repo = await setupTestRepo('basic');
git = repo.git;
options = {
directory: repo.baseDir,
silent: true, // comment out for debugging
};
});
afterEach(async () => {
await repo.cleanup();
});
describe('push event', () => {
beforeEach(async () => {
await git.checkout('main');
});
it('should collect report', async () => {
await expect(
runInCI(
{ head: { ref: 'main', sha: await git.revparse('main') } },
MOCK_API,
options,
git,
),
).resolves.toEqual({
mode: 'standalone',
files: {
current: {
json: path.join(
repo.baseDir,
'.code-pushup/.ci/.current/report.json',
),
md: path.join(repo.baseDir, '.code-pushup/.ci/.current/report.md'),
},
},
} satisfies RunResult);
const jsonPromise = readFile(
path.join(repo.baseDir, '.code-pushup/.ci/.current/report.json'),
'utf8',
);
await expect(jsonPromise).resolves.toBeTruthy();
const report = JSON.parse(await jsonPromise) as Report;
expect(report).toEqual(
expect.objectContaining({
plugins: [
expect.objectContaining({
slug: 'ts-migration',
audits: [
expect.objectContaining({
score: 0.5,
displayValue: '50% converted',
}),
],
}),
],
}),
);
});
});
describe('pull request event', () => {
let refs: GitRefs;
beforeEach(async () => {
await git.checkoutLocalBranch('feature-1');
await rename(
path.join(repo.baseDir, 'index.js'),
path.join(repo.baseDir, 'index.ts'),
);
await git.add('index.ts');
await git.commit('Convert JS file to TS');
refs = {
head: { ref: 'feature-1', sha: await git.revparse('feature-1') },
base: { ref: 'main', sha: await git.revparse('main') },
};
});
it('should compare reports', async () => {
await expect(runInCI(refs, MOCK_API, options, git)).resolves.toEqual({
mode: 'standalone',
commentId: MOCK_COMMENT.id,
newIssues: [],
files: {
current: {
json: path.join(
repo.baseDir,
'.code-pushup/.ci/.current/report.json',
),
md: path.join(repo.baseDir, '.code-pushup/.ci/.current/report.md'),
},
previous: {
json: path.join(
repo.baseDir,
'.code-pushup/.ci/.previous/report.json',
),
md: path.join(repo.baseDir, '.code-pushup/.ci/.previous/report.md'),
},
comparison: {
json: path.join(
repo.baseDir,
'.code-pushup/.ci/.comparison/report-diff.json',
),
md: path.join(
repo.baseDir,
'.code-pushup/.ci/.comparison/report-diff.md',
),
},
},
} satisfies RunResult);
const mdPromise = readFile(
path.join(repo.baseDir, '.code-pushup/.ci/.comparison/report-diff.md'),
'utf8',
);
await expect(mdPromise).resolves.toBeTruthy();
const md = await mdPromise;
await expect(
md.replace(/[\da-f]{40}/g, '`<commit-sha>`'),
).toMatchFileSnapshot(
path.join(TEST_SNAPSHOTS_DIR, 'basic-report-diff.md'),
);
});
});
});