-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcollect.e2e.test.ts
More file actions
91 lines (81 loc) · 2.62 KB
/
collect.e2e.test.ts
File metadata and controls
91 lines (81 loc) · 2.62 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
import { cp } from 'node:fs/promises';
import path from 'node:path';
import { afterAll, beforeAll, expect } from 'vitest';
import { type Report, reportSchema } from '@code-pushup/models';
import { nxTargetProject } from '@code-pushup/test-nx-utils';
import {
E2E_ENVIRONMENTS_DIR,
TEST_OUTPUT_DIR,
omitVariableReportData,
osAgnosticAuditOutputs,
osAgnosticPath,
restoreNxIgnoredFiles,
teardownTestFolder,
} from '@code-pushup/test-utils';
import { executeProcess, readJsonFile } from '@code-pushup/utils';
function sanitizeReportPaths(report: Report): Report {
return {
...report,
plugins: report.plugins.map(plugin => ({
...plugin,
audits: osAgnosticAuditOutputs(plugin.audits, message =>
message.replace(
/['"]([^'"]*[/\\][^'"]*)['"]/g,
(fullMatch: string, capturedPath: string) => {
const osAgnostic = osAgnosticPath(capturedPath);
// Only replace directory paths, not .ts file paths
if (capturedPath.endsWith('.ts')) {
return `'${osAgnostic}'`;
}
// on Windows the path starts from "plugin-typescript-e2e/src" not "./". This normalizes it to "./<segment>"
return `'${['.', osAgnostic.split('/').slice(-1)].join('/')}'`;
},
),
),
})),
};
}
describe('PLUGIN collect report with typescript-plugin NPM package', () => {
const envRoot = path.join(E2E_ENVIRONMENTS_DIR, nxTargetProject());
const distRoot = path.join(envRoot, TEST_OUTPUT_DIR);
const fixturesDir = path.join(
'e2e',
nxTargetProject(),
'mocks',
'fixtures',
'default-setup',
);
beforeAll(async () => {
await cp(fixturesDir, envRoot, { recursive: true });
await restoreNxIgnoredFiles(envRoot);
});
afterAll(async () => {
await teardownTestFolder(distRoot);
});
it('should run plugin over CLI and creates report.json', async () => {
const outputDir = path.join(
path.relative(envRoot, distRoot),
'create-report',
'.code-pushup',
);
const { code } = await executeProcess({
command: 'npx',
// verbose exposes audits with perfect scores that are hidden in the default stdout
args: [
'@code-pushup/cli',
'collect',
'--verbose',
`--persist.outputDir=${outputDir}`,
],
cwd: envRoot,
});
expect(code).toBe(0);
const reportJson = await readJsonFile<Report>(
path.join(envRoot, outputDir, 'report.json'),
);
expect(() => reportSchema.parse(reportJson)).not.toThrow();
expect(
omitVariableReportData(sanitizeReportPaths(reportJson)),
).toMatchSnapshot();
});
});