-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcollect.e2e.test.ts
More file actions
131 lines (114 loc) · 3.31 KB
/
Copy pathcollect.e2e.test.ts
File metadata and controls
131 lines (114 loc) · 3.31 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
import { cp } from 'node:fs/promises';
import path from 'node:path';
import { afterEach, beforeAll, describe, expect, it } from 'vitest';
import { nxTargetProject } from '@code-pushup/test-nx-utils';
import {
E2E_ENVIRONMENTS_DIR,
NX_IGNORED_FILES_TO_RESTORE,
TEST_OUTPUT_DIR,
restoreRenamedFiles,
teardownTestFolder,
} from '@code-pushup/test-utils';
import {
executeProcess,
fileExists,
readJsonFile,
readTextFile,
} from '@code-pushup/utils';
import { dummyPluginSlug } from '../mocks/fixtures/dummy-setup/dummy.plugin';
describe('CLI collect', () => {
const dummyPluginTitle = 'Dummy Plugin';
const dummyAuditTitle = 'Dummy Audit';
const fixtureDummyDir = path.join(
'e2e',
nxTargetProject(),
'mocks',
'fixtures',
'dummy-setup',
);
const testFileDir = path.join(
E2E_ENVIRONMENTS_DIR,
nxTargetProject(),
TEST_OUTPUT_DIR,
'collect',
);
const dummyDir = path.join(testFileDir, 'dummy-setup');
const dummyOutputDir = path.join(dummyDir, '.code-pushup');
beforeAll(async () => {
await cp(fixtureDummyDir, dummyDir, { recursive: true });
await restoreRenamedFiles(dummyDir, NX_IGNORED_FILES_TO_RESTORE);
});
afterAll(async () => {
await teardownTestFolder(dummyDir);
});
afterEach(async () => {
await teardownTestFolder(dummyOutputDir);
});
it('should create report.md', async () => {
const { code } = await executeProcess({
command: 'npx',
args: [
'@code-pushup/cli',
'--no-progress',
'collect',
'--persist.format=md',
],
cwd: dummyDir,
});
expect(code).toBe(0);
const md = await readTextFile(path.join(dummyOutputDir, 'report.md'));
expect(md).toContain('# Code PushUp Report');
expect(md).toContain(dummyPluginTitle);
expect(md).toContain(dummyAuditTitle);
});
it('should write runner outputs if --cache is given', async () => {
const { code } = await executeProcess({
command: 'npx',
args: ['@code-pushup/cli', '--no-progress', 'collect', '--cache'],
cwd: dummyDir,
});
expect(code).toBe(0);
await expect(
readJsonFile(
path.join(dummyOutputDir, dummyPluginSlug, 'runner-output.json'),
),
).resolves.toStrictEqual([
{
slug: 'dummy-audit',
score: 0.3,
value: 3,
},
]);
});
it('should not create reports if --persist.skipReports is given', async () => {
const { code } = await executeProcess({
command: 'npx',
args: [
'@code-pushup/cli',
'--no-progress',
'collect',
'--persist.skipReports',
],
cwd: dummyDir,
});
expect(code).toBe(0);
await expect(
fileExists(path.join(dummyOutputDir, 'report.md')),
).resolves.toBeFalsy();
await expect(
fileExists(path.join(dummyOutputDir, 'report.json')),
).resolves.toBeFalsy();
});
it('should print report summary to stdout', async () => {
const { code, stdout } = await executeProcess({
command: 'npx',
args: ['@code-pushup/cli', '--no-progress', 'collect'],
cwd: dummyDir,
});
expect(code).toBe(0);
expect(stdout).toContain('Code PushUp Report');
expect(stdout).not.toContain('Generated reports');
expect(stdout).toContain(dummyPluginTitle);
expect(stdout).toContain(dummyAuditTitle);
});
});