|
1 | | -import {cp} from 'node:fs/promises'; |
| 1 | +import { cp } from 'node:fs/promises'; |
2 | 2 | import path from 'node:path'; |
3 | | -import {afterAll, beforeAll, describe, expect, it} from 'vitest'; |
4 | | -import {auditOutputsSchema} from '@code-pushup/models'; |
5 | | -import {nxTargetProject} from '@code-pushup/test-nx-utils'; |
| 3 | +import { afterAll, beforeAll, describe, expect, it } from 'vitest'; |
| 4 | +import { auditOutputsSchema } from '@code-pushup/models'; |
| 5 | +import { nxTargetProject } from '@code-pushup/test-nx-utils'; |
6 | 6 | import { |
7 | | - E2E_ENVIRONMENTS_DIR, |
8 | | - TEST_OUTPUT_DIR, |
9 | | - restoreNxIgnoredFiles, |
10 | | - teardownTestFolder, |
| 7 | + E2E_ENVIRONMENTS_DIR, |
| 8 | + TEST_OUTPUT_DIR, |
| 9 | + restoreNxIgnoredFiles, |
| 10 | + teardownTestFolder, |
11 | 11 | } from '@code-pushup/test-utils'; |
12 | | -import {executeProcess, readJsonFile} from '@code-pushup/utils'; |
| 12 | +import { executeProcess, readJsonFile } from '@code-pushup/utils'; |
13 | 13 |
|
14 | 14 | describe('knip reporter for code pushup audits', () => { |
15 | | - const envDir = path.join(E2E_ENVIRONMENTS_DIR, nxTargetProject()); |
16 | | - const testFileDir = path.join(envDir, TEST_OUTPUT_DIR, 'reporter'); |
17 | | - const reporterSetupDir = path.join(testFileDir, 'reporter-setup'); |
18 | | - const fixturesDir = path.join('e2e', nxTargetProject(), 'mocks/fixtures'); |
19 | | - const reporterPath = path.resolve( |
20 | | - envDir, |
21 | | - 'node_modules', |
22 | | - '@code-pushup', |
23 | | - 'knip-plugin', |
24 | | - 'src', |
25 | | - 'lib', |
26 | | - 'reporter.js', |
27 | | - ); |
| 15 | + const envDir = path.join(E2E_ENVIRONMENTS_DIR, nxTargetProject()); |
| 16 | + const testFileDir = path.join(envDir, TEST_OUTPUT_DIR, 'reporter'); |
| 17 | + const reporterSetupDir = path.join(testFileDir, 'reporter-setup'); |
| 18 | + const fixturesDir = path.join('e2e', nxTargetProject(), 'mocks/fixtures'); |
| 19 | + const reporterPath = path.resolve( |
| 20 | + envDir, |
| 21 | + 'node_modules', |
| 22 | + '@code-pushup', |
| 23 | + 'knip-plugin', |
| 24 | + 'src', |
| 25 | + 'lib', |
| 26 | + 'reporter.js', |
| 27 | + ); |
28 | 28 |
|
29 | | - beforeAll(async () => { |
30 | | - await cp(fixturesDir, testFileDir, {recursive: true}); |
31 | | - await restoreNxIgnoredFiles(testFileDir); |
32 | | - }); |
| 29 | + beforeAll(async () => { |
| 30 | + await cp(fixturesDir, testFileDir, { recursive: true }); |
| 31 | + await restoreNxIgnoredFiles(testFileDir); |
| 32 | + }); |
33 | 33 |
|
34 | | - afterAll(async () => { |
35 | | - await teardownTestFolder(testFileDir); |
36 | | - }); |
| 34 | + afterAll(async () => { |
| 35 | + await teardownTestFolder(testFileDir); |
| 36 | + }); |
37 | 37 |
|
38 | | - it('should execute knip with custom reporter and generate report', async () => { |
39 | | - const outputFile = path.join(reporterSetupDir, 'knip-report.json'); |
| 38 | + it('should execute knip with custom reporter and generate report', async () => { |
| 39 | + const outputFile = path.join(reporterSetupDir, 'knip-report.json'); |
40 | 40 |
|
41 | | - const {code} = await executeProcess({ |
42 | | - command: 'npx', |
43 | | - args: [ |
44 | | - 'knip', |
45 | | - '--no-exit-code', |
46 | | - `--reporter=${reporterPath}`, |
47 | | - /* eslint-disable-next-line no-useless-escape */ |
48 | | - `--reporter-options={\"outputFile\":\"knip-report.json\"}'`, |
49 | | - ], |
50 | | - cwd: reporterSetupDir, |
51 | | - }); |
| 41 | + const { code } = await executeProcess({ |
| 42 | + command: 'npx', |
| 43 | + args: [ |
| 44 | + 'knip', |
| 45 | + '--no-exit-code', |
| 46 | + `--reporter=${reporterPath}`, |
| 47 | + /* eslint-disable-next-line no-useless-escape */ |
| 48 | + `--reporter-options={\"outputFile\":\"knip-report.json\"}'`, |
| 49 | + ], |
| 50 | + cwd: reporterSetupDir, |
| 51 | + }); |
52 | 52 |
|
53 | | - expect(code).toBe(0); |
| 53 | + expect(code).toBe(0); |
54 | 54 |
|
55 | | - const report = await readJsonFile(outputFile); |
56 | | - expect(() => auditOutputsSchema.parse(report)).not.toThrowError(); |
57 | | - expect(report).toStrictEqual( |
58 | | - expect.arrayContaining([ |
59 | | - expect.objectContaining({ |
60 | | - slug: 'dependencies', |
61 | | - score: 0, |
62 | | - value: 1, |
63 | | - details: { |
64 | | - issues: [ |
65 | | - { |
66 | | - message: 'Unused dependency zod', |
67 | | - severity: 'error', |
68 | | - source: { |
69 | | - "file": "tmp/e2e/plugin-knip-e2e/__test__/reporter/reporter-setup/package.json", |
70 | | - "position": { |
71 | | - "startColumn": 6, |
72 | | - "startLine": 4, |
73 | | - }, |
74 | | - }, |
75 | | - }, |
76 | | - ], |
77 | | - }, |
78 | | - }), |
79 | | - ]), |
80 | | - ); |
81 | | - }); |
| 55 | + const report = await readJsonFile(outputFile); |
| 56 | + expect(() => auditOutputsSchema.parse(report)).not.toThrowError(); |
| 57 | + expect(report).toStrictEqual( |
| 58 | + expect.arrayContaining([ |
| 59 | + expect.objectContaining({ |
| 60 | + slug: 'dependencies', |
| 61 | + score: 0, |
| 62 | + value: 1, |
| 63 | + details: { |
| 64 | + issues: [ |
| 65 | + { |
| 66 | + message: 'Unused dependency zod', |
| 67 | + severity: 'error', |
| 68 | + source: { |
| 69 | + file: 'tmp/e2e/plugin-knip-e2e/__test__/reporter/reporter-setup/package.json', |
| 70 | + position: { |
| 71 | + startColumn: 6, |
| 72 | + startLine: 4, |
| 73 | + }, |
| 74 | + }, |
| 75 | + }, |
| 76 | + ], |
| 77 | + }, |
| 78 | + }), |
| 79 | + ]), |
| 80 | + ); |
| 81 | + }); |
82 | 82 | }); |
0 commit comments