|
1 | | -import { cp, rm } from 'node:fs/promises'; |
| 1 | +import { cp } from 'node:fs/promises'; |
2 | 2 | import { join } from 'node:path'; |
3 | | -import { afterEach } from 'vitest'; |
| 3 | +import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest'; |
4 | 4 | import { type Report, reportSchema } from '@code-pushup/models'; |
5 | 5 | import { teardownTestFolder } from '@code-pushup/test-setup'; |
6 | 6 | import { omitVariableReportData } from '@code-pushup/test-utils'; |
7 | 7 | import { executeProcess, readJsonFile } from '@code-pushup/utils'; |
8 | 8 |
|
9 | 9 | describe('collect report with eslint-plugin NPM package', () => { |
10 | | - const fixturesDir = join('e2e', 'plugin-eslint-e2e', 'mocks', 'fixtures'); |
11 | | - const envRoot = join('tmp', 'plugin-eslint-e2e', '__test-env__'); |
12 | | - const outputDir = join(envRoot, '.code-pushup'); |
| 10 | + const fixturesOldVersionDir = join( |
| 11 | + 'e2e', |
| 12 | + 'plugin-eslint-e2e', |
| 13 | + 'mocks', |
| 14 | + 'fixtures', |
| 15 | + 'old-version', |
| 16 | + ); |
| 17 | + const envRoot = join('tmp', 'e2e', 'plugin-eslint-e2e'); |
| 18 | + const oldVersionDir = join(envRoot, 'old-version'); |
| 19 | + const oldVersionOutputDir = join(oldVersionDir, '.code-pushup'); |
13 | 20 |
|
14 | 21 | beforeAll(async () => { |
15 | | - await cp(fixturesDir, envRoot, { recursive: true }); |
| 22 | + await cp(fixturesOldVersionDir, oldVersionDir, { recursive: true }); |
16 | 23 | }); |
17 | 24 |
|
18 | 25 | afterAll(async () => { |
19 | | - await rm(envRoot, { recursive: true, force: true }); |
| 26 | + await teardownTestFolder(oldVersionDir); |
20 | 27 | }); |
21 | 28 |
|
22 | 29 | afterEach(async () => { |
23 | | - await teardownTestFolder(outputDir); |
| 30 | + await teardownTestFolder(oldVersionOutputDir); |
24 | 31 | }); |
25 | 32 |
|
26 | 33 | it('should run ESLint plugin and create report.json', async () => { |
27 | 34 | const { code, stderr } = await executeProcess({ |
28 | 35 | command: 'npx', |
29 | | - args: [ |
30 | | - '@code-pushup/cli', |
31 | | - 'collect', |
32 | | - '--no-progress', |
33 | | - '--onlyPlugins=eslint', |
34 | | - ], |
35 | | - cwd: envRoot, |
| 36 | + args: ['@code-pushup/cli', 'collect', '--no-progress'], |
| 37 | + cwd: oldVersionDir, |
36 | 38 | }); |
37 | 39 |
|
38 | 40 | expect(code).toBe(0); |
39 | 41 | expect(stderr).toBe(''); |
40 | 42 |
|
41 | | - const report = await readJsonFile(join(outputDir, 'report.json')); |
| 43 | + const report = await readJsonFile(join(oldVersionOutputDir, 'report.json')); |
42 | 44 |
|
43 | 45 | expect(() => reportSchema.parse(report)).not.toThrow(); |
44 | 46 | expect(omitVariableReportData(report as Report)).toMatchSnapshot(); |
|
0 commit comments