-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcollect.e2e.test.ts
More file actions
115 lines (98 loc) · 3.8 KB
/
collect.e2e.test.ts
File metadata and controls
115 lines (98 loc) · 3.8 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
import { cp } from 'node:fs/promises';
import path from 'node:path';
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
import { type Report, reportSchema } from '@code-pushup/models';
import { omitVariableReportData } from '@code-pushup/test-fixtures';
import { nxTargetProject } from '@code-pushup/test-nx-utils';
import {
E2E_ENVIRONMENTS_DIR,
TEST_OUTPUT_DIR,
restoreNxIgnoredFiles,
teardownTestFolder,
} from '@code-pushup/test-utils';
import { executeProcess, readJsonFile } from '@code-pushup/utils';
describe('PLUGIN collect report with eslint-plugin NPM package', () => {
const fixturesDir = path.join(
'e2e',
'plugin-eslint-e2e',
'mocks',
'fixtures',
);
const fixturesFlatConfigDir = path.join(fixturesDir, 'flat-config');
const fixturesLegacyConfigDir = path.join(fixturesDir, 'legacy-config');
const fixturesArtifactsConfigDir = path.join(fixturesDir, 'artifacts-config');
const envRoot = path.join(
E2E_ENVIRONMENTS_DIR,
nxTargetProject(),
TEST_OUTPUT_DIR,
);
const flatConfigDir = path.join(envRoot, 'flat-config');
const legacyConfigDir = path.join(envRoot, 'legacy-config');
const artifactsConfigDir = path.join(envRoot, 'artifacts-config');
const flatConfigOutputDir = path.join(flatConfigDir, '.code-pushup');
const legacyConfigOutputDir = path.join(legacyConfigDir, '.code-pushup');
const artifactsConfigOutputDir = path.join(
artifactsConfigDir,
'.code-pushup',
);
beforeAll(async () => {
await cp(fixturesFlatConfigDir, flatConfigDir, { recursive: true });
await restoreNxIgnoredFiles(flatConfigDir);
await cp(fixturesLegacyConfigDir, legacyConfigDir, { recursive: true });
await restoreNxIgnoredFiles(legacyConfigDir);
await cp(fixturesArtifactsConfigDir, artifactsConfigDir, {
recursive: true,
});
await restoreNxIgnoredFiles(artifactsConfigDir);
});
afterAll(async () => {
await teardownTestFolder(flatConfigDir);
await teardownTestFolder(legacyConfigDir);
await teardownTestFolder(artifactsConfigDir);
});
afterEach(async () => {
await teardownTestFolder(flatConfigOutputDir);
await teardownTestFolder(legacyConfigOutputDir);
await teardownTestFolder(artifactsConfigOutputDir);
});
it('should run ESLint plugin for flat config and create report.json', async () => {
const { code } = await executeProcess({
command: 'npx',
args: ['@code-pushup/cli', 'collect'],
cwd: flatConfigDir,
});
expect(code).toBe(0);
const report = await readJsonFile(
path.join(flatConfigOutputDir, 'report.json'),
);
expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});
it('should run ESLint plugin for legacy config and create report.json', async () => {
const { code } = await executeProcess({
command: 'npx',
args: ['@code-pushup/cli', 'collect'],
cwd: legacyConfigDir,
env: { ...process.env, ESLINT_USE_FLAT_CONFIG: 'false' },
});
expect(code).toBe(0);
const report = await readJsonFile(
path.join(legacyConfigOutputDir, 'report.json'),
);
expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});
it('should run ESLint plugin with artifacts options and create eslint-report.json and report.json', async () => {
const { code } = await executeProcess({
command: 'npx',
args: ['@code-pushup/cli', 'collect'],
cwd: artifactsConfigDir,
});
expect(code).toBe(0);
const report = await readJsonFile(
path.join(artifactsConfigOutputDir, 'report.json'),
);
expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});
});