|
| 1 | +import { cp } from 'node:fs/promises'; |
| 2 | +import path from 'node:path'; |
| 3 | +import { afterAll, beforeAll, expect } from 'vitest'; |
| 4 | +import { type Report, reportSchema } from '@code-pushup/models'; |
| 5 | +import { nxTargetProject } from '@code-pushup/test-nx-utils'; |
| 6 | +import { |
| 7 | + E2E_ENVIRONMENTS_DIR, |
| 8 | + TEST_OUTPUT_DIR, |
| 9 | + omitVariableReportData, |
| 10 | + restoreNxIgnoredFiles, |
| 11 | + teardownTestFolder, |
| 12 | +} from '@code-pushup/test-utils'; |
| 13 | +import { executeProcess, readJsonFile } from '@code-pushup/utils'; |
| 14 | + |
| 15 | +describe('PLUGIN collect report with knip-plugin NPM package', () => { |
| 16 | + const testFileDir = path.join( |
| 17 | + E2E_ENVIRONMENTS_DIR, |
| 18 | + nxTargetProject(), |
| 19 | + TEST_OUTPUT_DIR, |
| 20 | + 'collect', |
| 21 | + ); |
| 22 | + const defaultSetupDir = path.join(testFileDir, 'default-setup'); |
| 23 | + |
| 24 | + const fixturesDir = path.join('e2e', nxTargetProject(), 'mocks/fixtures'); |
| 25 | + |
| 26 | + beforeAll(async () => { |
| 27 | + await cp(fixturesDir, testFileDir, { recursive: true }); |
| 28 | + await restoreNxIgnoredFiles(testFileDir); |
| 29 | + }); |
| 30 | + |
| 31 | + afterAll(async () => { |
| 32 | + await teardownTestFolder(testFileDir); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should run plugin over CLI and creates report.json', async () => { |
| 36 | + const { code, stdout } = await executeProcess({ |
| 37 | + command: 'npx', |
| 38 | + // verbose exposes audits with perfect scores that are hidden in the default stdout |
| 39 | + args: ['@code-pushup/cli', 'collect', '--verbose'], |
| 40 | + cwd: defaultSetupDir, |
| 41 | + }); |
| 42 | + |
| 43 | + expect(code).toBe(0); |
| 44 | + // TODO: test knip output with toContain |
| 45 | + expect(stdout).toBe('knip string'); |
| 46 | + |
| 47 | + const report = await readJsonFile( |
| 48 | + path.join(defaultSetupDir, '.code-pushup', 'report.json'), |
| 49 | + ); |
| 50 | + expect(() => reportSchema.parse(report)).not.toThrow(); |
| 51 | + expect( |
| 52 | + omitVariableReportData(report as Report, { omitAuditData: true }), |
| 53 | + ).toMatchSnapshot(); |
| 54 | + }); |
| 55 | +}); |
0 commit comments