From bd1b8e1bf570097f6590d8962f9381623a3765f5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 02:02:36 +0100 Subject: [PATCH 01/42] cherry-pick --- .github/workflows/ci.yml | 2 +- .gitignore | 2 + e2e/cli-e2e/project.json | 11 +-- e2e/cli-e2e/tests/collect.e2e.test.ts | 35 +++++++--- e2e/cli-e2e/tests/compare.e2e.test.ts | 9 ++- e2e/cli-e2e/tests/help.e2e.test.ts | 15 ++-- e2e/cli-e2e/tests/print-config.e2e.test.ts | 22 +++--- e2e/cli-e2e/vite.config.e2e.ts | 1 - examples/react-todos-app/.eslintrc.js | 69 ------------------- examples/react-todos-app/.eslintrc.json | 64 +++++++++++++++++ ...pushup.config.js => code-pushup.config.ts} | 6 +- examples/react-todos-app/package.json | 16 ----- nx.json | 3 + 13 files changed, 130 insertions(+), 125 deletions(-) delete mode 100644 examples/react-todos-app/.eslintrc.js create mode 100644 examples/react-todos-app/.eslintrc.json rename examples/react-todos-app/{code-pushup.config.js => code-pushup.config.ts} (93%) delete mode 100644 examples/react-todos-app/package.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 845def216..55fb01fe6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -122,7 +122,7 @@ jobs: - name: E2E test affected projects run: npx nx affected -t nxv-e2e --exclude cli-e2e --parallel=1 - name: E2E test cli-e2e project (due to bugs in the setup it has to run last :( ) - run: npx nx run cli-e2e:e2e-old + run: npx nx run cli-e2e:nxv-e2e build: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 21c8b0424..01481eeee 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,8 @@ node_modules /connect.lock /coverage /examples/react-todos-app/coverage +/examples/react-todos-app/package.json +/examples/react-todos-app/package-lock.json /libpeerconnection.log npm-debug.log yarn-error.log diff --git a/e2e/cli-e2e/project.json b/e2e/cli-e2e/project.json index 5bef1175d..f61dab7cc 100644 --- a/e2e/cli-e2e/project.json +++ b/e2e/cli-e2e/project.json @@ -11,17 +11,20 @@ "lintFilePatterns": ["e2e/cli-e2e/**/*.ts"] } }, + "nxv-env-setup": { + "options": { + "environmentRoot": "examples/react-todos-app" + } + }, "e2e-old": { "executor": "@nx/vite:test", "options": { - "configFile": "e2e/cli-e2e/vite.config.e2e.ts" + "configFile": "e2e/cli-e2e/vite.config.e2e.ts", + "environmentRoot": "examples/react-todos-app" } } }, "implicitDependencies": [ - "models", - "utils", - "core", "cli", "plugin-eslint", "plugin-coverage", diff --git a/e2e/cli-e2e/tests/collect.e2e.test.ts b/e2e/cli-e2e/tests/collect.e2e.test.ts index 5e301ab29..ba4676d49 100644 --- a/e2e/cli-e2e/tests/collect.e2e.test.ts +++ b/e2e/cli-e2e/tests/collect.e2e.test.ts @@ -51,8 +51,13 @@ describe('CLI collect', () => { it('should run ESLint plugin and create report.json', async () => { const { code, stderr } = await executeProcess({ - command: 'code-pushup', - args: ['collect', '--no-progress', '--onlyPlugins=eslint'], + command: 'npx', + args: [ + '@code-pushup/cli', + 'collect', + '--no-progress', + '--onlyPlugins=eslint', + ], cwd: 'examples/react-todos-app', }); @@ -83,14 +88,16 @@ describe('CLI collect', () => { ); const { code, stderr } = await executeProcess({ - command: 'code-pushup', + command: 'npx', args: [ + '@code-pushup/cli', 'collect', '--no-progress', `--config=${configPath}`, '--persist.outputDir=tmp/e2e', '--onlyPlugins=coverage', ], + cwd: 'examples/react-todos-app', }); expect(code).toBe(0); @@ -104,8 +111,13 @@ describe('CLI collect', () => { it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => { const { code, stderr } = await executeProcess({ - command: 'code-pushup', - args: ['collect', '--no-progress', '--onlyPlugins=coverage'], + command: 'npx', + args: [ + '@code-pushup/cli', + 'collect', + '--no-progress', + '--onlyPlugins=coverage', + ], cwd: 'examples/react-todos-app', }); @@ -120,8 +132,13 @@ describe('CLI collect', () => { it('should create report.md', async () => { const { code, stderr } = await executeProcess({ - command: 'code-pushup', - args: ['collect', '--persist.format=md', '--no-progress'], + command: 'npx', + args: [ + '@code-pushup/cli', + 'collect', + '--persist.format=md', + '--no-progress', + ], cwd: 'examples/react-todos-app', }); @@ -137,8 +154,8 @@ describe('CLI collect', () => { it('should print report summary to stdout', async () => { const { code, stdout, stderr } = await executeProcess({ - command: 'code-pushup', - args: ['collect', '--no-progress'], + command: 'npx', + args: ['@code-pushup/cli', 'collect', '--no-progress'], cwd: 'examples/react-todos-app', }); diff --git a/e2e/cli-e2e/tests/compare.e2e.test.ts b/e2e/cli-e2e/tests/compare.e2e.test.ts index 9f5744c9f..c80eb9e24 100644 --- a/e2e/cli-e2e/tests/compare.e2e.test.ts +++ b/e2e/cli-e2e/tests/compare.e2e.test.ts @@ -14,8 +14,9 @@ describe('CLI compare', () => { } await cleanTestFolder('tmp/e2e/react-todos-app'); await executeProcess({ - command: 'code-pushup', + command: 'npx', args: [ + '@code-pushup/cli', 'collect', '--persist.filename=source-report', '--onlyPlugins=eslint', @@ -28,8 +29,9 @@ describe('CLI compare', () => { cwd: 'examples/react-todos-app', }); await executeProcess({ - command: 'code-pushup', + command: 'npx', args: [ + '@code-pushup/cli', 'collect', '--persist.filename=target-report', '--onlyPlugins=eslint', @@ -45,8 +47,9 @@ describe('CLI compare', () => { it('should compare report.json files and create report-diff.json and report-diff.md', async () => { await executeProcess({ - command: 'code-pushup', + command: 'npx', args: [ + '@code-pushup/cli', 'compare', '--before=../../tmp/e2e/react-todos-app/source-report.json', '--after=../../tmp/e2e/react-todos-app/target-report.json', diff --git a/e2e/cli-e2e/tests/help.e2e.test.ts b/e2e/cli-e2e/tests/help.e2e.test.ts index cf5316be1..40032dfe9 100644 --- a/e2e/cli-e2e/tests/help.e2e.test.ts +++ b/e2e/cli-e2e/tests/help.e2e.test.ts @@ -4,8 +4,9 @@ import { executeProcess } from '@code-pushup/utils'; describe('CLI help', () => { it('should print help with help command', async () => { const { code, stdout, stderr } = await executeProcess({ - command: 'code-pushup', - args: ['help'], + command: 'npx', + args: ['@code-pushup/cli', 'help'], + cwd: 'examples/react-todos-app', }); expect(code).toBe(0); expect(stderr).toBe(''); @@ -14,12 +15,14 @@ describe('CLI help', () => { it('should produce the same output to stdout for both help argument and help command', async () => { const helpArgResult = await executeProcess({ - command: 'code-pushup', - args: ['help'], + command: 'npx', + args: ['@code-pushup/cli', 'help'], + cwd: 'examples/react-todos-app', }); const helpCommandResult = await executeProcess({ - command: 'code-pushup', - args: ['--help'], + command: 'npx', + args: ['@code-pushup/cli', '--help'], + cwd: 'examples/react-todos-app', }); expect(helpArgResult.code).toBe(0); expect(helpCommandResult.code).toBe(0); diff --git a/e2e/cli-e2e/tests/print-config.e2e.test.ts b/e2e/cli-e2e/tests/print-config.e2e.test.ts index 46190659d..75ef57e76 100644 --- a/e2e/cli-e2e/tests/print-config.e2e.test.ts +++ b/e2e/cli-e2e/tests/print-config.e2e.test.ts @@ -6,29 +6,29 @@ const extensions = ['js', 'mjs', 'ts'] as const; export const configFilePath = (ext: (typeof extensions)[number]) => join(process.cwd(), `e2e/cli-e2e/mocks/fixtures/code-pushup.config.${ext}`); -describe('print-config', () => { +describe('CLI print-config', () => { it.each(extensions)( 'should load .%s config file with correct arguments', async ext => { const { code, stdout } = await executeProcess({ - command: 'code-pushup', + command: 'npx', args: [ + '@code-pushup/cli', 'print-config', '--no-progress', - `--config=${configFilePath(ext)}`, '--tsconfig=tsconfig.base.json', '--persist.outputDir=output-dir', '--persist.format=md', `--persist.filename=${ext}-report`, '--onlyPlugins=coverage', ], + cwd: 'examples/react-todos-app', }); expect(code).toBe(0); expect(JSON.parse(stdout)).toEqual( expect.objectContaining({ - config: expect.stringContaining(`code-pushup.config.${ext}`), tsconfig: 'tsconfig.base.json', // filled by command options persist: { @@ -36,19 +36,15 @@ describe('print-config', () => { filename: `${ext}-report`, format: ['md'], }, - upload: { - organization: 'code-pushup', - project: `cli-${ext}`, - apiKey: 'e2e-api-key', - server: 'https://e2e.com/api', - }, - plugins: [ + plugins: expect.arrayContaining([ expect.objectContaining({ slug: 'coverage', title: 'Code coverage', }), - ], - categories: [expect.objectContaining({ slug: 'code-coverage' })], + ]), + categories: expect.arrayContaining([ + expect.objectContaining({ slug: 'code-coverage' }), + ]), onlyPlugins: ['coverage'], }), ); diff --git a/e2e/cli-e2e/vite.config.e2e.ts b/e2e/cli-e2e/vite.config.e2e.ts index f1b3c3b93..2514c0209 100644 --- a/e2e/cli-e2e/vite.config.e2e.ts +++ b/e2e/cli-e2e/vite.config.e2e.ts @@ -16,7 +16,6 @@ export default defineConfig({ }, environment: 'node', include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], - globalSetup: ['../../global-setup.e2e.ts'], setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'], }, }); diff --git a/examples/react-todos-app/.eslintrc.js b/examples/react-todos-app/.eslintrc.js deleted file mode 100644 index e05f2bb62..000000000 --- a/examples/react-todos-app/.eslintrc.js +++ /dev/null @@ -1,69 +0,0 @@ -/** @type {import('eslint').ESLint.ConfigData} */ -module.exports = { - root: true, - env: { - browser: true, - es2021: true, - }, - plugins: ['react', 'react-hooks'], - overrides: [ - { - env: { - node: true, - }, - files: ['.eslintrc.{js,cjs}'], - parserOptions: { - sourceType: 'script', - }, - }, - ], - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - ecmaFeatures: { - jsx: true, - }, - }, - settings: { - react: { - version: 'detect', - }, - }, - rules: { - // https://eslint.org/docs/latest/rules/#possible-problems - 'no-cond-assign': 'warn', - 'no-const-assign': 'warn', - 'no-debugger': 'warn', - 'no-invalid-regexp': 'warn', - 'no-undef': 'warn', - 'no-unreachable-loop': 'warn', - 'no-unsafe-negation': 'warn', - 'no-unsafe-optional-chaining': 'warn', - 'no-unused-vars': 'warn', - 'use-isnan': 'warn', - 'valid-typeof': 'warn', - // https://eslint.org/docs/latest/rules/#suggestions - 'arrow-body-style': 'warn', - camelcase: 'warn', - curly: 'warn', - eqeqeq: 'warn', - 'max-lines-per-function': 'warn', - 'max-lines': 'warn', - 'no-shadow': 'warn', - 'no-var': 'warn', - 'object-shorthand': 'warn', - 'prefer-arrow-callback': 'warn', - 'prefer-const': 'warn', - 'prefer-object-spread': 'warn', - yoda: 'warn', - // https://github.com/jsx-eslint/eslint-plugin-react#list-of-supported-rules - 'react/jsx-key': 'warn', - 'react/prop-types': 'warn', - 'react/react-in-jsx-scope': 'warn', - 'react/jsx-uses-vars': 'warn', - 'react/jsx-uses-react': 'error', - // https://www.npmjs.com/package/eslint-plugin-react-hooks - 'react-hooks/rules-of-hooks': 'error', - 'react-hooks/exhaustive-deps': 'warn', - }, -}; diff --git a/examples/react-todos-app/.eslintrc.json b/examples/react-todos-app/.eslintrc.json new file mode 100644 index 000000000..9c50e51ca --- /dev/null +++ b/examples/react-todos-app/.eslintrc.json @@ -0,0 +1,64 @@ +{ + "root": true, + "env": { + "browser": true, + "es2021": true + }, + "plugins": ["react", "react-hooks"], + "overrides": [ + { + "env": { + "node": true + }, + "files": [".eslintrc.{js,cjs}"], + "parserOptions": { + "sourceType": "script" + } + } + ], + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module", + "ecmaFeatures": { + "jsx": true + } + }, + "settings": { + "react": { + "version": "detect" + } + }, + "rules": { + "no-cond-assign": "warn", + "no-const-assign": "warn", + "no-debugger": "warn", + "no-invalid-regexp": "warn", + "no-undef": "warn", + "no-unreachable-loop": "warn", + "no-unsafe-negation": "warn", + "no-unsafe-optional-chaining": "warn", + "no-unused-vars": "warn", + "use-isnan": "warn", + "valid-typeof": "warn", + "arrow-body-style": "warn", + "camelcase": "warn", + "curly": "warn", + "eqeqeq": "warn", + "max-lines-per-function": "warn", + "max-lines": "warn", + "no-shadow": "warn", + "no-var": "warn", + "object-shorthand": "warn", + "prefer-arrow-callback": "warn", + "prefer-const": "warn", + "prefer-object-spread": "warn", + "yoda": "warn", + "react/jsx-key": "warn", + "react/prop-types": "warn", + "react/react-in-jsx-scope": "warn", + "react/jsx-uses-vars": "warn", + "react/jsx-uses-react": "error", + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "warn" + } +} diff --git a/examples/react-todos-app/code-pushup.config.js b/examples/react-todos-app/code-pushup.config.ts similarity index 93% rename from examples/react-todos-app/code-pushup.config.js rename to examples/react-todos-app/code-pushup.config.ts index dcef94a7f..60780c794 100644 --- a/examples/react-todos-app/code-pushup.config.js +++ b/examples/react-todos-app/code-pushup.config.ts @@ -1,5 +1,5 @@ -import coveragePlugin from '../../dist/packages/plugin-coverage'; -import eslintPlugin from '../../dist/packages/plugin-eslint'; +import coveragePlugin from '@code-pushup/coverage-plugin'; +import eslintPlugin from '@code-pushup/eslint-plugin'; const eslintAuditRef = (slug, weight) => ({ type: 'audit', @@ -21,7 +21,7 @@ export default { }, }), await eslintPlugin({ - eslintrc: '.eslintrc.js', + eslintrc: '.eslintrc.json', patterns: ['src/**/*.js', 'src/**/*.jsx'], }), ], diff --git a/examples/react-todos-app/package.json b/examples/react-todos-app/package.json deleted file mode 100644 index d9e892a84..000000000 --- a/examples/react-todos-app/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "todo-app", - "private": true, - "scripts": { - "start": "esbuild src/index.jsx --bundle --outdir=www/js --servedir=www", - "build": "esbuild src/index.jsx --bundle --outdir=www/js --minify" - }, - "dependencies": { - "react": "^16.12.0", - "semver": "5.7.1" - }, - "devDependencies": { - "vite": "~4.5.0", - "vitest": "0.34.0" - } -} diff --git a/nx.json b/nx.json index bebd69d65..b660413ce 100644 --- a/nx.json +++ b/nx.json @@ -28,6 +28,9 @@ "e2e": { "dependsOn": ["^build"] }, + "nxv-env-setup": { + "executor": "@push-based/nx-verdaccio:env-setup" + }, "@nx/vite:test": { "cache": true, "inputs": ["default", "^production"], From d92bf4684e72a8a0faecd925bfc224d3c6112aae Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 02:12:33 +0100 Subject: [PATCH 02/42] adjust target name --- e2e/cli-e2e/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/cli-e2e/project.json b/e2e/cli-e2e/project.json index f61dab7cc..c14b2d8cb 100644 --- a/e2e/cli-e2e/project.json +++ b/e2e/cli-e2e/project.json @@ -16,7 +16,7 @@ "environmentRoot": "examples/react-todos-app" } }, - "e2e-old": { + "e2e": { "executor": "@nx/vite:test", "options": { "configFile": "e2e/cli-e2e/vite.config.e2e.ts", From 8cc75ee47c71f08c7ca173c271b5a6dea1f6d35c Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 03:34:40 +0100 Subject: [PATCH 03/42] test: add eslint e2e project --- e2e/plugin-eslint-e2e/.eslintrc.json | 12 +++++++ e2e/plugin-eslint-e2e/project.json | 29 +++++++++++++++ .../tests/collect.e2e.test.ts | 35 +++++++++++++++++++ e2e/plugin-eslint-e2e/tsconfig.json | 20 +++++++++++ e2e/plugin-eslint-e2e/tsconfig.test.json | 14 ++++++++ e2e/plugin-eslint-e2e/vite.config.e2e.ts | 21 +++++++++++ 6 files changed, 131 insertions(+) create mode 100644 e2e/plugin-eslint-e2e/.eslintrc.json create mode 100644 e2e/plugin-eslint-e2e/project.json create mode 100644 e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts create mode 100644 e2e/plugin-eslint-e2e/tsconfig.json create mode 100644 e2e/plugin-eslint-e2e/tsconfig.test.json create mode 100644 e2e/plugin-eslint-e2e/vite.config.e2e.ts diff --git a/e2e/plugin-eslint-e2e/.eslintrc.json b/e2e/plugin-eslint-e2e/.eslintrc.json new file mode 100644 index 000000000..622f1f491 --- /dev/null +++ b/e2e/plugin-eslint-e2e/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*", "code-pushup.config*.ts"], + "overrides": [ + { + "files": ["*.ts", "*.tsx"], + "parserOptions": { + "project": ["e2e/plugin-eslint-e2e/tsconfig.*?.json"] + } + } + ] +} diff --git a/e2e/plugin-eslint-e2e/project.json b/e2e/plugin-eslint-e2e/project.json new file mode 100644 index 000000000..8edc665f8 --- /dev/null +++ b/e2e/plugin-eslint-e2e/project.json @@ -0,0 +1,29 @@ +{ + "name": "plugin-eslint-e2e", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "e2e/plugin-eslint-e2e/src", + "projectType": "application", + "targets": { + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["e2e/plugin-eslint-e2e/**/*.ts"] + } + }, + "nxv-env-setup": { + "options": { + "environmentRoot": "examples/eslint-example-app" + } + }, + "e2e": { + "executor": "@nx/vite:test", + "options": { + "configFile": "e2e/plugin-eslint-e2e/vite.config.e2e.ts", + "environmentRoot": "examples/eslint-example-app" + } + } + }, + "implicitDependencies": ["cli", "plugin-eslint", "eslint-e2e-env"], + "tags": ["scope:plugin", "type:e2e"] +} diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts new file mode 100644 index 000000000..52d6ebbaf --- /dev/null +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -0,0 +1,35 @@ +import { join } from 'node:path'; +import { afterEach } from 'vitest'; +import { type Report, reportSchema } from '@code-pushup/models'; +import { teardownTestFolder } from '@code-pushup/test-setup'; +import { omitVariableReportData } from '@code-pushup/test-utils'; +import { executeProcess, readJsonFile } from '@code-pushup/utils'; + +describe('collect report with eslint-plugin NPM package', () => { + const baseDir = 'eslint-e2e-env/__test__'; + + afterEach(async () => { + await teardownTestFolder(baseDir); + }); + + it('should run ESLint plugin and create report.json', async () => { + const { code, stderr } = await executeProcess({ + command: 'npx', + args: [ + '@code-pushup/cli', + 'collect', + '--no-progress', + '--onlyPlugins=eslint', + ], + cwd: baseDir, + }); + + expect(code).toBe(0); + expect(stderr).toBe(''); + + const report = await readJsonFile(join(baseDir, 'code-pushup/report.json')); + + expect(() => reportSchema.parse(report)).not.toThrow(); + expect(omitVariableReportData(report as Report)).toMatchSnapshot(); + }); +}); diff --git a/e2e/plugin-eslint-e2e/tsconfig.json b/e2e/plugin-eslint-e2e/tsconfig.json new file mode 100644 index 000000000..f5a2f890a --- /dev/null +++ b/e2e/plugin-eslint-e2e/tsconfig.json @@ -0,0 +1,20 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "ESNext", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "types": ["vitest"] + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.test.json" + } + ] +} diff --git a/e2e/plugin-eslint-e2e/tsconfig.test.json b/e2e/plugin-eslint-e2e/tsconfig.test.json new file mode 100644 index 000000000..10c7f79de --- /dev/null +++ b/e2e/plugin-eslint-e2e/tsconfig.test.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"], + "target": "ES2020" + }, + "include": [ + "vite.config.e2e.ts", + "tests/**/*.e2e.test.ts", + "tests/**/*.d.ts", + "mocks/**/*.ts" + ] +} diff --git a/e2e/plugin-eslint-e2e/vite.config.e2e.ts b/e2e/plugin-eslint-e2e/vite.config.e2e.ts new file mode 100644 index 000000000..3956da52e --- /dev/null +++ b/e2e/plugin-eslint-e2e/vite.config.e2e.ts @@ -0,0 +1,21 @@ +/// +import { defineConfig } from 'vite'; +import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases'; + +export default defineConfig({ + cacheDir: '../../node_modules/.vite/plugin-lighthouse-e2e', + test: { + reporters: ['basic'], + testTimeout: 120_000, + globals: true, + alias: tsconfigPathAliases(), + pool: 'threads', + poolOptions: { threads: { singleThread: true } }, + cache: { + dir: '../../node_modules/.vitest', + }, + environment: 'node', + include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'], + }, +}); From 71ff81a71c90a6b78c29185ac37490869899cef8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 03:34:57 +0100 Subject: [PATCH 04/42] test: add eslint e2e env project --- .../eslint-e2e-env/.eslintrc.json | 15 +++++++++++++++ .../eslint-e2e-env/code-pushup.config.ts | 10 ++++++++++ .../eslint-e2e-env/project.json | 18 ++++++++++++++++++ .../eslint-e2e-env/src/index.js | 1 + 4 files changed, 44 insertions(+) create mode 100644 static-environments/eslint-e2e-env/.eslintrc.json create mode 100644 static-environments/eslint-e2e-env/code-pushup.config.ts create mode 100644 static-environments/eslint-e2e-env/project.json create mode 100644 static-environments/eslint-e2e-env/src/index.js diff --git a/static-environments/eslint-e2e-env/.eslintrc.json b/static-environments/eslint-e2e-env/.eslintrc.json new file mode 100644 index 000000000..451833b75 --- /dev/null +++ b/static-environments/eslint-e2e-env/.eslintrc.json @@ -0,0 +1,15 @@ +{ + "root": true, + "ignorePatterns": ["code-pushup.config.ts"], + "overrides": [ + { + "files": ["*.js"], + "env": { + "node": true + }, + "parserOptions": { + "sourceType": "script" + } + } + ] +} diff --git a/static-environments/eslint-e2e-env/code-pushup.config.ts b/static-environments/eslint-e2e-env/code-pushup.config.ts new file mode 100644 index 000000000..a2c2ef291 --- /dev/null +++ b/static-environments/eslint-e2e-env/code-pushup.config.ts @@ -0,0 +1,10 @@ +import eslintPlugin from '../../dist/packages/plugin-eslint'; + +export default { + plugins: [ + await eslintPlugin({ + eslintrc: '.eslintrc.json', + patterns: ['*.js'], + }), + ], +}; diff --git a/static-environments/eslint-e2e-env/project.json b/static-environments/eslint-e2e-env/project.json new file mode 100644 index 000000000..d8cc640d4 --- /dev/null +++ b/static-environments/eslint-e2e-env/project.json @@ -0,0 +1,18 @@ +{ + "name": "eslint-e2e-env", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "static-environments/eslint-e2e-env/src", + "projectType": "library", + "targets": { + "lint": { + "command": "npx eslint --config static-environments/eslint-e2e-env/.eslintrc.json static-environments/eslint-e2e-env/src" + }, + "run-collect": { + "command": "npx ../../dist/packages/cli collect", + "options": { + "cwd": "static-environments/eslint-e2e-env" + } + } + }, + "tags": ["scope:internal", "type:feature"] +} diff --git a/static-environments/eslint-e2e-env/src/index.js b/static-environments/eslint-e2e-env/src/index.js new file mode 100644 index 000000000..44dba22ef --- /dev/null +++ b/static-environments/eslint-e2e-env/src/index.js @@ -0,0 +1 @@ +export const test = 42; From 7718c06652bdfebeeb8738dbae1641ee7eddc95b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 14:17:02 +0100 Subject: [PATCH 05/42] wip --- e2e/plugin-eslint-e2e/project.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/plugin-eslint-e2e/project.json b/e2e/plugin-eslint-e2e/project.json index 8edc665f8..a1a657ed4 100644 --- a/e2e/plugin-eslint-e2e/project.json +++ b/e2e/plugin-eslint-e2e/project.json @@ -13,14 +13,14 @@ }, "nxv-env-setup": { "options": { - "environmentRoot": "examples/eslint-example-app" + "environmentRoot": "static-environments/eslint-e2e-env" } }, "e2e": { "executor": "@nx/vite:test", "options": { "configFile": "e2e/plugin-eslint-e2e/vite.config.e2e.ts", - "environmentRoot": "examples/eslint-example-app" + "environmentRoot": "static-environments/eslint-e2e-env" } } }, From a0ef58eb28054abdd8239d0e94f151d160e26cba Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 14:38:54 +0100 Subject: [PATCH 06/42] wip --- static-environments/eslint-e2e-env/code-pushup.config.ts | 2 +- static-environments/eslint-e2e-env/project.json | 2 +- static-environments/eslint-e2e-env/src/index.js | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/static-environments/eslint-e2e-env/code-pushup.config.ts b/static-environments/eslint-e2e-env/code-pushup.config.ts index a2c2ef291..8895efa4a 100644 --- a/static-environments/eslint-e2e-env/code-pushup.config.ts +++ b/static-environments/eslint-e2e-env/code-pushup.config.ts @@ -1,4 +1,4 @@ -import eslintPlugin from '../../dist/packages/plugin-eslint'; +import eslintPlugin from '@code-pushup/eslint-plugin'; export default { plugins: [ diff --git a/static-environments/eslint-e2e-env/project.json b/static-environments/eslint-e2e-env/project.json index d8cc640d4..7f8687c4a 100644 --- a/static-environments/eslint-e2e-env/project.json +++ b/static-environments/eslint-e2e-env/project.json @@ -8,7 +8,7 @@ "command": "npx eslint --config static-environments/eslint-e2e-env/.eslintrc.json static-environments/eslint-e2e-env/src" }, "run-collect": { - "command": "npx ../../dist/packages/cli collect", + "command": "npx @code-pushup/cli collect", "options": { "cwd": "static-environments/eslint-e2e-env" } diff --git a/static-environments/eslint-e2e-env/src/index.js b/static-environments/eslint-e2e-env/src/index.js index 44dba22ef..717d5891b 100644 --- a/static-environments/eslint-e2e-env/src/index.js +++ b/static-environments/eslint-e2e-env/src/index.js @@ -1 +1,3 @@ -export const test = 42; +function random() { + return '42'; +} From ba625bbfd5da84a93ed24abc55444fe75e538e39 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 14:53:04 +0100 Subject: [PATCH 07/42] wip --- e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index 52d6ebbaf..47f4025d2 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -6,7 +6,7 @@ import { omitVariableReportData } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with eslint-plugin NPM package', () => { - const baseDir = 'eslint-e2e-env/__test__'; + const baseDir = 'static-environments/eslint-e2e-env'; afterEach(async () => { await teardownTestFolder(baseDir); From 30602756d4f8a66088ef600b0d5b5572c75f42e4 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 14:56:57 +0100 Subject: [PATCH 08/42] wip --- static-environments/eslint-e2e-env/.eslintrc.json | 3 +++ static-environments/eslint-e2e-env/project.json | 5 ++++- static-environments/eslint-e2e-env/src/index.js | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/static-environments/eslint-e2e-env/.eslintrc.json b/static-environments/eslint-e2e-env/.eslintrc.json index 451833b75..d9684a6dd 100644 --- a/static-environments/eslint-e2e-env/.eslintrc.json +++ b/static-environments/eslint-e2e-env/.eslintrc.json @@ -9,6 +9,9 @@ }, "parserOptions": { "sourceType": "script" + }, + "rules": { + "no-unused-vars": "error" } } ] diff --git a/static-environments/eslint-e2e-env/project.json b/static-environments/eslint-e2e-env/project.json index 7f8687c4a..76c90ba64 100644 --- a/static-environments/eslint-e2e-env/project.json +++ b/static-environments/eslint-e2e-env/project.json @@ -5,7 +5,10 @@ "projectType": "library", "targets": { "lint": { - "command": "npx eslint --config static-environments/eslint-e2e-env/.eslintrc.json static-environments/eslint-e2e-env/src" + "command": "npx eslint src", + "options": { + "cwd": "static-environments/eslint-e2e-env" + } }, "run-collect": { "command": "npx @code-pushup/cli collect", diff --git a/static-environments/eslint-e2e-env/src/index.js b/static-environments/eslint-e2e-env/src/index.js index 717d5891b..7b2d56d8e 100644 --- a/static-environments/eslint-e2e-env/src/index.js +++ b/static-environments/eslint-e2e-env/src/index.js @@ -1,3 +1,3 @@ -function random() { +function random(unused) { return '42'; } From d4b84ad23c792956951de76ddb6391d9ad695bcf Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 16:08:42 +0100 Subject: [PATCH 09/42] wip --- .github/workflows/ci.yml | 2 +- .gitignore | 2 - e2e/cli-e2e/project.json | 13 ++-- e2e/cli-e2e/tests/collect.e2e.test.ts | 35 +++------- e2e/cli-e2e/tests/compare.e2e.test.ts | 9 +-- e2e/cli-e2e/tests/help.e2e.test.ts | 15 ++-- e2e/cli-e2e/tests/print-config.e2e.test.ts | 22 +++--- e2e/cli-e2e/vite.config.e2e.ts | 1 + .../tests/collect.e2e.test.ts | 5 +- examples/react-todos-app/.eslintrc.js | 69 +++++++++++++++++++ examples/react-todos-app/.eslintrc.json | 64 ----------------- ...pushup.config.ts => code-pushup.config.js} | 6 +- 12 files changed, 113 insertions(+), 130 deletions(-) create mode 100644 examples/react-todos-app/.eslintrc.js delete mode 100644 examples/react-todos-app/.eslintrc.json rename examples/react-todos-app/{code-pushup.config.ts => code-pushup.config.js} (93%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55fb01fe6..845def216 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -122,7 +122,7 @@ jobs: - name: E2E test affected projects run: npx nx affected -t nxv-e2e --exclude cli-e2e --parallel=1 - name: E2E test cli-e2e project (due to bugs in the setup it has to run last :( ) - run: npx nx run cli-e2e:nxv-e2e + run: npx nx run cli-e2e:e2e-old build: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 01481eeee..21c8b0424 100644 --- a/.gitignore +++ b/.gitignore @@ -33,8 +33,6 @@ node_modules /connect.lock /coverage /examples/react-todos-app/coverage -/examples/react-todos-app/package.json -/examples/react-todos-app/package-lock.json /libpeerconnection.log npm-debug.log yarn-error.log diff --git a/e2e/cli-e2e/project.json b/e2e/cli-e2e/project.json index c14b2d8cb..5bef1175d 100644 --- a/e2e/cli-e2e/project.json +++ b/e2e/cli-e2e/project.json @@ -11,20 +11,17 @@ "lintFilePatterns": ["e2e/cli-e2e/**/*.ts"] } }, - "nxv-env-setup": { - "options": { - "environmentRoot": "examples/react-todos-app" - } - }, - "e2e": { + "e2e-old": { "executor": "@nx/vite:test", "options": { - "configFile": "e2e/cli-e2e/vite.config.e2e.ts", - "environmentRoot": "examples/react-todos-app" + "configFile": "e2e/cli-e2e/vite.config.e2e.ts" } } }, "implicitDependencies": [ + "models", + "utils", + "core", "cli", "plugin-eslint", "plugin-coverage", diff --git a/e2e/cli-e2e/tests/collect.e2e.test.ts b/e2e/cli-e2e/tests/collect.e2e.test.ts index ba4676d49..5e301ab29 100644 --- a/e2e/cli-e2e/tests/collect.e2e.test.ts +++ b/e2e/cli-e2e/tests/collect.e2e.test.ts @@ -51,13 +51,8 @@ describe('CLI collect', () => { it('should run ESLint plugin and create report.json', async () => { const { code, stderr } = await executeProcess({ - command: 'npx', - args: [ - '@code-pushup/cli', - 'collect', - '--no-progress', - '--onlyPlugins=eslint', - ], + command: 'code-pushup', + args: ['collect', '--no-progress', '--onlyPlugins=eslint'], cwd: 'examples/react-todos-app', }); @@ -88,16 +83,14 @@ describe('CLI collect', () => { ); const { code, stderr } = await executeProcess({ - command: 'npx', + command: 'code-pushup', args: [ - '@code-pushup/cli', 'collect', '--no-progress', `--config=${configPath}`, '--persist.outputDir=tmp/e2e', '--onlyPlugins=coverage', ], - cwd: 'examples/react-todos-app', }); expect(code).toBe(0); @@ -111,13 +104,8 @@ describe('CLI collect', () => { it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => { const { code, stderr } = await executeProcess({ - command: 'npx', - args: [ - '@code-pushup/cli', - 'collect', - '--no-progress', - '--onlyPlugins=coverage', - ], + command: 'code-pushup', + args: ['collect', '--no-progress', '--onlyPlugins=coverage'], cwd: 'examples/react-todos-app', }); @@ -132,13 +120,8 @@ describe('CLI collect', () => { it('should create report.md', async () => { const { code, stderr } = await executeProcess({ - command: 'npx', - args: [ - '@code-pushup/cli', - 'collect', - '--persist.format=md', - '--no-progress', - ], + command: 'code-pushup', + args: ['collect', '--persist.format=md', '--no-progress'], cwd: 'examples/react-todos-app', }); @@ -154,8 +137,8 @@ describe('CLI collect', () => { it('should print report summary to stdout', async () => { const { code, stdout, stderr } = await executeProcess({ - command: 'npx', - args: ['@code-pushup/cli', 'collect', '--no-progress'], + command: 'code-pushup', + args: ['collect', '--no-progress'], cwd: 'examples/react-todos-app', }); diff --git a/e2e/cli-e2e/tests/compare.e2e.test.ts b/e2e/cli-e2e/tests/compare.e2e.test.ts index c80eb9e24..9f5744c9f 100644 --- a/e2e/cli-e2e/tests/compare.e2e.test.ts +++ b/e2e/cli-e2e/tests/compare.e2e.test.ts @@ -14,9 +14,8 @@ describe('CLI compare', () => { } await cleanTestFolder('tmp/e2e/react-todos-app'); await executeProcess({ - command: 'npx', + command: 'code-pushup', args: [ - '@code-pushup/cli', 'collect', '--persist.filename=source-report', '--onlyPlugins=eslint', @@ -29,9 +28,8 @@ describe('CLI compare', () => { cwd: 'examples/react-todos-app', }); await executeProcess({ - command: 'npx', + command: 'code-pushup', args: [ - '@code-pushup/cli', 'collect', '--persist.filename=target-report', '--onlyPlugins=eslint', @@ -47,9 +45,8 @@ describe('CLI compare', () => { it('should compare report.json files and create report-diff.json and report-diff.md', async () => { await executeProcess({ - command: 'npx', + command: 'code-pushup', args: [ - '@code-pushup/cli', 'compare', '--before=../../tmp/e2e/react-todos-app/source-report.json', '--after=../../tmp/e2e/react-todos-app/target-report.json', diff --git a/e2e/cli-e2e/tests/help.e2e.test.ts b/e2e/cli-e2e/tests/help.e2e.test.ts index 40032dfe9..cf5316be1 100644 --- a/e2e/cli-e2e/tests/help.e2e.test.ts +++ b/e2e/cli-e2e/tests/help.e2e.test.ts @@ -4,9 +4,8 @@ import { executeProcess } from '@code-pushup/utils'; describe('CLI help', () => { it('should print help with help command', async () => { const { code, stdout, stderr } = await executeProcess({ - command: 'npx', - args: ['@code-pushup/cli', 'help'], - cwd: 'examples/react-todos-app', + command: 'code-pushup', + args: ['help'], }); expect(code).toBe(0); expect(stderr).toBe(''); @@ -15,14 +14,12 @@ describe('CLI help', () => { it('should produce the same output to stdout for both help argument and help command', async () => { const helpArgResult = await executeProcess({ - command: 'npx', - args: ['@code-pushup/cli', 'help'], - cwd: 'examples/react-todos-app', + command: 'code-pushup', + args: ['help'], }); const helpCommandResult = await executeProcess({ - command: 'npx', - args: ['@code-pushup/cli', '--help'], - cwd: 'examples/react-todos-app', + command: 'code-pushup', + args: ['--help'], }); expect(helpArgResult.code).toBe(0); expect(helpCommandResult.code).toBe(0); diff --git a/e2e/cli-e2e/tests/print-config.e2e.test.ts b/e2e/cli-e2e/tests/print-config.e2e.test.ts index 75ef57e76..46190659d 100644 --- a/e2e/cli-e2e/tests/print-config.e2e.test.ts +++ b/e2e/cli-e2e/tests/print-config.e2e.test.ts @@ -6,29 +6,29 @@ const extensions = ['js', 'mjs', 'ts'] as const; export const configFilePath = (ext: (typeof extensions)[number]) => join(process.cwd(), `e2e/cli-e2e/mocks/fixtures/code-pushup.config.${ext}`); -describe('CLI print-config', () => { +describe('print-config', () => { it.each(extensions)( 'should load .%s config file with correct arguments', async ext => { const { code, stdout } = await executeProcess({ - command: 'npx', + command: 'code-pushup', args: [ - '@code-pushup/cli', 'print-config', '--no-progress', + `--config=${configFilePath(ext)}`, '--tsconfig=tsconfig.base.json', '--persist.outputDir=output-dir', '--persist.format=md', `--persist.filename=${ext}-report`, '--onlyPlugins=coverage', ], - cwd: 'examples/react-todos-app', }); expect(code).toBe(0); expect(JSON.parse(stdout)).toEqual( expect.objectContaining({ + config: expect.stringContaining(`code-pushup.config.${ext}`), tsconfig: 'tsconfig.base.json', // filled by command options persist: { @@ -36,15 +36,19 @@ describe('CLI print-config', () => { filename: `${ext}-report`, format: ['md'], }, - plugins: expect.arrayContaining([ + upload: { + organization: 'code-pushup', + project: `cli-${ext}`, + apiKey: 'e2e-api-key', + server: 'https://e2e.com/api', + }, + plugins: [ expect.objectContaining({ slug: 'coverage', title: 'Code coverage', }), - ]), - categories: expect.arrayContaining([ - expect.objectContaining({ slug: 'code-coverage' }), - ]), + ], + categories: [expect.objectContaining({ slug: 'code-coverage' })], onlyPlugins: ['coverage'], }), ); diff --git a/e2e/cli-e2e/vite.config.e2e.ts b/e2e/cli-e2e/vite.config.e2e.ts index 2514c0209..f1b3c3b93 100644 --- a/e2e/cli-e2e/vite.config.e2e.ts +++ b/e2e/cli-e2e/vite.config.e2e.ts @@ -16,6 +16,7 @@ export default defineConfig({ }, environment: 'node', include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + globalSetup: ['../../global-setup.e2e.ts'], setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'], }, }); diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index 47f4025d2..05e45277b 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -6,10 +6,10 @@ import { omitVariableReportData } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with eslint-plugin NPM package', () => { - const baseDir = 'static-environments/eslint-e2e-env'; + const baseDir = 'static-environments/eslint-e2e-env/__tests__'; afterEach(async () => { - await teardownTestFolder(baseDir); + // await teardownTestFolder(baseDir); }); it('should run ESLint plugin and create report.json', async () => { @@ -18,6 +18,7 @@ describe('collect report with eslint-plugin NPM package', () => { args: [ '@code-pushup/cli', 'collect', + `--persist.outputDir=${join(baseDir, '.code-pushup')}`, '--no-progress', '--onlyPlugins=eslint', ], diff --git a/examples/react-todos-app/.eslintrc.js b/examples/react-todos-app/.eslintrc.js new file mode 100644 index 000000000..e05f2bb62 --- /dev/null +++ b/examples/react-todos-app/.eslintrc.js @@ -0,0 +1,69 @@ +/** @type {import('eslint').ESLint.ConfigData} */ +module.exports = { + root: true, + env: { + browser: true, + es2021: true, + }, + plugins: ['react', 'react-hooks'], + overrides: [ + { + env: { + node: true, + }, + files: ['.eslintrc.{js,cjs}'], + parserOptions: { + sourceType: 'script', + }, + }, + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + ecmaFeatures: { + jsx: true, + }, + }, + settings: { + react: { + version: 'detect', + }, + }, + rules: { + // https://eslint.org/docs/latest/rules/#possible-problems + 'no-cond-assign': 'warn', + 'no-const-assign': 'warn', + 'no-debugger': 'warn', + 'no-invalid-regexp': 'warn', + 'no-undef': 'warn', + 'no-unreachable-loop': 'warn', + 'no-unsafe-negation': 'warn', + 'no-unsafe-optional-chaining': 'warn', + 'no-unused-vars': 'warn', + 'use-isnan': 'warn', + 'valid-typeof': 'warn', + // https://eslint.org/docs/latest/rules/#suggestions + 'arrow-body-style': 'warn', + camelcase: 'warn', + curly: 'warn', + eqeqeq: 'warn', + 'max-lines-per-function': 'warn', + 'max-lines': 'warn', + 'no-shadow': 'warn', + 'no-var': 'warn', + 'object-shorthand': 'warn', + 'prefer-arrow-callback': 'warn', + 'prefer-const': 'warn', + 'prefer-object-spread': 'warn', + yoda: 'warn', + // https://github.com/jsx-eslint/eslint-plugin-react#list-of-supported-rules + 'react/jsx-key': 'warn', + 'react/prop-types': 'warn', + 'react/react-in-jsx-scope': 'warn', + 'react/jsx-uses-vars': 'warn', + 'react/jsx-uses-react': 'error', + // https://www.npmjs.com/package/eslint-plugin-react-hooks + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'warn', + }, +}; diff --git a/examples/react-todos-app/.eslintrc.json b/examples/react-todos-app/.eslintrc.json deleted file mode 100644 index 9c50e51ca..000000000 --- a/examples/react-todos-app/.eslintrc.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "root": true, - "env": { - "browser": true, - "es2021": true - }, - "plugins": ["react", "react-hooks"], - "overrides": [ - { - "env": { - "node": true - }, - "files": [".eslintrc.{js,cjs}"], - "parserOptions": { - "sourceType": "script" - } - } - ], - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module", - "ecmaFeatures": { - "jsx": true - } - }, - "settings": { - "react": { - "version": "detect" - } - }, - "rules": { - "no-cond-assign": "warn", - "no-const-assign": "warn", - "no-debugger": "warn", - "no-invalid-regexp": "warn", - "no-undef": "warn", - "no-unreachable-loop": "warn", - "no-unsafe-negation": "warn", - "no-unsafe-optional-chaining": "warn", - "no-unused-vars": "warn", - "use-isnan": "warn", - "valid-typeof": "warn", - "arrow-body-style": "warn", - "camelcase": "warn", - "curly": "warn", - "eqeqeq": "warn", - "max-lines-per-function": "warn", - "max-lines": "warn", - "no-shadow": "warn", - "no-var": "warn", - "object-shorthand": "warn", - "prefer-arrow-callback": "warn", - "prefer-const": "warn", - "prefer-object-spread": "warn", - "yoda": "warn", - "react/jsx-key": "warn", - "react/prop-types": "warn", - "react/react-in-jsx-scope": "warn", - "react/jsx-uses-vars": "warn", - "react/jsx-uses-react": "error", - "react-hooks/rules-of-hooks": "error", - "react-hooks/exhaustive-deps": "warn" - } -} diff --git a/examples/react-todos-app/code-pushup.config.ts b/examples/react-todos-app/code-pushup.config.js similarity index 93% rename from examples/react-todos-app/code-pushup.config.ts rename to examples/react-todos-app/code-pushup.config.js index 60780c794..dcef94a7f 100644 --- a/examples/react-todos-app/code-pushup.config.ts +++ b/examples/react-todos-app/code-pushup.config.js @@ -1,5 +1,5 @@ -import coveragePlugin from '@code-pushup/coverage-plugin'; -import eslintPlugin from '@code-pushup/eslint-plugin'; +import coveragePlugin from '../../dist/packages/plugin-coverage'; +import eslintPlugin from '../../dist/packages/plugin-eslint'; const eslintAuditRef = (slug, weight) => ({ type: 'audit', @@ -21,7 +21,7 @@ export default { }, }), await eslintPlugin({ - eslintrc: '.eslintrc.json', + eslintrc: '.eslintrc.js', patterns: ['src/**/*.js', 'src/**/*.jsx'], }), ], From edaa857356da1aa8c417a01c33335a18b4971c56 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 16:37:06 +0100 Subject: [PATCH 10/42] use minimal eslint rules --- .../__snapshots__/collect.e2e.test.ts.snap | 139 ++++++++++++++++++ .../tests/collect.e2e.test.ts | 17 ++- .../eslint-e2e-env/.eslintrc.json | 4 +- .../eslint-e2e-env/code-pushup.config.ts | 19 ++- .../eslint-e2e-env/src/index.js | 6 +- 5 files changed, 176 insertions(+), 9 deletions(-) create mode 100644 e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap diff --git a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap new file mode 100644 index 000000000..39f169153 --- /dev/null +++ b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -0,0 +1,139 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`collect report with eslint-plugin NPM package > should run ESLint plugin and create report.json 1`] = ` +{ + "categories": [ + { + "description": "Lint rules that find **potential bugs** in your code.", + "refs": [ + { + "plugin": "eslint", + "slug": "problems", + "type": "group", + "weight": 1, + }, + ], + "slug": "bug-prevention", + "title": "Bug prevention", + }, + { + "description": "Lint rules that promote **good practices** and consistency in your code.", + "refs": [ + { + "plugin": "eslint", + "slug": "suggestions", + "type": "group", + "weight": 1, + }, + ], + "slug": "code-style", + "title": "Code style", + }, + ], + "packageName": "@code-pushup/core", + "plugins": [ + { + "audits": [ + { + "description": "ESLint rule **no-unused-vars**.", + "details": { + "issues": [ + { + "message": "'unusedFn' is defined but never used.", + "severity": "error", + "source": { + "file": "static-environments/eslint-e2e-env/src/index.js", + "position": { + "endColumn": 18, + "endLine": 1, + "startColumn": 10, + "startLine": 1, + }, + }, + }, + ], + }, + "displayValue": "1 error", + "docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars", + "score": 0, + "slug": "no-unused-vars", + "title": "Disallow unused variables", + "value": 1, + }, + { + "description": "ESLint rule **no-console**.", + "details": { + "issues": [ + { + "message": "Unexpected console statement.", + "severity": "warning", + "source": { + "file": "static-environments/eslint-e2e-env/src/index.js", + "position": { + "endColumn": 14, + "endLine": 6, + "startColumn": 3, + "startLine": 6, + }, + }, + }, + ], + }, + "displayValue": "1 warning", + "docsUrl": "https://eslint.org/docs/latest/rules/no-console", + "score": 0, + "slug": "no-console", + "title": "Disallow the use of \`console\`", + "value": 1, + }, + { + "description": "ESLint rule **no-undef**.", + "details": { + "issues": [], + }, + "displayValue": "passed", + "docsUrl": "https://eslint.org/docs/latest/rules/no-undef", + "score": 1, + "slug": "no-undef", + "title": "Disallow the use of undeclared variables unless mentioned in \`/*global */\` comments", + "value": 0, + }, + ], + "description": "Official Code PushUp ESLint plugin", + "docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin", + "groups": [ + { + "description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.", + "refs": [ + { + "slug": "no-unused-vars", + "weight": 1, + }, + { + "slug": "no-undef", + "weight": 1, + }, + ], + "slug": "problems", + "title": "Problems", + }, + { + "description": "Something that could be done in a better way but no errors will occur if the code isn't changed.", + "refs": [ + { + "slug": "no-console", + "weight": 1, + }, + ], + "slug": "suggestions", + "title": "Suggestions", + }, + ], + "icon": "eslint", + "packageName": "@code-pushup/eslint-plugin", + "slug": "eslint", + "title": "ESLint", + }, + ], +} +`; diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index 05e45277b..17d7d05be 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -1,4 +1,4 @@ -import { join } from 'node:path'; +import { join, relative } from 'node:path'; import { afterEach } from 'vitest'; import { type Report, reportSchema } from '@code-pushup/models'; import { teardownTestFolder } from '@code-pushup/test-setup'; @@ -6,29 +6,34 @@ import { omitVariableReportData } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with eslint-plugin NPM package', () => { - const baseDir = 'static-environments/eslint-e2e-env/__tests__'; + const envRoot = 'static-environments/eslint-e2e-env'; + const baseDir = join(envRoot, '__tests__'); afterEach(async () => { - // await teardownTestFolder(baseDir); + await teardownTestFolder(baseDir); }); it('should run ESLint plugin and create report.json', async () => { + const outputDir = relative( + envRoot, + join(baseDir, 'default-report', '.code-pushup'), + ); const { code, stderr } = await executeProcess({ command: 'npx', args: [ '@code-pushup/cli', 'collect', - `--persist.outputDir=${join(baseDir, '.code-pushup')}`, + `--persist.outputDir=${outputDir}`, '--no-progress', '--onlyPlugins=eslint', ], - cwd: baseDir, + cwd: envRoot, }); expect(code).toBe(0); expect(stderr).toBe(''); - const report = await readJsonFile(join(baseDir, 'code-pushup/report.json')); + const report = await readJsonFile(join(envRoot, outputDir, 'report.json')); expect(() => reportSchema.parse(report)).not.toThrow(); expect(omitVariableReportData(report as Report)).toMatchSnapshot(); diff --git a/static-environments/eslint-e2e-env/.eslintrc.json b/static-environments/eslint-e2e-env/.eslintrc.json index d9684a6dd..113136c93 100644 --- a/static-environments/eslint-e2e-env/.eslintrc.json +++ b/static-environments/eslint-e2e-env/.eslintrc.json @@ -11,7 +11,9 @@ "sourceType": "script" }, "rules": { - "no-unused-vars": "error" + "no-unused-vars": "error", + "no-console": "warn", + "no-undef": "error" } } ] diff --git a/static-environments/eslint-e2e-env/code-pushup.config.ts b/static-environments/eslint-e2e-env/code-pushup.config.ts index 8895efa4a..01feaf2ff 100644 --- a/static-environments/eslint-e2e-env/code-pushup.config.ts +++ b/static-environments/eslint-e2e-env/code-pushup.config.ts @@ -4,7 +4,24 @@ export default { plugins: [ await eslintPlugin({ eslintrc: '.eslintrc.json', - patterns: ['*.js'], + patterns: ['src/*.js'], }), ], + categories: [ + { + slug: 'bug-prevention', + title: 'Bug prevention', + description: 'Lint rules that find **potential bugs** in your code.', + refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }], + }, + { + slug: 'code-style', + title: 'Code style', + description: + 'Lint rules that promote **good practices** and consistency in your code.', + refs: [ + { type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 }, + ], + }, + ], }; diff --git a/static-environments/eslint-e2e-env/src/index.js b/static-environments/eslint-e2e-env/src/index.js index 7b2d56d8e..4710a3767 100644 --- a/static-environments/eslint-e2e-env/src/index.js +++ b/static-environments/eslint-e2e-env/src/index.js @@ -1,3 +1,7 @@ -function random(unused) { +function unusedFn() { return '42'; } + +module.exports = function consoleLog() { + console.log('No console.log()!'); +}; From efd1b07170e6508b77acebf5a8afff0d7632e0b7 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 16:47:19 +0100 Subject: [PATCH 11/42] wip --- nx.json | 15 ++++++++++++++- static-environments/eslint-e2e-env/project.json | 15 +-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/nx.json b/nx.json index b660413ce..55fc16bb7 100644 --- a/nx.json +++ b/nx.json @@ -29,7 +29,20 @@ "dependsOn": ["^build"] }, "nxv-env-setup": { - "executor": "@push-based/nx-verdaccio:env-setup" + "cache": true, + "inputs": [ + "{projectRoot}/project.json", + { + "runtime": "node --version" + }, + { + "runtime": "npm --version" + }, + { + "externalDependencies": ["verdaccio"] + }, + "^production" + ] }, "@nx/vite:test": { "cache": true, diff --git a/static-environments/eslint-e2e-env/project.json b/static-environments/eslint-e2e-env/project.json index 76c90ba64..857adc78f 100644 --- a/static-environments/eslint-e2e-env/project.json +++ b/static-environments/eslint-e2e-env/project.json @@ -3,19 +3,6 @@ "$schema": "../../node_modules/nx/schemas/project-schema.json", "sourceRoot": "static-environments/eslint-e2e-env/src", "projectType": "library", - "targets": { - "lint": { - "command": "npx eslint src", - "options": { - "cwd": "static-environments/eslint-e2e-env" - } - }, - "run-collect": { - "command": "npx @code-pushup/cli collect", - "options": { - "cwd": "static-environments/eslint-e2e-env" - } - } - }, + "targets": {}, "tags": ["scope:internal", "type:feature"] } From f4253d0263e4f63c0be3085640ef2761f9210ebf Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 16:56:55 +0100 Subject: [PATCH 12/42] wip --- nx.json | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/nx.json b/nx.json index 55fc16bb7..c0cddefbf 100644 --- a/nx.json +++ b/nx.json @@ -84,23 +84,7 @@ "appsDir": "examples", "libsDir": "packages" }, - "generators": { - "@nx/react": { - "application": { - "style": "css", - "linter": "eslint", - "bundler": "vite", - "babel": true - }, - "component": { - "style": "css" - }, - "library": { - "style": "css", - "linter": "eslint" - } - } - }, + "generators": {}, "release": { "projects": ["packages/*"], "projectsRelationship": "fixed", From f9911fbdf092d23c0be589ac43f0400c087f0ebf Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 17:23:27 +0100 Subject: [PATCH 13/42] wip --- nx.json | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/nx.json b/nx.json index c0cddefbf..c7603298b 100644 --- a/nx.json +++ b/nx.json @@ -29,20 +29,7 @@ "dependsOn": ["^build"] }, "nxv-env-setup": { - "cache": true, - "inputs": [ - "{projectRoot}/project.json", - { - "runtime": "node --version" - }, - { - "runtime": "npm --version" - }, - { - "externalDependencies": ["verdaccio"] - }, - "^production" - ] + "executor": "@push-based/nx-verdaccio:env-setup" }, "@nx/vite:test": { "cache": true, From 5f0dfbe2793906f066567c9e79fa817ac34aa972 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 17:37:42 +0100 Subject: [PATCH 14/42] reduce configuration --- e2e/plugin-eslint-e2e/project.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/e2e/plugin-eslint-e2e/project.json b/e2e/plugin-eslint-e2e/project.json index a1a657ed4..6487d3102 100644 --- a/e2e/plugin-eslint-e2e/project.json +++ b/e2e/plugin-eslint-e2e/project.json @@ -19,8 +19,7 @@ "e2e": { "executor": "@nx/vite:test", "options": { - "configFile": "e2e/plugin-eslint-e2e/vite.config.e2e.ts", - "environmentRoot": "static-environments/eslint-e2e-env" + "configFile": "e2e/plugin-eslint-e2e/vite.config.e2e.ts" } } }, From 14ad3c09701b8d56c613954dec53f977ae78207f Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 17:39:46 +0100 Subject: [PATCH 15/42] wip --- examples/react-todos-app/package.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/react-todos-app/package.json diff --git a/examples/react-todos-app/package.json b/examples/react-todos-app/package.json new file mode 100644 index 000000000..d9e892a84 --- /dev/null +++ b/examples/react-todos-app/package.json @@ -0,0 +1,16 @@ +{ + "name": "todo-app", + "private": true, + "scripts": { + "start": "esbuild src/index.jsx --bundle --outdir=www/js --servedir=www", + "build": "esbuild src/index.jsx --bundle --outdir=www/js --minify" + }, + "dependencies": { + "react": "^16.12.0", + "semver": "5.7.1" + }, + "devDependencies": { + "vite": "~4.5.0", + "vitest": "0.34.0" + } +} From 83bdb9864211c13c650b6313205e9f305c015850 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 17:48:59 +0100 Subject: [PATCH 16/42] update nx-verdaccio to alpha.26 --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 80639ae4b..960950fda 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "@nx/react": "17.3.2", "@nx/vite": "17.3.2", "@nx/workspace": "17.3.2", - "@push-based/nx-verdaccio": "0.0.0-alpha.25", + "@push-based/nx-verdaccio": "0.0.0-alpha.26", "@swc-node/register": "^1.10.9", "@swc/cli": "~0.1.62", "@swc/core": "^1.3.99", @@ -5457,9 +5457,9 @@ } }, "node_modules/@push-based/nx-verdaccio": { - "version": "0.0.0-alpha.25", - "resolved": "https://registry.npmjs.org/@push-based/nx-verdaccio/-/nx-verdaccio-0.0.0-alpha.25.tgz", - "integrity": "sha512-5keAr9Gpw0TjUEwtMZVu/qweBYPPHHxHRNaRJgw94uOGSwcQwFcYn92w3+Z4/VdXhM0/RINALGc+/DgG1PV5fg==", + "version": "0.0.0-alpha.26", + "resolved": "https://registry.npmjs.org/@push-based/nx-verdaccio/-/nx-verdaccio-0.0.0-alpha.26.tgz", + "integrity": "sha512-Go11Dg+w5Ntl5Ig8YNzVVPbpOG85aVszjyBIK0FvVBX+/QllQY1F4fP8K8fYnMJnO9v5Tao3cryGFY5Zo9i+/g==", "dev": true, "dependencies": { "@nx/devkit": "19.8.0", diff --git a/package.json b/package.json index da4f9fb46..354f89a4b 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@nx/react": "17.3.2", "@nx/vite": "17.3.2", "@nx/workspace": "17.3.2", - "@push-based/nx-verdaccio": "0.0.0-alpha.25", + "@push-based/nx-verdaccio": "0.0.0-alpha.26", "@swc-node/register": "^1.10.9", "@swc/cli": "~0.1.62", "@swc/core": "^1.3.99", From 7dad5b5ac47ae7a992ef07cba007daf4271b5c34 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 18:42:25 +0100 Subject: [PATCH 17/42] test: split coverage tests --- e2e/plugin-coverage-e2e/.eslintrc.json | 12 ++ e2e/plugin-coverage-e2e/project.json | 28 ++++ .../__snapshots__/collect.e2e.test.ts.snap | 129 ++++++++++++++++++ .../tests/collect.e2e.test.ts | 72 ++++++++++ e2e/plugin-coverage-e2e/tsconfig.json | 20 +++ e2e/plugin-coverage-e2e/tsconfig.test.json | 14 ++ e2e/plugin-coverage-e2e/vite.config.e2e.ts | 21 +++ nx.json | 21 +-- package-lock.json | 8 +- package.json | 2 +- .../coverage-e2e-env/.gitignore | 3 + .../coverage-e2e-env/code-pushup.config.ts | 16 +++ .../coverage-e2e-env/project.json | 8 ++ .../coverage-e2e-env/src/index.mjs | 16 +++ .../coverage-e2e-env/src/index.test.mjs | 20 +++ .../coverage-e2e-env/vite.config.ts | 25 ++++ 16 files changed, 393 insertions(+), 22 deletions(-) create mode 100644 e2e/plugin-coverage-e2e/.eslintrc.json create mode 100644 e2e/plugin-coverage-e2e/project.json create mode 100644 e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap create mode 100644 e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts create mode 100644 e2e/plugin-coverage-e2e/tsconfig.json create mode 100644 e2e/plugin-coverage-e2e/tsconfig.test.json create mode 100644 e2e/plugin-coverage-e2e/vite.config.e2e.ts create mode 100644 static-environments/coverage-e2e-env/.gitignore create mode 100644 static-environments/coverage-e2e-env/code-pushup.config.ts create mode 100644 static-environments/coverage-e2e-env/project.json create mode 100644 static-environments/coverage-e2e-env/src/index.mjs create mode 100644 static-environments/coverage-e2e-env/src/index.test.mjs create mode 100644 static-environments/coverage-e2e-env/vite.config.ts diff --git a/e2e/plugin-coverage-e2e/.eslintrc.json b/e2e/plugin-coverage-e2e/.eslintrc.json new file mode 100644 index 000000000..7ef7b6dc8 --- /dev/null +++ b/e2e/plugin-coverage-e2e/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*", "code-pushup.config*.ts"], + "overrides": [ + { + "files": ["*.ts", "*.tsx"], + "parserOptions": { + "project": ["e2e/plugin-coverage-e2e/tsconfig.*?.json"] + } + } + ] +} diff --git a/e2e/plugin-coverage-e2e/project.json b/e2e/plugin-coverage-e2e/project.json new file mode 100644 index 000000000..fdf8f2e3c --- /dev/null +++ b/e2e/plugin-coverage-e2e/project.json @@ -0,0 +1,28 @@ +{ + "name": "plugin-coverage-e2e", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "e2e/plugin-coverage-e2e/src", + "projectType": "application", + "targets": { + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["e2e/plugin-coverage-e2e/**/*.ts"] + } + }, + "nxv-env-setup": { + "options": { + "environmentRoot": "static-environments/coverage-e2e-env" + } + }, + "e2e": { + "executor": "@nx/vite:test", + "options": { + "configFile": "e2e/plugin-coverage-e2e/vite.config.e2e.ts" + } + } + }, + "implicitDependencies": ["cli", "plugin-coverage", "coverage-e2e-env"], + "tags": ["scope:plugin", "type:e2e"] +} diff --git a/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap new file mode 100644 index 000000000..4dfa1545d --- /dev/null +++ b/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -0,0 +1,129 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`collect report with coverage-plugin NPM package > should run Code coverage plugin that runs coverage tool and creates report.json 1`] = ` +{ + "categories": [], + "packageName": "@code-pushup/core", + "plugins": [ + { + "audits": [ + { + "description": "Measures how many functions were called in at least one test.", + "details": { + "issues": [ + { + "message": "Function untested is not called in any test case.", + "severity": "error", + "source": { + "file": "static-environments/coverage-e2e-env/src/index.mjs", + "position": { + "startLine": 1, + }, + }, + }, + ], + }, + "displayValue": "66.7 %", + "score": 0.6667, + "slug": "function-coverage", + "title": "Function coverage", + "value": 66.66666666666666, + }, + { + "description": "Measures how many branches were executed after conditional statements in at least one test.", + "details": { + "issues": [ + { + "message": "1st branch is not taken in any test case.", + "severity": "error", + "source": { + "file": "static-environments/coverage-e2e-env/src/index.mjs", + "position": { + "startLine": 11, + }, + }, + }, + { + "message": "1st branch is not taken in any test case.", + "severity": "error", + "source": { + "file": "static-environments/coverage-e2e-env/src/index.mjs", + "position": { + "startLine": 15, + }, + }, + }, + ], + }, + "displayValue": "50 %", + "score": 0.5, + "slug": "branch-coverage", + "title": "Branch coverage", + "value": 50, + }, + { + "description": "Measures how many lines of code were executed in at least one test.", + "details": { + "issues": [ + { + "message": "Lines 2-3 are not covered in any test case.", + "severity": "warning", + "source": { + "file": "static-environments/coverage-e2e-env/src/index.mjs", + "position": { + "endLine": 3, + "startLine": 2, + }, + }, + }, + { + "message": "Lines 12-13 are not covered in any test case.", + "severity": "warning", + "source": { + "file": "static-environments/coverage-e2e-env/src/index.mjs", + "position": { + "endLine": 13, + "startLine": 12, + }, + }, + }, + ], + }, + "displayValue": "75 %", + "score": 0.75, + "slug": "line-coverage", + "title": "Line coverage", + "value": 75, + }, + ], + "description": "Official Code PushUp code coverage plugin.", + "docsUrl": "https://www.npmjs.com/package/@code-pushup/coverage-plugin/", + "groups": [ + { + "description": "Group containing all defined coverage types as audits.", + "refs": [ + { + "slug": "function-coverage", + "weight": 6, + }, + { + "slug": "branch-coverage", + "weight": 3, + }, + { + "slug": "line-coverage", + "weight": 1, + }, + ], + "slug": "coverage", + "title": "Code coverage metrics", + }, + ], + "icon": "folder-coverage-open", + "packageName": "@code-pushup/coverage-plugin", + "slug": "coverage", + "title": "Code coverage", + }, + ], +} +`; diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts new file mode 100644 index 000000000..5ed03a756 --- /dev/null +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -0,0 +1,72 @@ +import {dirname, join} from 'node:path'; +import {afterEach} from 'vitest'; +import {teardownTestFolder} from '@code-pushup/test-setup'; +import {fileURLToPath} from "node:url"; +import {executeProcess, readJsonFile} from "@code-pushup/utils"; +import {type Report, reportSchema} from "@code-pushup/models"; +import {omitVariableReportData} from "@code-pushup/test-utils"; + +describe('collect report with coverage-plugin NPM package', () => { + const envRoot = 'static-environments/coverage-e2e-env'; + const baseDir = join(envRoot, '__tests__'); + + afterEach(async () => { + await teardownTestFolder(baseDir); + }); + + it('should run Code coverage plugin which collects passed results and creates report.json', async () => { + /** + * The stats passed in the fixture are as follows + * 3 files: one partially covered, one with no coverage, one with full coverage + * Functions: 2 + 1 + 2 found | 1 + 0 + 2 covered (60% coverage) + * Branches: 10 + 2 + 5 found | 8 + 0 + 5 covered (76% coverage) + * Lines: 10 + 5 + 10 found | 7 + 0 + 10 covered (68% coverage) + */ + + const configPath = join( + fileURLToPath(dirname(import.meta.url)), + '..', + 'mocks', + 'fixtures', + 'code-pushup.config.ts', + ); + + const {code, stderr} = await executeProcess({ + command: 'npx', + args: [ + '@code-pushup/cli', + 'collect', + '--no-progress', + `--config=${configPath}`, + '--persist.outputDir=tmp/e2e', + '--onlyPlugins=coverage', + ], + }); + + expect(code).toBe(0); + expect(stderr).toBe(''); + + const report = await readJsonFile(join(envRoot, 'e2e', 'report.json')); + + expect(() => reportSchema.parse(report)).not.toThrow(); + expect(omitVariableReportData(report as Report)).toMatchSnapshot(); + }); + + it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => { + const {code, stderr} = await executeProcess({ + command: 'npx', + args: ['@code-pushup/cli', 'collect', '--no-progress', '--onlyPlugins=coverage'], + cwd: 'examples/react-todos-app', + }); + + expect(code).toBe(0); + expect(stderr).toBe(''); + + const report = await readJsonFile(join(envRoot, '.code-pushup/report.json')); + + expect(() => reportSchema.parse(report)).not.toThrow(); + expect(omitVariableReportData(report as Report)).toMatchSnapshot(); + }); + + +}); diff --git a/e2e/plugin-coverage-e2e/tsconfig.json b/e2e/plugin-coverage-e2e/tsconfig.json new file mode 100644 index 000000000..f5a2f890a --- /dev/null +++ b/e2e/plugin-coverage-e2e/tsconfig.json @@ -0,0 +1,20 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "ESNext", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "types": ["vitest"] + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.test.json" + } + ] +} diff --git a/e2e/plugin-coverage-e2e/tsconfig.test.json b/e2e/plugin-coverage-e2e/tsconfig.test.json new file mode 100644 index 000000000..10c7f79de --- /dev/null +++ b/e2e/plugin-coverage-e2e/tsconfig.test.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"], + "target": "ES2020" + }, + "include": [ + "vite.config.e2e.ts", + "tests/**/*.e2e.test.ts", + "tests/**/*.d.ts", + "mocks/**/*.ts" + ] +} diff --git a/e2e/plugin-coverage-e2e/vite.config.e2e.ts b/e2e/plugin-coverage-e2e/vite.config.e2e.ts new file mode 100644 index 000000000..3956da52e --- /dev/null +++ b/e2e/plugin-coverage-e2e/vite.config.e2e.ts @@ -0,0 +1,21 @@ +/// +import { defineConfig } from 'vite'; +import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases'; + +export default defineConfig({ + cacheDir: '../../node_modules/.vite/plugin-lighthouse-e2e', + test: { + reporters: ['basic'], + testTimeout: 120_000, + globals: true, + alias: tsconfigPathAliases(), + pool: 'threads', + poolOptions: { threads: { singleThread: true } }, + cache: { + dir: '../../node_modules/.vitest', + }, + environment: 'node', + include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'], + }, +}); diff --git a/nx.json b/nx.json index bebd69d65..c7603298b 100644 --- a/nx.json +++ b/nx.json @@ -28,6 +28,9 @@ "e2e": { "dependsOn": ["^build"] }, + "nxv-env-setup": { + "executor": "@push-based/nx-verdaccio:env-setup" + }, "@nx/vite:test": { "cache": true, "inputs": ["default", "^production"], @@ -68,23 +71,7 @@ "appsDir": "examples", "libsDir": "packages" }, - "generators": { - "@nx/react": { - "application": { - "style": "css", - "linter": "eslint", - "bundler": "vite", - "babel": true - }, - "component": { - "style": "css" - }, - "library": { - "style": "css", - "linter": "eslint" - } - } - }, + "generators": {}, "release": { "projects": ["packages/*"], "projectsRelationship": "fixed", diff --git a/package-lock.json b/package-lock.json index 80639ae4b..960950fda 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "@nx/react": "17.3.2", "@nx/vite": "17.3.2", "@nx/workspace": "17.3.2", - "@push-based/nx-verdaccio": "0.0.0-alpha.25", + "@push-based/nx-verdaccio": "0.0.0-alpha.26", "@swc-node/register": "^1.10.9", "@swc/cli": "~0.1.62", "@swc/core": "^1.3.99", @@ -5457,9 +5457,9 @@ } }, "node_modules/@push-based/nx-verdaccio": { - "version": "0.0.0-alpha.25", - "resolved": "https://registry.npmjs.org/@push-based/nx-verdaccio/-/nx-verdaccio-0.0.0-alpha.25.tgz", - "integrity": "sha512-5keAr9Gpw0TjUEwtMZVu/qweBYPPHHxHRNaRJgw94uOGSwcQwFcYn92w3+Z4/VdXhM0/RINALGc+/DgG1PV5fg==", + "version": "0.0.0-alpha.26", + "resolved": "https://registry.npmjs.org/@push-based/nx-verdaccio/-/nx-verdaccio-0.0.0-alpha.26.tgz", + "integrity": "sha512-Go11Dg+w5Ntl5Ig8YNzVVPbpOG85aVszjyBIK0FvVBX+/QllQY1F4fP8K8fYnMJnO9v5Tao3cryGFY5Zo9i+/g==", "dev": true, "dependencies": { "@nx/devkit": "19.8.0", diff --git a/package.json b/package.json index da4f9fb46..354f89a4b 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@nx/react": "17.3.2", "@nx/vite": "17.3.2", "@nx/workspace": "17.3.2", - "@push-based/nx-verdaccio": "0.0.0-alpha.25", + "@push-based/nx-verdaccio": "0.0.0-alpha.26", "@swc-node/register": "^1.10.9", "@swc/cli": "~0.1.62", "@swc/core": "^1.3.99", diff --git a/static-environments/coverage-e2e-env/.gitignore b/static-environments/coverage-e2e-env/.gitignore new file mode 100644 index 000000000..9e76e5c81 --- /dev/null +++ b/static-environments/coverage-e2e-env/.gitignore @@ -0,0 +1,3 @@ +coverage +node_modules +.code-pushup diff --git a/static-environments/coverage-e2e-env/code-pushup.config.ts b/static-environments/coverage-e2e-env/code-pushup.config.ts new file mode 100644 index 000000000..6421554cf --- /dev/null +++ b/static-environments/coverage-e2e-env/code-pushup.config.ts @@ -0,0 +1,16 @@ +import coveragePlugin from '@code-pushup/coverage-plugin'; + +export default { + plugins: [ + await coveragePlugin({ + reports: ['coverage/lcov.info'], + coverageToolCommand: { + command: 'npx', + args: ['vitest', 'run', '--coverage'], + }, + }), + ], + categories: [ + + ], +}; diff --git a/static-environments/coverage-e2e-env/project.json b/static-environments/coverage-e2e-env/project.json new file mode 100644 index 000000000..f8d390e28 --- /dev/null +++ b/static-environments/coverage-e2e-env/project.json @@ -0,0 +1,8 @@ +{ + "name": "coverage-e2e-env", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "static-environments/coverage-e2e-env/src", + "projectType": "library", + "targets": {}, + "tags": ["scope:internal", "type:feature"] +} diff --git a/static-environments/coverage-e2e-env/src/index.mjs b/static-environments/coverage-e2e-env/src/index.mjs new file mode 100644 index 000000000..18178fd1a --- /dev/null +++ b/static-environments/coverage-e2e-env/src/index.mjs @@ -0,0 +1,16 @@ +export function untested() { + console.log('This function is not tested'); +}; + +export function get42() { + return 42; +}; + +export function isEven(num) { + if(num === undefined){ + return false; + } + const parsedNumber = parseInt(num, 10); + return parsedNumber % 2 === 0; +}; + diff --git a/static-environments/coverage-e2e-env/src/index.test.mjs b/static-environments/coverage-e2e-env/src/index.test.mjs new file mode 100644 index 000000000..992e13f71 --- /dev/null +++ b/static-environments/coverage-e2e-env/src/index.test.mjs @@ -0,0 +1,20 @@ +import {describe, expect, it} from "vitest"; +import {get42, isEven, untested} from "./index"; + +describe("get42", () => { + it("should return 42", async () => { + expect(get42()).toBe(42); + }); +}); + +describe("isEven", () => { + it("should return true for even number 42", async () => { + expect(isEven(42)).toBe(true); + }); + + it.todo("should return false for odd number 1") +}); + +describe.todo("untested", () => { + +}); diff --git a/static-environments/coverage-e2e-env/vite.config.ts b/static-environments/coverage-e2e-env/vite.config.ts new file mode 100644 index 000000000..7051bfcef --- /dev/null +++ b/static-environments/coverage-e2e-env/vite.config.ts @@ -0,0 +1,25 @@ +/// +import {dirname} from 'node:path'; +import {fileURLToPath} from 'node:url'; +import {defineConfig} from 'vite'; + +export default defineConfig({ + root: fileURLToPath(dirname(import.meta.url)), + cacheDir: 'node_modules/.vite/coverage-e2e-env', + + test: { + reporters: ['basic'], + globals: true, + cache: { + dir: 'node_modules/.vitest', + }, + coverage: { + reporter: ['lcov', 'text'], + provider: 'v8', + reportsDirectory: 'coverage', + include: ['src/**/*.{js,mjs}'], + }, + environment: 'node', + include: ['src/**/*.{test,spec}.{js,mjs}'] + }, +}); From e8cba86a402a45534cabd009e570523094e168fd Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 18:57:05 +0100 Subject: [PATCH 18/42] config --- e2e/cli-e2e/tests/collect.e2e.test.ts | 55 ------------- .../__snapshots__/collect.e2e.test.ts.snap | 45 ++++++----- .../tests/collect.e2e.test.ts | 49 ++++++------ .../coverage-e2e-env/code-pushup.config.ts | 13 +++- .../code-pushup.existing-report.config.ts | 25 ++++++ .../coverage-e2e-env/mocks/fixtures/lcov.info | 78 +++++++++++++++++++ .../coverage-e2e-env/src/index.mjs | 9 +-- .../coverage-e2e-env/src/index.test.mjs | 18 ++--- .../coverage-e2e-env/vite.config.ts | 8 +- 9 files changed, 179 insertions(+), 121 deletions(-) create mode 100644 static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts create mode 100644 static-environments/coverage-e2e-env/mocks/fixtures/lcov.info diff --git a/e2e/cli-e2e/tests/collect.e2e.test.ts b/e2e/cli-e2e/tests/collect.e2e.test.ts index 5e301ab29..269fae9fb 100644 --- a/e2e/cli-e2e/tests/collect.e2e.test.ts +++ b/e2e/cli-e2e/tests/collect.e2e.test.ts @@ -1,5 +1,3 @@ -import { dirname, join } from 'node:path'; -import { fileURLToPath } from 'node:url'; import { type AuditReport, type PluginReport, @@ -65,59 +63,6 @@ describe('CLI collect', () => { expect(omitVariableReportData(report as Report)).toMatchSnapshot(); }); - it('should run Code coverage plugin which collects passed results and creates report.json', async () => { - /** - * The stats passed in the fixture are as follows - * 3 files: one partially covered, one with no coverage, one with full coverage - * Functions: 2 + 1 + 2 found | 1 + 0 + 2 covered (60% coverage) - * Branches: 10 + 2 + 5 found | 8 + 0 + 5 covered (76% coverage) - * Lines: 10 + 5 + 10 found | 7 + 0 + 10 covered (68% coverage) - */ - - const configPath = join( - fileURLToPath(dirname(import.meta.url)), - '..', - 'mocks', - 'fixtures', - 'code-pushup.config.ts', - ); - - const { code, stderr } = await executeProcess({ - command: 'code-pushup', - args: [ - 'collect', - '--no-progress', - `--config=${configPath}`, - '--persist.outputDir=tmp/e2e', - '--onlyPlugins=coverage', - ], - }); - - expect(code).toBe(0); - expect(stderr).toBe(''); - - const report = await readJsonFile(join('tmp', 'e2e', 'report.json')); - - expect(() => reportSchema.parse(report)).not.toThrow(); - expect(omitVariableReportData(report as Report)).toMatchSnapshot(); - }); - - it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => { - const { code, stderr } = await executeProcess({ - command: 'code-pushup', - args: ['collect', '--no-progress', '--onlyPlugins=coverage'], - cwd: 'examples/react-todos-app', - }); - - expect(code).toBe(0); - expect(stderr).toBe(''); - - const report = await readJsonFile('tmp/e2e/react-todos-app/report.json'); - - expect(() => reportSchema.parse(report)).not.toThrow(); - expect(omitVariableReportData(report as Report)).toMatchSnapshot(); - }); - it('should create report.md', async () => { const { code, stderr } = await executeProcess({ command: 'code-pushup', diff --git a/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index 4dfa1545d..857acd4f4 100644 --- a/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -2,7 +2,20 @@ exports[`collect report with coverage-plugin NPM package > should run Code coverage plugin that runs coverage tool and creates report.json 1`] = ` { - "categories": [], + "categories": [ + { + "refs": [ + { + "plugin": "coverage", + "slug": "coverage", + "type": "group", + "weight": 1, + }, + ], + "slug": "code-coverage", + "title": "Code coverage", + }, + ], "packageName": "@code-pushup/core", "plugins": [ { @@ -39,27 +52,17 @@ exports[`collect report with coverage-plugin NPM package > should run Code cover "source": { "file": "static-environments/coverage-e2e-env/src/index.mjs", "position": { - "startLine": 11, - }, - }, - }, - { - "message": "1st branch is not taken in any test case.", - "severity": "error", - "source": { - "file": "static-environments/coverage-e2e-env/src/index.mjs", - "position": { - "startLine": 15, + "startLine": 10, }, }, }, ], }, - "displayValue": "50 %", - "score": 0.5, + "displayValue": "66.7 %", + "score": 0.6667, "slug": "branch-coverage", "title": "Branch coverage", - "value": 50, + "value": 66.66666666666666, }, { "description": "Measures how many lines of code were executed in at least one test.", @@ -77,23 +80,23 @@ exports[`collect report with coverage-plugin NPM package > should run Code cover }, }, { - "message": "Lines 12-13 are not covered in any test case.", + "message": "Lines 11-12 are not covered in any test case.", "severity": "warning", "source": { "file": "static-environments/coverage-e2e-env/src/index.mjs", "position": { - "endLine": 13, - "startLine": 12, + "endLine": 12, + "startLine": 11, }, }, }, ], }, - "displayValue": "75 %", - "score": 0.75, + "displayValue": "73.3 %", + "score": 0.7333, "slug": "line-coverage", "title": "Line coverage", - "value": 75, + "value": 73.33333333333333, }, ], "description": "Official Code PushUp code coverage plugin.", diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index 5ed03a756..4b169df74 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -1,10 +1,10 @@ -import {dirname, join} from 'node:path'; -import {afterEach} from 'vitest'; -import {teardownTestFolder} from '@code-pushup/test-setup'; -import {fileURLToPath} from "node:url"; -import {executeProcess, readJsonFile} from "@code-pushup/utils"; -import {type Report, reportSchema} from "@code-pushup/models"; -import {omitVariableReportData} from "@code-pushup/test-utils"; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { afterEach } from 'vitest'; +import { type Report, reportSchema } from '@code-pushup/models'; +import { teardownTestFolder } from '@code-pushup/test-setup'; +import { omitVariableReportData } from '@code-pushup/test-utils'; +import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with coverage-plugin NPM package', () => { const envRoot = 'static-environments/coverage-e2e-env'; @@ -23,50 +23,49 @@ describe('collect report with coverage-plugin NPM package', () => { * Lines: 10 + 5 + 10 found | 7 + 0 + 10 covered (68% coverage) */ - const configPath = join( - fileURLToPath(dirname(import.meta.url)), - '..', - 'mocks', - 'fixtures', - 'code-pushup.config.ts', - ); - - const {code, stderr} = await executeProcess({ + const { code, stderr } = await executeProcess({ command: 'npx', args: [ '@code-pushup/cli', 'collect', '--no-progress', - `--config=${configPath}`, - '--persist.outputDir=tmp/e2e', + `--config=code-pushup.existing-report.config.ts`, '--onlyPlugins=coverage', ], + cwd: envRoot, }); expect(code).toBe(0); expect(stderr).toBe(''); - const report = await readJsonFile(join(envRoot, 'e2e', 'report.json')); + const report = await readJsonFile( + join(envRoot, '.code-pushup', 'report.json'), + ); expect(() => reportSchema.parse(report)).not.toThrow(); expect(omitVariableReportData(report as Report)).toMatchSnapshot(); }); it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => { - const {code, stderr} = await executeProcess({ + const { code, stderr } = await executeProcess({ command: 'npx', - args: ['@code-pushup/cli', 'collect', '--no-progress', '--onlyPlugins=coverage'], - cwd: 'examples/react-todos-app', + args: [ + '@code-pushup/cli', + 'collect', + '--no-progress', + '--onlyPlugins=coverage', + ], + cwd: envRoot, }); expect(code).toBe(0); expect(stderr).toBe(''); - const report = await readJsonFile(join(envRoot, '.code-pushup/report.json')); + const report = await readJsonFile( + join(envRoot, '.code-pushup/report.json'), + ); expect(() => reportSchema.parse(report)).not.toThrow(); expect(omitVariableReportData(report as Report)).toMatchSnapshot(); }); - - }); diff --git a/static-environments/coverage-e2e-env/code-pushup.config.ts b/static-environments/coverage-e2e-env/code-pushup.config.ts index 6421554cf..7fdd945d5 100644 --- a/static-environments/coverage-e2e-env/code-pushup.config.ts +++ b/static-environments/coverage-e2e-env/code-pushup.config.ts @@ -11,6 +11,17 @@ export default { }), ], categories: [ - + { + slug: 'code-coverage', + title: 'Code coverage', + refs: [ + { + type: 'group', + plugin: 'coverage', + slug: 'coverage', + weight: 1, + }, + ], + }, ], }; diff --git a/static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts b/static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts new file mode 100644 index 000000000..3ecb63128 --- /dev/null +++ b/static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts @@ -0,0 +1,25 @@ +import { join } from 'node:path'; +import coveragePlugin from '@code-pushup/coverage-plugin'; +import type { CoreConfig } from '@code-pushup/models'; + +export default { + plugins: [ + await coveragePlugin({ + reports: [join('e2e', 'cli-e2e', 'mocks', 'fixtures', 'lcov.info')], + }), + ], + categories: [ + { + slug: 'code-coverage', + title: 'Code coverage', + refs: [ + { + type: 'group', + plugin: 'coverage', + slug: 'coverage', + weight: 1, + }, + ], + }, + ], +} satisfies CoreConfig; diff --git a/static-environments/coverage-e2e-env/mocks/fixtures/lcov.info b/static-environments/coverage-e2e-env/mocks/fixtures/lcov.info new file mode 100644 index 000000000..474ad74e7 --- /dev/null +++ b/static-environments/coverage-e2e-env/mocks/fixtures/lcov.info @@ -0,0 +1,78 @@ +TN: +SF:src\lib\partly-covered\utils.ts +FN:2,formatReportScore +FN:6,calcDuration +FNF:2 +FNH:1 +FNDA:0,formatReportScore +FNDA:6,calcDuration +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:6,1 +DA:7,0 +DA:8,0 +DA:9,0 +DA:10,1 +LF:10 +LH:7 +BRDA:1,0,0,6 +BRDA:1,1,0,5 +BRDA:2,4,0,1 +BRDA:4,5,0,17 +BRDA:5,6,0,4 +BRDA:6,7,0,13 +BRDA:6,10,1,0 +BRDA:7,11,0,3 +BRDA:10,12,0,12 +BRDA:10,13,1,0 +BRF:10 +BRH:8 +end_of_record +SF:src\lib\not-covered\sorting.ts +FN:1,sortReport +FNF:1 +FNH:0 +FNDA:0,sortReport +DA:1,0 +DA:2,0 +DA:3,0 +DA:4,0 +DA:5,0 +LF:5 +LH:0 +BRDA:7,1,0,0 +BRDA:7,2,1,0 +BRF:2 +BRH:0 +end_of_record +TN: +SF:src\lib\fully-covered\scoring.ts +FN:2,scoreReport +FN:8,calculateScore +FNF:2 +FNH:2 +FNDA:3,scoreReport +FNDA:5,calculateScore +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:6,1 +DA:7,1 +DA:8,1 +DA:9,1 +DA:10,1 +LF:10 +LH:10 +BRDA:1,0,0,5 +BRDA:2,1,0,1 +BRDA:2,2,1,4 +BRDA:2,3,2,3 +BRDA:6,4,0,4 +BRF:5 +BRH:5 +end_of_record diff --git a/static-environments/coverage-e2e-env/src/index.mjs b/static-environments/coverage-e2e-env/src/index.mjs index 18178fd1a..b698a1fac 100644 --- a/static-environments/coverage-e2e-env/src/index.mjs +++ b/static-environments/coverage-e2e-env/src/index.mjs @@ -1,16 +1,15 @@ export function untested() { console.log('This function is not tested'); -}; +} export function get42() { return 42; -}; +} export function isEven(num) { - if(num === undefined){ + if (num === undefined) { return false; } const parsedNumber = parseInt(num, 10); return parsedNumber % 2 === 0; -}; - +} diff --git a/static-environments/coverage-e2e-env/src/index.test.mjs b/static-environments/coverage-e2e-env/src/index.test.mjs index 992e13f71..efef0528b 100644 --- a/static-environments/coverage-e2e-env/src/index.test.mjs +++ b/static-environments/coverage-e2e-env/src/index.test.mjs @@ -1,20 +1,18 @@ -import {describe, expect, it} from "vitest"; -import {get42, isEven, untested} from "./index"; +import { describe, expect, it } from 'vitest'; +import { get42, isEven, untested } from './index'; -describe("get42", () => { - it("should return 42", async () => { +describe('get42', () => { + it('should return 42', async () => { expect(get42()).toBe(42); }); }); -describe("isEven", () => { - it("should return true for even number 42", async () => { +describe('isEven', () => { + it('should return true for even number 42', async () => { expect(isEven(42)).toBe(true); }); - it.todo("should return false for odd number 1") + it.todo('should return false for odd number 1'); }); -describe.todo("untested", () => { - -}); +describe.todo('untested', () => {}); diff --git a/static-environments/coverage-e2e-env/vite.config.ts b/static-environments/coverage-e2e-env/vite.config.ts index 7051bfcef..7a6636feb 100644 --- a/static-environments/coverage-e2e-env/vite.config.ts +++ b/static-environments/coverage-e2e-env/vite.config.ts @@ -1,7 +1,7 @@ /// -import {dirname} from 'node:path'; -import {fileURLToPath} from 'node:url'; -import {defineConfig} from 'vite'; +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { defineConfig } from 'vite'; export default defineConfig({ root: fileURLToPath(dirname(import.meta.url)), @@ -20,6 +20,6 @@ export default defineConfig({ include: ['src/**/*.{js,mjs}'], }, environment: 'node', - include: ['src/**/*.{test,spec}.{js,mjs}'] + include: ['src/**/*.{test,spec}.{js,mjs}'], }, }); From 436673f1ca2cd0ab14f4f14159650b231154ee6b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 18:57:58 +0100 Subject: [PATCH 19/42] remove duplicate test --- e2e/cli-e2e/tests/collect.e2e.test.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/e2e/cli-e2e/tests/collect.e2e.test.ts b/e2e/cli-e2e/tests/collect.e2e.test.ts index 5e301ab29..f9aa4eefa 100644 --- a/e2e/cli-e2e/tests/collect.e2e.test.ts +++ b/e2e/cli-e2e/tests/collect.e2e.test.ts @@ -49,22 +49,6 @@ describe('CLI collect', () => { await cleanTestFolder('tmp/e2e/react-todos-app'); }); - it('should run ESLint plugin and create report.json', async () => { - const { code, stderr } = await executeProcess({ - command: 'code-pushup', - args: ['collect', '--no-progress', '--onlyPlugins=eslint'], - cwd: 'examples/react-todos-app', - }); - - expect(code).toBe(0); - expect(stderr).toBe(''); - - const report = await readJsonFile('tmp/e2e/react-todos-app/report.json'); - - expect(() => reportSchema.parse(report)).not.toThrow(); - expect(omitVariableReportData(report as Report)).toMatchSnapshot(); - }); - it('should run Code coverage plugin which collects passed results and creates report.json', async () => { /** * The stats passed in the fixture are as follows From 69eba2522893ff4afb78aa28eaf28e18d93cffd5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 19:01:08 +0100 Subject: [PATCH 20/42] polish --- .../__snapshots__/collect.e2e.test.ts.snap | 171 ++++++++++++++++++ .../tests/collect.e2e.test.ts | 3 +- .../code-pushup.existing-report.config.ts | 2 +- .../coverage-e2e-env/package.json | 17 ++ 4 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 static-environments/coverage-e2e-env/package.json diff --git a/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index 857acd4f4..610e3b0a3 100644 --- a/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -130,3 +130,174 @@ exports[`collect report with coverage-plugin NPM package > should run Code cover ], } `; + +exports[`collect report with coverage-plugin NPM package > should run Code coverage plugin which collects passed results and creates report.json 1`] = ` +{ + "categories": [ + { + "refs": [ + { + "plugin": "coverage", + "slug": "coverage", + "type": "group", + "weight": 1, + }, + ], + "slug": "code-coverage", + "title": "Code coverage", + }, + ], + "packageName": "@code-pushup/core", + "plugins": [ + { + "audits": [ + { + "description": "Measures how many functions were called in at least one test.", + "details": { + "issues": [ + { + "message": "Function formatReportScore is not called in any test case.", + "severity": "error", + "source": { + "file": "static-environments/coverage-e2e-env/src/lib/partly-covered/utils.ts", + "position": { + "startLine": 2, + }, + }, + }, + { + "message": "Function sortReport is not called in any test case.", + "severity": "error", + "source": { + "file": "static-environments/coverage-e2e-env/src/lib/not-covered/sorting.ts", + "position": { + "startLine": 1, + }, + }, + }, + ], + }, + "displayValue": "60 %", + "score": 0.6, + "slug": "function-coverage", + "title": "Function coverage", + "value": 60, + }, + { + "description": "Measures how many branches were executed after conditional statements in at least one test.", + "details": { + "issues": [ + { + "message": "2nd branch is not taken in any test case.", + "severity": "error", + "source": { + "file": "static-environments/coverage-e2e-env/src/lib/partly-covered/utils.ts", + "position": { + "startLine": 6, + }, + }, + }, + { + "message": "2nd branch is not taken in any test case.", + "severity": "error", + "source": { + "file": "static-environments/coverage-e2e-env/src/lib/partly-covered/utils.ts", + "position": { + "startLine": 10, + }, + }, + }, + { + "message": "1st branch is not taken in any test case.", + "severity": "error", + "source": { + "file": "static-environments/coverage-e2e-env/src/lib/not-covered/sorting.ts", + "position": { + "startLine": 7, + }, + }, + }, + { + "message": "2nd branch is not taken in any test case.", + "severity": "error", + "source": { + "file": "static-environments/coverage-e2e-env/src/lib/not-covered/sorting.ts", + "position": { + "startLine": 7, + }, + }, + }, + ], + }, + "displayValue": "76.5 %", + "score": 0.7647, + "slug": "branch-coverage", + "title": "Branch coverage", + "value": 76.47058823529412, + }, + { + "description": "Measures how many lines of code were executed in at least one test.", + "details": { + "issues": [ + { + "message": "Lines 7-9 are not covered in any test case.", + "severity": "warning", + "source": { + "file": "static-environments/coverage-e2e-env/src/lib/partly-covered/utils.ts", + "position": { + "endLine": 9, + "startLine": 7, + }, + }, + }, + { + "message": "Lines 1-5 are not covered in any test case.", + "severity": "warning", + "source": { + "file": "static-environments/coverage-e2e-env/src/lib/not-covered/sorting.ts", + "position": { + "endLine": 5, + "startLine": 1, + }, + }, + }, + ], + }, + "displayValue": "68 %", + "score": 0.68, + "slug": "line-coverage", + "title": "Line coverage", + "value": 68, + }, + ], + "description": "Official Code PushUp code coverage plugin.", + "docsUrl": "https://www.npmjs.com/package/@code-pushup/coverage-plugin/", + "groups": [ + { + "description": "Group containing all defined coverage types as audits.", + "refs": [ + { + "slug": "function-coverage", + "weight": 6, + }, + { + "slug": "branch-coverage", + "weight": 3, + }, + { + "slug": "line-coverage", + "weight": 1, + }, + ], + "slug": "coverage", + "title": "Code coverage metrics", + }, + ], + "icon": "folder-coverage-open", + "packageName": "@code-pushup/coverage-plugin", + "slug": "coverage", + "title": "Code coverage", + }, + ], +} +`; diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index 4b169df74..6b3a01e42 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -1,5 +1,4 @@ -import { dirname, join } from 'node:path'; -import { fileURLToPath } from 'node:url'; +import { join } from 'node:path'; import { afterEach } from 'vitest'; import { type Report, reportSchema } from '@code-pushup/models'; import { teardownTestFolder } from '@code-pushup/test-setup'; diff --git a/static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts b/static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts index 3ecb63128..9f6fffbb8 100644 --- a/static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts +++ b/static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts @@ -5,7 +5,7 @@ import type { CoreConfig } from '@code-pushup/models'; export default { plugins: [ await coveragePlugin({ - reports: [join('e2e', 'cli-e2e', 'mocks', 'fixtures', 'lcov.info')], + reports: [join('mocks', 'fixtures', 'lcov.info')], }), ], categories: [ diff --git a/static-environments/coverage-e2e-env/package.json b/static-environments/coverage-e2e-env/package.json new file mode 100644 index 000000000..a300af90f --- /dev/null +++ b/static-environments/coverage-e2e-env/package.json @@ -0,0 +1,17 @@ +{ + "name": "coverage-e2e-env", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@code-pushup/coverage-plugin": "^0.54.0", + "@code-pushup/models": "^0.54.0", + "@code-pushup/utils": "^0.54.0" + }, + "description": "" +} From ff441116c136acd4d5d0310d21b007bda6d2b232 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 19:02:34 +0100 Subject: [PATCH 21/42] polish --- e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index 6b3a01e42..747fe0571 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -14,14 +14,6 @@ describe('collect report with coverage-plugin NPM package', () => { }); it('should run Code coverage plugin which collects passed results and creates report.json', async () => { - /** - * The stats passed in the fixture are as follows - * 3 files: one partially covered, one with no coverage, one with full coverage - * Functions: 2 + 1 + 2 found | 1 + 0 + 2 covered (60% coverage) - * Branches: 10 + 2 + 5 found | 8 + 0 + 5 covered (76% coverage) - * Lines: 10 + 5 + 10 found | 7 + 0 + 10 covered (68% coverage) - */ - const { code, stderr } = await executeProcess({ command: 'npx', args: [ From 9ddce4df4d051d5791e470aa4b5c20e30b0d716a Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 19:08:41 +0100 Subject: [PATCH 22/42] remove duplicate CP runs --- .../react-todos-app/code-pushup.config.js | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/examples/react-todos-app/code-pushup.config.js b/examples/react-todos-app/code-pushup.config.js index dcef94a7f..988dca804 100644 --- a/examples/react-todos-app/code-pushup.config.js +++ b/examples/react-todos-app/code-pushup.config.js @@ -1,4 +1,3 @@ -import coveragePlugin from '../../dist/packages/plugin-coverage'; import eslintPlugin from '../../dist/packages/plugin-eslint'; const eslintAuditRef = (slug, weight) => ({ @@ -13,31 +12,12 @@ export default { outputDir: '../../tmp/e2e/react-todos-app', }, plugins: [ - await coveragePlugin({ - reports: ['../../coverage/react-todos-app/lcov.info'], - coverageToolCommand: { - command: 'npx', - args: ['vitest', 'run', '--coverage'], - }, - }), await eslintPlugin({ eslintrc: '.eslintrc.js', patterns: ['src/**/*.js', 'src/**/*.jsx'], }), ], categories: [ - { - slug: 'code-coverage', - title: 'Code coverage', - refs: [ - { - type: 'group', - plugin: 'coverage', - slug: 'coverage', - weight: 1, - }, - ], - }, { slug: 'bug-prevention', title: 'Bug prevention', @@ -60,7 +40,6 @@ export default { eslintAuditRef('react-hooks-exhaustive-deps', 2), ], }, - { slug: 'code-style', title: 'Code style', From 3239423359f83022f8101a9b36d4c17b2286305d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 19:37:59 +0100 Subject: [PATCH 23/42] add test script --- static-environments/coverage-e2e-env/code-pushup.config.ts | 4 ++-- static-environments/coverage-e2e-env/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/static-environments/coverage-e2e-env/code-pushup.config.ts b/static-environments/coverage-e2e-env/code-pushup.config.ts index 7fdd945d5..8d506c569 100644 --- a/static-environments/coverage-e2e-env/code-pushup.config.ts +++ b/static-environments/coverage-e2e-env/code-pushup.config.ts @@ -5,8 +5,8 @@ export default { await coveragePlugin({ reports: ['coverage/lcov.info'], coverageToolCommand: { - command: 'npx', - args: ['vitest', 'run', '--coverage'], + command: 'npm', + args: ['run', 'test'], }, }), ], diff --git a/static-environments/coverage-e2e-env/package.json b/static-environments/coverage-e2e-env/package.json index a300af90f..34be6d532 100644 --- a/static-environments/coverage-e2e-env/package.json +++ b/static-environments/coverage-e2e-env/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "npx vitest run --coverage" }, "keywords": [], "author": "", From 3ad8ee4b6c4be3be57d953108501a694c0c23403 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 19:47:38 +0100 Subject: [PATCH 24/42] verbose gh action --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 845def216..a8ad36da1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,7 +120,7 @@ jobs: - name: Install dependencies run: npm ci - name: E2E test affected projects - run: npx nx affected -t nxv-e2e --exclude cli-e2e --parallel=1 + run: npx nx affected -t nxv-e2e --exclude cli-e2e --parallel=1 --verbose - name: E2E test cli-e2e project (due to bugs in the setup it has to run last :( ) run: npx nx run cli-e2e:e2e-old From a624b5aa582613597ce6976c71ba305763bf8fa3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 10 Nov 2024 02:34:14 +0100 Subject: [PATCH 25/42] adjust tests --- e2e/plugin-coverage-e2e/project.json | 5 +++++ nx.json | 1 + static-environments/coverage-e2e-env/package.json | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/e2e/plugin-coverage-e2e/project.json b/e2e/plugin-coverage-e2e/project.json index fdf8f2e3c..4c4f76881 100644 --- a/e2e/plugin-coverage-e2e/project.json +++ b/e2e/plugin-coverage-e2e/project.json @@ -11,6 +11,11 @@ "lintFilePatterns": ["e2e/plugin-coverage-e2e/**/*.ts"] } }, + "nxv-e2e": { + "options": { + "environmentRoot": "static-environments/coverage-e2e-env" + } + }, "nxv-env-setup": { "options": { "environmentRoot": "static-environments/coverage-e2e-env" diff --git a/nx.json b/nx.json index c7603298b..299156fe9 100644 --- a/nx.json +++ b/nx.json @@ -28,6 +28,7 @@ "e2e": { "dependsOn": ["^build"] }, + "nxv-e2e": {}, "nxv-env-setup": { "executor": "@push-based/nx-verdaccio:env-setup" }, diff --git a/static-environments/coverage-e2e-env/package.json b/static-environments/coverage-e2e-env/package.json index 34be6d532..c132d93f1 100644 --- a/static-environments/coverage-e2e-env/package.json +++ b/static-environments/coverage-e2e-env/package.json @@ -8,10 +8,11 @@ "keywords": [], "author": "", "license": "ISC", + "description": "", "dependencies": { + "@code-pushup/core": "^0.54.0", "@code-pushup/coverage-plugin": "^0.54.0", "@code-pushup/models": "^0.54.0", "@code-pushup/utils": "^0.54.0" - }, - "description": "" + } } From 1647e380b15cf89a708a19cc75f438bbb435328b Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 11 Nov 2024 17:47:43 +0100 Subject: [PATCH 26/42] colocate e2e files --- e2e/plugin-eslint-e2e/project.json | 7 ++++- .../tests/collect.e2e.test.ts | 6 ++--- e2e/plugin-eslint-e2e/tsconfig.test.json | 3 +++ .../eslint-e2e-env/.eslintrc.json | 20 -------------- .../eslint-e2e-env/code-pushup.config.ts | 27 ------------------- .../eslint-e2e-env/project.json | 8 ------ .../eslint-e2e-env/src/index.js | 7 ----- 7 files changed, 12 insertions(+), 66 deletions(-) delete mode 100644 static-environments/eslint-e2e-env/.eslintrc.json delete mode 100644 static-environments/eslint-e2e-env/code-pushup.config.ts delete mode 100644 static-environments/eslint-e2e-env/project.json delete mode 100644 static-environments/eslint-e2e-env/src/index.js diff --git a/e2e/plugin-eslint-e2e/project.json b/e2e/plugin-eslint-e2e/project.json index 6487d3102..05dac3ffc 100644 --- a/e2e/plugin-eslint-e2e/project.json +++ b/e2e/plugin-eslint-e2e/project.json @@ -11,9 +11,14 @@ "lintFilePatterns": ["e2e/plugin-eslint-e2e/**/*.ts"] } }, + "nxv-e2e": { + "options": { + "environmentRoot": "e2e/plugin-eslint-e2e/__test-env__" + } + }, "nxv-env-setup": { "options": { - "environmentRoot": "static-environments/eslint-e2e-env" + "environmentRoot": "e2e/plugin-eslint-e2e/__test-env__" } }, "e2e": { diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index 17d7d05be..5587090e5 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -6,8 +6,8 @@ import { omitVariableReportData } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with eslint-plugin NPM package', () => { - const envRoot = 'static-environments/eslint-e2e-env'; - const baseDir = join(envRoot, '__tests__'); + const envRoot = 'e2e/plugin-eslint-e2e/__test-env__'; + const baseDir = join(envRoot); afterEach(async () => { await teardownTestFolder(baseDir); @@ -16,7 +16,7 @@ describe('collect report with eslint-plugin NPM package', () => { it('should run ESLint plugin and create report.json', async () => { const outputDir = relative( envRoot, - join(baseDir, 'default-report', '.code-pushup'), + join(baseDir, '.code-pushup'), ); const { code, stderr } = await executeProcess({ command: 'npx', diff --git a/e2e/plugin-eslint-e2e/tsconfig.test.json b/e2e/plugin-eslint-e2e/tsconfig.test.json index 10c7f79de..419f13bc6 100644 --- a/e2e/plugin-eslint-e2e/tsconfig.test.json +++ b/e2e/plugin-eslint-e2e/tsconfig.test.json @@ -5,6 +5,9 @@ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"], "target": "ES2020" }, + "exclude": [ + "__test-env__" + ], "include": [ "vite.config.e2e.ts", "tests/**/*.e2e.test.ts", diff --git a/static-environments/eslint-e2e-env/.eslintrc.json b/static-environments/eslint-e2e-env/.eslintrc.json deleted file mode 100644 index 113136c93..000000000 --- a/static-environments/eslint-e2e-env/.eslintrc.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "root": true, - "ignorePatterns": ["code-pushup.config.ts"], - "overrides": [ - { - "files": ["*.js"], - "env": { - "node": true - }, - "parserOptions": { - "sourceType": "script" - }, - "rules": { - "no-unused-vars": "error", - "no-console": "warn", - "no-undef": "error" - } - } - ] -} diff --git a/static-environments/eslint-e2e-env/code-pushup.config.ts b/static-environments/eslint-e2e-env/code-pushup.config.ts deleted file mode 100644 index 01feaf2ff..000000000 --- a/static-environments/eslint-e2e-env/code-pushup.config.ts +++ /dev/null @@ -1,27 +0,0 @@ -import eslintPlugin from '@code-pushup/eslint-plugin'; - -export default { - plugins: [ - await eslintPlugin({ - eslintrc: '.eslintrc.json', - patterns: ['src/*.js'], - }), - ], - categories: [ - { - slug: 'bug-prevention', - title: 'Bug prevention', - description: 'Lint rules that find **potential bugs** in your code.', - refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }], - }, - { - slug: 'code-style', - title: 'Code style', - description: - 'Lint rules that promote **good practices** and consistency in your code.', - refs: [ - { type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 }, - ], - }, - ], -}; diff --git a/static-environments/eslint-e2e-env/project.json b/static-environments/eslint-e2e-env/project.json deleted file mode 100644 index 857adc78f..000000000 --- a/static-environments/eslint-e2e-env/project.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "eslint-e2e-env", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "static-environments/eslint-e2e-env/src", - "projectType": "library", - "targets": {}, - "tags": ["scope:internal", "type:feature"] -} diff --git a/static-environments/eslint-e2e-env/src/index.js b/static-environments/eslint-e2e-env/src/index.js deleted file mode 100644 index 4710a3767..000000000 --- a/static-environments/eslint-e2e-env/src/index.js +++ /dev/null @@ -1,7 +0,0 @@ -function unusedFn() { - return '42'; -} - -module.exports = function consoleLog() { - console.log('No console.log()!'); -}; From 4a615242746e37cd2e5793cc967b60eec2d515ce Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 11 Nov 2024 18:06:55 +0100 Subject: [PATCH 27/42] cleanup --- .../__snapshots__/collect.e2e.test.ts.snap | 1000 ----------------- e2e/plugin-eslint-e2e/project.json | 2 +- .../tests/collect.e2e.test.ts | 5 +- e2e/plugin-eslint-e2e/tsconfig.test.json | 4 +- 4 files changed, 3 insertions(+), 1008 deletions(-) diff --git a/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index 47a9e0f07..063ffb7ea 100644 --- a/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -419,1003 +419,3 @@ exports[`CLI collect > should run Code coverage plugin which collects passed res ], } `; - -exports[`CLI collect > should run ESLint plugin and create report.json 1`] = ` -{ - "categories": [ - { - "refs": [ - { - "plugin": "eslint", - "slug": "no-cond-assign", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "no-const-assign", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "no-debugger", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "no-invalid-regexp", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "no-undef", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "no-unreachable-loop", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "no-unsafe-negation", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "no-unsafe-optional-chaining", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "use-isnan", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "valid-typeof", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "eqeqeq", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "react-jsx-key", - "type": "audit", - "weight": 2, - }, - { - "plugin": "eslint", - "slug": "react-prop-types", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "react-react-in-jsx-scope", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "react-hooks-rules-of-hooks", - "type": "audit", - "weight": 2, - }, - { - "plugin": "eslint", - "slug": "react-hooks-exhaustive-deps", - "type": "audit", - "weight": 2, - }, - ], - "slug": "bug-prevention", - "title": "Bug prevention", - }, - { - "refs": [ - { - "plugin": "eslint", - "slug": "no-unused-vars", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "arrow-body-style", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "camelcase", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "curly", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "eqeqeq", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "max-lines-per-function", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "max-lines", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "object-shorthand", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "prefer-arrow-callback", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "prefer-const", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "prefer-object-spread", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "yoda", - "type": "audit", - "weight": 1, - }, - { - "plugin": "eslint", - "slug": "no-var", - "type": "audit", - "weight": 1, - }, - ], - "slug": "code-style", - "title": "Code style", - }, - ], - "packageName": "@code-pushup/core", - "plugins": [ - { - "audits": [ - { - "description": "ESLint rule **no-cond-assign**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/no-cond-assign", - "score": 1, - "slug": "no-cond-assign", - "title": "Disallow assignment operators in conditional expressions", - "value": 0, - }, - { - "description": "ESLint rule **no-const-assign**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/no-const-assign", - "score": 1, - "slug": "no-const-assign", - "title": "Disallow reassigning \`const\` variables", - "value": 0, - }, - { - "description": "ESLint rule **no-debugger**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/no-debugger", - "score": 1, - "slug": "no-debugger", - "title": "Disallow the use of \`debugger\`", - "value": 0, - }, - { - "description": "ESLint rule **no-invalid-regexp**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/no-invalid-regexp", - "score": 1, - "slug": "no-invalid-regexp", - "title": "Disallow invalid regular expression strings in \`RegExp\` constructors", - "value": 0, - }, - { - "description": "ESLint rule **no-undef**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/no-undef", - "score": 1, - "slug": "no-undef", - "title": "Disallow the use of undeclared variables unless mentioned in \`/*global */\` comments", - "value": 0, - }, - { - "description": "ESLint rule **no-unreachable-loop**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/no-unreachable-loop", - "score": 1, - "slug": "no-unreachable-loop", - "title": "Disallow loops with a body that allows only one iteration", - "value": 0, - }, - { - "description": "ESLint rule **no-unsafe-negation**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/no-unsafe-negation", - "score": 1, - "slug": "no-unsafe-negation", - "title": "Disallow negating the left operand of relational operators", - "value": 0, - }, - { - "description": "ESLint rule **no-unsafe-optional-chaining**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/no-unsafe-optional-chaining", - "score": 1, - "slug": "no-unsafe-optional-chaining", - "title": "Disallow use of optional chaining in contexts where the \`undefined\` value is not allowed", - "value": 0, - }, - { - "description": "ESLint rule **no-unused-vars**.", - "details": { - "issues": [ - { - "message": "'loading' is assigned a value but never used.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/App.jsx", - "position": { - "endColumn": 18, - "endLine": 8, - "startColumn": 11, - "startLine": 8, - }, - }, - }, - ], - }, - "displayValue": "1 warning", - "docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars", - "score": 0, - "slug": "no-unused-vars", - "title": "Disallow unused variables", - "value": 1, - }, - { - "description": "ESLint rule **use-isnan**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/use-isnan", - "score": 1, - "slug": "use-isnan", - "title": "Require calls to \`isNaN()\` when checking for \`NaN\`", - "value": 0, - }, - { - "description": "ESLint rule **valid-typeof**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/valid-typeof", - "score": 1, - "slug": "valid-typeof", - "title": "Enforce comparing \`typeof\` expressions against valid strings", - "value": 0, - }, - { - "description": "ESLint rule **arrow-body-style**.", - "details": { - "issues": [ - { - "message": "Unexpected block statement surrounding arrow body; move the returned value immediately after the \`=>\`.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoFilter.jsx", - "position": { - "endColumn": 2, - "endLine": 25, - "startColumn": 29, - "startLine": 3, - }, - }, - }, - ], - }, - "displayValue": "1 warning", - "docsUrl": "https://eslint.org/docs/latest/rules/arrow-body-style", - "score": 0, - "slug": "arrow-body-style", - "title": "Require braces around arrow function bodies", - "value": 1, - }, - { - "description": "ESLint rule **camelcase**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/camelcase", - "score": 1, - "slug": "camelcase", - "title": "Enforce camelcase naming convention", - "value": 0, - }, - { - "description": "ESLint rule **curly**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/curly", - "score": 1, - "slug": "curly", - "title": "Enforce consistent brace style for all control statements", - "value": 0, - }, - { - "description": "ESLint rule **eqeqeq**.", - "details": { - "issues": [ - { - "message": "Expected '===' and instead saw '=='.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 43, - "endLine": 41, - "startColumn": 41, - "startLine": 41, - }, - }, - }, - ], - }, - "displayValue": "1 warning", - "docsUrl": "https://eslint.org/docs/latest/rules/eqeqeq", - "score": 0, - "slug": "eqeqeq", - "title": "Require the use of \`===\` and \`!==\`", - "value": 1, - }, - { - "description": "ESLint rule **max-lines-per-function**.", - "details": { - "issues": [ - { - "message": "Arrow function has too many lines (71). Maximum allowed is 50.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 2, - "endLine": 73, - "startColumn": 25, - "startLine": 3, - }, - }, - }, - ], - }, - "displayValue": "1 warning", - "docsUrl": "https://eslint.org/docs/latest/rules/max-lines-per-function", - "score": 0, - "slug": "max-lines-per-function", - "title": "Enforce a maximum number of lines of code in a function", - "value": 1, - }, - { - "description": "ESLint rule **max-lines**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/max-lines", - "score": 1, - "slug": "max-lines", - "title": "Enforce a maximum number of lines per file", - "value": 0, - }, - { - "description": "ESLint rule **no-shadow**.", - "details": { - "issues": [ - { - "message": "'data' is already declared in the upper scope on line 5 column 10.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 17, - "endLine": 11, - "startColumn": 13, - "startLine": 11, - }, - }, - }, - { - "message": "'data' is already declared in the upper scope on line 5 column 10.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 21, - "endLine": 29, - "startColumn": 17, - "startLine": 29, - }, - }, - }, - { - "message": "'data' is already declared in the upper scope on line 5 column 10.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 17, - "endLine": 41, - "startColumn": 13, - "startLine": 41, - }, - }, - }, - ], - }, - "displayValue": "3 warnings", - "docsUrl": "https://eslint.org/docs/latest/rules/no-shadow", - "score": 0, - "slug": "no-shadow", - "title": "Disallow variable declarations from shadowing variables declared in the outer scope", - "value": 3, - }, - { - "description": "ESLint rule **no-var**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/no-var", - "score": 1, - "slug": "no-var", - "title": "Require \`let\` or \`const\` instead of \`var\`", - "value": 0, - }, - { - "description": "ESLint rule **object-shorthand**.", - "details": { - "issues": [ - { - "message": "Expected property shorthand.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 19, - "endLine": 19, - "startColumn": 7, - "startLine": 19, - }, - }, - }, - { - "message": "Expected property shorthand.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 19, - "endLine": 32, - "startColumn": 13, - "startLine": 32, - }, - }, - }, - { - "message": "Expected property shorthand.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 25, - "endLine": 33, - "startColumn": 13, - "startLine": 33, - }, - }, - }, - ], - }, - "displayValue": "3 warnings", - "docsUrl": "https://eslint.org/docs/latest/rules/object-shorthand", - "score": 0, - "slug": "object-shorthand", - "title": "Require or disallow method and property shorthand syntax for object literals", - "value": 3, - }, - { - "description": "ESLint rule **prefer-arrow-callback**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/prefer-arrow-callback", - "score": 1, - "slug": "prefer-arrow-callback", - "title": "Require using arrow functions for callbacks", - "value": 0, - }, - { - "description": "ESLint rule **prefer-const**.", - "details": { - "issues": [ - { - "message": "'root' is never reassigned. Use 'const' instead.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/index.jsx", - "position": { - "endColumn": 9, - "endLine": 5, - "startColumn": 5, - "startLine": 5, - }, - }, - }, - ], - }, - "displayValue": "1 warning", - "docsUrl": "https://eslint.org/docs/latest/rules/prefer-const", - "score": 0, - "slug": "prefer-const", - "title": "Require \`const\` declarations for variables that are never reassigned after declared", - "value": 1, - }, - { - "description": "ESLint rule **prefer-object-spread**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/prefer-object-spread", - "score": 1, - "slug": "prefer-object-spread", - "title": "Disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead", - "value": 0, - }, - { - "description": "ESLint rule **yoda**.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://eslint.org/docs/latest/rules/yoda", - "score": 1, - "slug": "yoda", - "title": "Require or disallow "Yoda" conditions", - "value": 0, - }, - { - "description": "ESLint rule **jsx-key**, from _react_ plugin.", - "details": { - "issues": [ - { - "message": "Missing "key" prop for element in iterator", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoList.jsx", - "position": { - "endColumn": 12, - "endLine": 28, - "startColumn": 7, - "startLine": 7, - }, - }, - }, - ], - }, - "displayValue": "1 warning", - "docsUrl": "https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/jsx-key.md", - "score": 0, - "slug": "react-jsx-key", - "title": "Disallow missing \`key\` props in iterators/collection literals", - "value": 1, - }, - { - "description": "ESLint rule **prop-types**, from _react_ plugin.", - "details": { - "issues": [ - { - "message": "'onCreate' is missing in props validation", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/CreateTodo.jsx", - "position": { - "endColumn": 23, - "endLine": 15, - "startColumn": 15, - "startLine": 15, - }, - }, - }, - { - "message": "'setQuery' is missing in props validation", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoFilter.jsx", - "position": { - "endColumn": 25, - "endLine": 10, - "startColumn": 17, - "startLine": 10, - }, - }, - }, - { - "message": "'setHideComplete' is missing in props validation", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoFilter.jsx", - "position": { - "endColumn": 34, - "endLine": 18, - "startColumn": 19, - "startLine": 18, - }, - }, - }, - { - "message": "'todos' is missing in props validation", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoList.jsx", - "position": { - "endColumn": 17, - "endLine": 6, - "startColumn": 12, - "startLine": 6, - }, - }, - }, - { - "message": "'todos.map' is missing in props validation", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoList.jsx", - "position": { - "endColumn": 21, - "endLine": 6, - "startColumn": 18, - "startLine": 6, - }, - }, - }, - { - "message": "'onEdit' is missing in props validation", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoList.jsx", - "position": { - "endColumn": 27, - "endLine": 13, - "startColumn": 21, - "startLine": 13, - }, - }, - }, - ], - }, - "displayValue": "6 warnings", - "docsUrl": "https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/prop-types.md", - "score": 0, - "slug": "react-prop-types", - "title": "Disallow missing props validation in a React component definition", - "value": 6, - }, - { - "description": "ESLint rule **react-in-jsx-scope**, from _react_ plugin.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/react-in-jsx-scope.md", - "score": 1, - "slug": "react-react-in-jsx-scope", - "title": "Disallow missing React when using JSX", - "value": 0, - }, - { - "description": "ESLint rule **jsx-uses-vars**, from _react_ plugin.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/jsx-uses-vars.md", - "score": 1, - "slug": "react-jsx-uses-vars", - "title": "Disallow variables used in JSX to be incorrectly marked as unused", - "value": 0, - }, - { - "description": "ESLint rule **jsx-uses-react**, from _react_ plugin.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/jsx-uses-react.md", - "score": 1, - "slug": "react-jsx-uses-react", - "title": "Disallow React to be incorrectly marked as unused", - "value": 0, - }, - { - "description": "ESLint rule **rules-of-hooks**, from _react-hooks_ plugin.", - "details": { - "issues": [], - }, - "displayValue": "passed", - "docsUrl": "https://reactjs.org/docs/hooks-rules.html", - "score": 1, - "slug": "react-hooks-rules-of-hooks", - "title": "enforces the Rules of Hooks", - "value": 0, - }, - { - "description": "ESLint rule **exhaustive-deps**, from _react-hooks_ plugin.", - "details": { - "issues": [ - { - "message": "React Hook useCallback does nothing when called with only one argument. Did you forget to pass an array of dependencies?", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 31, - "endLine": 17, - "startColumn": 20, - "startLine": 17, - }, - }, - }, - { - "message": "React Hook useCallback does nothing when called with only one argument. Did you forget to pass an array of dependencies?", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endColumn": 29, - "endLine": 40, - "startColumn": 18, - "startLine": 40, - }, - }, - }, - ], - }, - "displayValue": "2 warnings", - "docsUrl": "https://github.com/facebook/react/issues/14920", - "score": 0, - "slug": "react-hooks-exhaustive-deps", - "title": "verifies the list of dependencies for Hooks like useEffect and similar", - "value": 2, - }, - ], - "description": "Official Code PushUp ESLint plugin", - "docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin", - "groups": [ - { - "description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.", - "refs": [ - { - "slug": "no-cond-assign", - "weight": 1, - }, - { - "slug": "no-const-assign", - "weight": 1, - }, - { - "slug": "no-debugger", - "weight": 1, - }, - { - "slug": "no-invalid-regexp", - "weight": 1, - }, - { - "slug": "no-undef", - "weight": 1, - }, - { - "slug": "no-unreachable-loop", - "weight": 1, - }, - { - "slug": "no-unsafe-negation", - "weight": 1, - }, - { - "slug": "no-unsafe-optional-chaining", - "weight": 1, - }, - { - "slug": "no-unused-vars", - "weight": 1, - }, - { - "slug": "use-isnan", - "weight": 1, - }, - { - "slug": "valid-typeof", - "weight": 1, - }, - { - "slug": "react-hooks-rules-of-hooks", - "weight": 1, - }, - ], - "slug": "problems", - "title": "Problems", - }, - { - "description": "Something that could be done in a better way but no errors will occur if the code isn't changed.", - "refs": [ - { - "slug": "arrow-body-style", - "weight": 1, - }, - { - "slug": "camelcase", - "weight": 1, - }, - { - "slug": "curly", - "weight": 1, - }, - { - "slug": "eqeqeq", - "weight": 1, - }, - { - "slug": "max-lines-per-function", - "weight": 1, - }, - { - "slug": "max-lines", - "weight": 1, - }, - { - "slug": "no-shadow", - "weight": 1, - }, - { - "slug": "no-var", - "weight": 1, - }, - { - "slug": "object-shorthand", - "weight": 1, - }, - { - "slug": "prefer-arrow-callback", - "weight": 1, - }, - { - "slug": "prefer-const", - "weight": 1, - }, - { - "slug": "prefer-object-spread", - "weight": 1, - }, - { - "slug": "yoda", - "weight": 1, - }, - { - "slug": "react-hooks-exhaustive-deps", - "weight": 1, - }, - ], - "slug": "suggestions", - "title": "Suggestions", - }, - { - "refs": [ - { - "slug": "react-prop-types", - "weight": 1, - }, - { - "slug": "react-jsx-uses-vars", - "weight": 1, - }, - { - "slug": "react-jsx-uses-react", - "weight": 1, - }, - ], - "slug": "react-best-practices", - "title": "Best Practices (react)", - }, - { - "refs": [ - { - "slug": "react-jsx-key", - "weight": 1, - }, - { - "slug": "react-react-in-jsx-scope", - "weight": 1, - }, - ], - "slug": "react-possible-errors", - "title": "Possible Errors (react)", - }, - ], - "icon": "eslint", - "packageName": "@code-pushup/eslint-plugin", - "slug": "eslint", - "title": "ESLint", - }, - ], -} -`; diff --git a/e2e/plugin-eslint-e2e/project.json b/e2e/plugin-eslint-e2e/project.json index 05dac3ffc..301f6d19a 100644 --- a/e2e/plugin-eslint-e2e/project.json +++ b/e2e/plugin-eslint-e2e/project.json @@ -28,6 +28,6 @@ } } }, - "implicitDependencies": ["cli", "plugin-eslint", "eslint-e2e-env"], + "implicitDependencies": ["cli", "plugin-eslint"], "tags": ["scope:plugin", "type:e2e"] } diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index 5587090e5..a510876b0 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -14,10 +14,7 @@ describe('collect report with eslint-plugin NPM package', () => { }); it('should run ESLint plugin and create report.json', async () => { - const outputDir = relative( - envRoot, - join(baseDir, '.code-pushup'), - ); + const outputDir = relative(envRoot, join(baseDir, '.code-pushup')); const { code, stderr } = await executeProcess({ command: 'npx', args: [ diff --git a/e2e/plugin-eslint-e2e/tsconfig.test.json b/e2e/plugin-eslint-e2e/tsconfig.test.json index 419f13bc6..7e4507b8b 100644 --- a/e2e/plugin-eslint-e2e/tsconfig.test.json +++ b/e2e/plugin-eslint-e2e/tsconfig.test.json @@ -5,9 +5,7 @@ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"], "target": "ES2020" }, - "exclude": [ - "__test-env__" - ], + "exclude": ["__test-env__"], "include": [ "vite.config.e2e.ts", "tests/**/*.e2e.test.ts", From c32e1589e6401802049496bef1eada5f27245c72 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 11 Nov 2024 18:29:40 +0100 Subject: [PATCH 28/42] cleanup --- .../plugin-coverage-e2e/__test-env__}/.gitignore | 0 .../plugin-coverage-e2e/__test-env__}/code-pushup.config.ts | 0 .../__test-env__}/code-pushup.existing-report.config.ts | 0 .../__test-env__}/mocks/fixtures/lcov.info | 0 .../plugin-coverage-e2e/__test-env__}/package.json | 4 ++-- .../plugin-coverage-e2e/__test-env__}/project.json | 2 +- .../plugin-coverage-e2e/__test-env__}/src/index.mjs | 0 .../plugin-coverage-e2e/__test-env__}/src/index.test.mjs | 2 +- .../plugin-coverage-e2e/__test-env__}/vite.config.ts | 0 e2e/plugin-coverage-e2e/project.json | 6 +++--- e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts | 6 +++--- e2e/plugin-coverage-e2e/tsconfig.test.json | 1 + 12 files changed, 11 insertions(+), 10 deletions(-) rename {static-environments/coverage-e2e-env => e2e/plugin-coverage-e2e/__test-env__}/.gitignore (100%) rename {static-environments/coverage-e2e-env => e2e/plugin-coverage-e2e/__test-env__}/code-pushup.config.ts (100%) rename {static-environments/coverage-e2e-env => e2e/plugin-coverage-e2e/__test-env__}/code-pushup.existing-report.config.ts (100%) rename {static-environments/coverage-e2e-env => e2e/plugin-coverage-e2e/__test-env__}/mocks/fixtures/lcov.info (100%) rename {static-environments/coverage-e2e-env => e2e/plugin-coverage-e2e/__test-env__}/package.json (93%) rename {static-environments/coverage-e2e-env => e2e/plugin-coverage-e2e/__test-env__}/project.json (72%) rename {static-environments/coverage-e2e-env => e2e/plugin-coverage-e2e/__test-env__}/src/index.mjs (100%) rename {static-environments/coverage-e2e-env => e2e/plugin-coverage-e2e/__test-env__}/src/index.test.mjs (87%) rename {static-environments/coverage-e2e-env => e2e/plugin-coverage-e2e/__test-env__}/vite.config.ts (100%) diff --git a/static-environments/coverage-e2e-env/.gitignore b/e2e/plugin-coverage-e2e/__test-env__/.gitignore similarity index 100% rename from static-environments/coverage-e2e-env/.gitignore rename to e2e/plugin-coverage-e2e/__test-env__/.gitignore diff --git a/static-environments/coverage-e2e-env/code-pushup.config.ts b/e2e/plugin-coverage-e2e/__test-env__/code-pushup.config.ts similarity index 100% rename from static-environments/coverage-e2e-env/code-pushup.config.ts rename to e2e/plugin-coverage-e2e/__test-env__/code-pushup.config.ts diff --git a/static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts b/e2e/plugin-coverage-e2e/__test-env__/code-pushup.existing-report.config.ts similarity index 100% rename from static-environments/coverage-e2e-env/code-pushup.existing-report.config.ts rename to e2e/plugin-coverage-e2e/__test-env__/code-pushup.existing-report.config.ts diff --git a/static-environments/coverage-e2e-env/mocks/fixtures/lcov.info b/e2e/plugin-coverage-e2e/__test-env__/mocks/fixtures/lcov.info similarity index 100% rename from static-environments/coverage-e2e-env/mocks/fixtures/lcov.info rename to e2e/plugin-coverage-e2e/__test-env__/mocks/fixtures/lcov.info diff --git a/static-environments/coverage-e2e-env/package.json b/e2e/plugin-coverage-e2e/__test-env__/package.json similarity index 93% rename from static-environments/coverage-e2e-env/package.json rename to e2e/plugin-coverage-e2e/__test-env__/package.json index c132d93f1..ac964b1c9 100644 --- a/static-environments/coverage-e2e-env/package.json +++ b/e2e/plugin-coverage-e2e/__test-env__/package.json @@ -8,11 +8,11 @@ "keywords": [], "author": "", "license": "ISC", - "description": "", "dependencies": { "@code-pushup/core": "^0.54.0", "@code-pushup/coverage-plugin": "^0.54.0", "@code-pushup/models": "^0.54.0", "@code-pushup/utils": "^0.54.0" - } + }, + "description": "" } diff --git a/static-environments/coverage-e2e-env/project.json b/e2e/plugin-coverage-e2e/__test-env__/project.json similarity index 72% rename from static-environments/coverage-e2e-env/project.json rename to e2e/plugin-coverage-e2e/__test-env__/project.json index f8d390e28..4a70f3435 100644 --- a/static-environments/coverage-e2e-env/project.json +++ b/e2e/plugin-coverage-e2e/__test-env__/project.json @@ -1,6 +1,6 @@ { "name": "coverage-e2e-env", - "$schema": "../../node_modules/nx/schemas/project-schema.json", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", "sourceRoot": "static-environments/coverage-e2e-env/src", "projectType": "library", "targets": {}, diff --git a/static-environments/coverage-e2e-env/src/index.mjs b/e2e/plugin-coverage-e2e/__test-env__/src/index.mjs similarity index 100% rename from static-environments/coverage-e2e-env/src/index.mjs rename to e2e/plugin-coverage-e2e/__test-env__/src/index.mjs diff --git a/static-environments/coverage-e2e-env/src/index.test.mjs b/e2e/plugin-coverage-e2e/__test-env__/src/index.test.mjs similarity index 87% rename from static-environments/coverage-e2e-env/src/index.test.mjs rename to e2e/plugin-coverage-e2e/__test-env__/src/index.test.mjs index efef0528b..d02988166 100644 --- a/static-environments/coverage-e2e-env/src/index.test.mjs +++ b/e2e/plugin-coverage-e2e/__test-env__/src/index.test.mjs @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { get42, isEven, untested } from './index'; +import { get42, isEven, untested } from './index.mjs'; describe('get42', () => { it('should return 42', async () => { diff --git a/static-environments/coverage-e2e-env/vite.config.ts b/e2e/plugin-coverage-e2e/__test-env__/vite.config.ts similarity index 100% rename from static-environments/coverage-e2e-env/vite.config.ts rename to e2e/plugin-coverage-e2e/__test-env__/vite.config.ts diff --git a/e2e/plugin-coverage-e2e/project.json b/e2e/plugin-coverage-e2e/project.json index 4c4f76881..14dd9ca93 100644 --- a/e2e/plugin-coverage-e2e/project.json +++ b/e2e/plugin-coverage-e2e/project.json @@ -13,12 +13,12 @@ }, "nxv-e2e": { "options": { - "environmentRoot": "static-environments/coverage-e2e-env" + "environmentRoot": "e2e/plugin-coverage-e2e/__test-env__" } }, "nxv-env-setup": { "options": { - "environmentRoot": "static-environments/coverage-e2e-env" + "environmentRoot": "e2e/plugin-coverage-e2e/__test-env__" } }, "e2e": { @@ -28,6 +28,6 @@ } } }, - "implicitDependencies": ["cli", "plugin-coverage", "coverage-e2e-env"], + "implicitDependencies": ["cli", "plugin-coverage"], "tags": ["scope:plugin", "type:e2e"] } diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index 747fe0571..dd7081fa5 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -6,11 +6,11 @@ import { omitVariableReportData } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with coverage-plugin NPM package', () => { - const envRoot = 'static-environments/coverage-e2e-env'; - const baseDir = join(envRoot, '__tests__'); + const envRoot = 'e2e/plugin-coverage-e2e/__test-env__'; + const coverageDir = join(envRoot, '.code-pushup'); afterEach(async () => { - await teardownTestFolder(baseDir); + await teardownTestFolder(coverageDir); }); it('should run Code coverage plugin which collects passed results and creates report.json', async () => { diff --git a/e2e/plugin-coverage-e2e/tsconfig.test.json b/e2e/plugin-coverage-e2e/tsconfig.test.json index 10c7f79de..22ad6e52a 100644 --- a/e2e/plugin-coverage-e2e/tsconfig.test.json +++ b/e2e/plugin-coverage-e2e/tsconfig.test.json @@ -5,6 +5,7 @@ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"], "target": "ES2020" }, + "exclude": [], "include": [ "vite.config.e2e.ts", "tests/**/*.e2e.test.ts", From 6b93d248c7f4013464daa916557df0d240d9ff54 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 11 Nov 2024 19:10:53 +0100 Subject: [PATCH 29/42] wip --- .../__test-env__/.eslintrc.json | 20 ++++++++++++++ .../__test-env__/code-pushup.config.ts | 27 +++++++++++++++++++ .../__test-env__/package.json | 15 +++++++++++ .../__test-env__/project.json | 8 ++++++ .../__test-env__/src/index.js | 7 +++++ 5 files changed, 77 insertions(+) create mode 100644 e2e/plugin-eslint-e2e/__test-env__/.eslintrc.json create mode 100644 e2e/plugin-eslint-e2e/__test-env__/code-pushup.config.ts create mode 100644 e2e/plugin-eslint-e2e/__test-env__/package.json create mode 100644 e2e/plugin-eslint-e2e/__test-env__/project.json create mode 100644 e2e/plugin-eslint-e2e/__test-env__/src/index.js diff --git a/e2e/plugin-eslint-e2e/__test-env__/.eslintrc.json b/e2e/plugin-eslint-e2e/__test-env__/.eslintrc.json new file mode 100644 index 000000000..113136c93 --- /dev/null +++ b/e2e/plugin-eslint-e2e/__test-env__/.eslintrc.json @@ -0,0 +1,20 @@ +{ + "root": true, + "ignorePatterns": ["code-pushup.config.ts"], + "overrides": [ + { + "files": ["*.js"], + "env": { + "node": true + }, + "parserOptions": { + "sourceType": "script" + }, + "rules": { + "no-unused-vars": "error", + "no-console": "warn", + "no-undef": "error" + } + } + ] +} diff --git a/e2e/plugin-eslint-e2e/__test-env__/code-pushup.config.ts b/e2e/plugin-eslint-e2e/__test-env__/code-pushup.config.ts new file mode 100644 index 000000000..01feaf2ff --- /dev/null +++ b/e2e/plugin-eslint-e2e/__test-env__/code-pushup.config.ts @@ -0,0 +1,27 @@ +import eslintPlugin from '@code-pushup/eslint-plugin'; + +export default { + plugins: [ + await eslintPlugin({ + eslintrc: '.eslintrc.json', + patterns: ['src/*.js'], + }), + ], + categories: [ + { + slug: 'bug-prevention', + title: 'Bug prevention', + description: 'Lint rules that find **potential bugs** in your code.', + refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }], + }, + { + slug: 'code-style', + title: 'Code style', + description: + 'Lint rules that promote **good practices** and consistency in your code.', + refs: [ + { type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 }, + ], + }, + ], +}; diff --git a/e2e/plugin-eslint-e2e/__test-env__/package.json b/e2e/plugin-eslint-e2e/__test-env__/package.json new file mode 100644 index 000000000..970508f95 --- /dev/null +++ b/e2e/plugin-eslint-e2e/__test-env__/package.json @@ -0,0 +1,15 @@ +{ + "name": "__test-env__", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@code-pushup/models": "^0.54.0" + } +} diff --git a/e2e/plugin-eslint-e2e/__test-env__/project.json b/e2e/plugin-eslint-e2e/__test-env__/project.json new file mode 100644 index 000000000..e3757a0de --- /dev/null +++ b/e2e/plugin-eslint-e2e/__test-env__/project.json @@ -0,0 +1,8 @@ +{ + "name": "eslint-e2e-env", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "static-environments/eslint-e2e-env/src", + "projectType": "library", + "targets": {}, + "tags": ["scope:internal", "type:feature"] +} diff --git a/e2e/plugin-eslint-e2e/__test-env__/src/index.js b/e2e/plugin-eslint-e2e/__test-env__/src/index.js new file mode 100644 index 000000000..4710a3767 --- /dev/null +++ b/e2e/plugin-eslint-e2e/__test-env__/src/index.js @@ -0,0 +1,7 @@ +function unusedFn() { + return '42'; +} + +module.exports = function consoleLog() { + console.log('No console.log()!'); +}; From 8d8ecc4abb5ebb05f46211731ba9f4b18c65029f Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 11 Nov 2024 19:16:27 +0100 Subject: [PATCH 30/42] wip --- e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts | 10 ++++------ e2e/plugin-eslint-e2e/tsconfig.test.json | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index a510876b0..228b8a86d 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -1,4 +1,4 @@ -import { join, relative } from 'node:path'; +import { join } from 'node:path'; import { afterEach } from 'vitest'; import { type Report, reportSchema } from '@code-pushup/models'; import { teardownTestFolder } from '@code-pushup/test-setup'; @@ -7,20 +7,18 @@ import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with eslint-plugin NPM package', () => { const envRoot = 'e2e/plugin-eslint-e2e/__test-env__'; - const baseDir = join(envRoot); + const outputDir = join(envRoot, '.code-pushup'); afterEach(async () => { - await teardownTestFolder(baseDir); + await teardownTestFolder(outputDir); }); it('should run ESLint plugin and create report.json', async () => { - const outputDir = relative(envRoot, join(baseDir, '.code-pushup')); const { code, stderr } = await executeProcess({ command: 'npx', args: [ '@code-pushup/cli', 'collect', - `--persist.outputDir=${outputDir}`, '--no-progress', '--onlyPlugins=eslint', ], @@ -30,7 +28,7 @@ describe('collect report with eslint-plugin NPM package', () => { expect(code).toBe(0); expect(stderr).toBe(''); - const report = await readJsonFile(join(envRoot, outputDir, 'report.json')); + const report = await readJsonFile(join(outputDir, 'report.json')); expect(() => reportSchema.parse(report)).not.toThrow(); expect(omitVariableReportData(report as Report)).toMatchSnapshot(); diff --git a/e2e/plugin-eslint-e2e/tsconfig.test.json b/e2e/plugin-eslint-e2e/tsconfig.test.json index 7e4507b8b..34f35e30f 100644 --- a/e2e/plugin-eslint-e2e/tsconfig.test.json +++ b/e2e/plugin-eslint-e2e/tsconfig.test.json @@ -5,7 +5,7 @@ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"], "target": "ES2020" }, - "exclude": ["__test-env__"], + "exclude": ["__test-env__/**"], "include": [ "vite.config.e2e.ts", "tests/**/*.e2e.test.ts", From 3334e3a1982acfc40304354c1c01ffdd294b1c9a Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 11 Nov 2024 19:26:35 +0100 Subject: [PATCH 31/42] wip --- e2e/plugin-eslint-e2e/__test-env__/package.json | 8 +++++--- nx.json | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/e2e/plugin-eslint-e2e/__test-env__/package.json b/e2e/plugin-eslint-e2e/__test-env__/package.json index 970508f95..999b66434 100644 --- a/e2e/plugin-eslint-e2e/__test-env__/package.json +++ b/e2e/plugin-eslint-e2e/__test-env__/package.json @@ -1,7 +1,6 @@ { "name": "__test-env__", "version": "1.0.0", - "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" @@ -10,6 +9,9 @@ "author": "", "license": "ISC", "dependencies": { - "@code-pushup/models": "^0.54.0" - } + "@code-pushup/eslint-plugin": "^0.54.0", + "@code-pushup/models": "^0.54.0", + "@code-pushup/utils": "^0.54.0" + }, + "description": "" } diff --git a/nx.json b/nx.json index c7603298b..105d57bc2 100644 --- a/nx.json +++ b/nx.json @@ -28,6 +28,9 @@ "e2e": { "dependsOn": ["^build"] }, + "nxv-e2e": { + "executor": "@push-based/nx-verdaccio:env-setup" + }, "nxv-env-setup": { "executor": "@push-based/nx-verdaccio:env-setup" }, From 385f0e370efd81704876eb75aa0d2918c345f70c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Chalk?= Date: Wed, 13 Nov 2024 13:00:00 +0100 Subject: [PATCH 32/42] test(plugin-eslint-e2e): fix tests by separating fixtures from test env folder --- e2e/plugin-eslint-e2e/__test-env__/package.json | 17 ----------------- e2e/plugin-eslint-e2e/__test-env__/project.json | 8 -------- .../fixtures}/.eslintrc.json | 0 .../fixtures}/code-pushup.config.ts | 0 .../fixtures}/src/index.js | 0 e2e/plugin-eslint-e2e/project.json | 4 ++-- .../__snapshots__/collect.e2e.test.ts.snap | 4 ++-- e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts | 12 +++++++++++- 8 files changed, 15 insertions(+), 30 deletions(-) delete mode 100644 e2e/plugin-eslint-e2e/__test-env__/package.json delete mode 100644 e2e/plugin-eslint-e2e/__test-env__/project.json rename e2e/plugin-eslint-e2e/{__test-env__ => mocks/fixtures}/.eslintrc.json (100%) rename e2e/plugin-eslint-e2e/{__test-env__ => mocks/fixtures}/code-pushup.config.ts (100%) rename e2e/plugin-eslint-e2e/{__test-env__ => mocks/fixtures}/src/index.js (100%) diff --git a/e2e/plugin-eslint-e2e/__test-env__/package.json b/e2e/plugin-eslint-e2e/__test-env__/package.json deleted file mode 100644 index 999b66434..000000000 --- a/e2e/plugin-eslint-e2e/__test-env__/package.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "__test-env__", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "@code-pushup/eslint-plugin": "^0.54.0", - "@code-pushup/models": "^0.54.0", - "@code-pushup/utils": "^0.54.0" - }, - "description": "" -} diff --git a/e2e/plugin-eslint-e2e/__test-env__/project.json b/e2e/plugin-eslint-e2e/__test-env__/project.json deleted file mode 100644 index e3757a0de..000000000 --- a/e2e/plugin-eslint-e2e/__test-env__/project.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "eslint-e2e-env", - "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "static-environments/eslint-e2e-env/src", - "projectType": "library", - "targets": {}, - "tags": ["scope:internal", "type:feature"] -} diff --git a/e2e/plugin-eslint-e2e/__test-env__/.eslintrc.json b/e2e/plugin-eslint-e2e/mocks/fixtures/.eslintrc.json similarity index 100% rename from e2e/plugin-eslint-e2e/__test-env__/.eslintrc.json rename to e2e/plugin-eslint-e2e/mocks/fixtures/.eslintrc.json diff --git a/e2e/plugin-eslint-e2e/__test-env__/code-pushup.config.ts b/e2e/plugin-eslint-e2e/mocks/fixtures/code-pushup.config.ts similarity index 100% rename from e2e/plugin-eslint-e2e/__test-env__/code-pushup.config.ts rename to e2e/plugin-eslint-e2e/mocks/fixtures/code-pushup.config.ts diff --git a/e2e/plugin-eslint-e2e/__test-env__/src/index.js b/e2e/plugin-eslint-e2e/mocks/fixtures/src/index.js similarity index 100% rename from e2e/plugin-eslint-e2e/__test-env__/src/index.js rename to e2e/plugin-eslint-e2e/mocks/fixtures/src/index.js diff --git a/e2e/plugin-eslint-e2e/project.json b/e2e/plugin-eslint-e2e/project.json index 301f6d19a..9705c2b0e 100644 --- a/e2e/plugin-eslint-e2e/project.json +++ b/e2e/plugin-eslint-e2e/project.json @@ -13,12 +13,12 @@ }, "nxv-e2e": { "options": { - "environmentRoot": "e2e/plugin-eslint-e2e/__test-env__" + "environmentRoot": "tmp/plugin-eslint-e2e/__test-env__" } }, "nxv-env-setup": { "options": { - "environmentRoot": "e2e/plugin-eslint-e2e/__test-env__" + "environmentRoot": "tmp/plugin-eslint-e2e/__test-env__" } }, "e2e": { diff --git a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index 39f169153..c1cfbf75f 100644 --- a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -42,7 +42,7 @@ exports[`collect report with eslint-plugin NPM package > should run ESLint plugi "message": "'unusedFn' is defined but never used.", "severity": "error", "source": { - "file": "static-environments/eslint-e2e-env/src/index.js", + "file": "tmp/plugin-eslint-e2e/__test-env__/src/index.js", "position": { "endColumn": 18, "endLine": 1, @@ -68,7 +68,7 @@ exports[`collect report with eslint-plugin NPM package > should run ESLint plugi "message": "Unexpected console statement.", "severity": "warning", "source": { - "file": "static-environments/eslint-e2e-env/src/index.js", + "file": "tmp/plugin-eslint-e2e/__test-env__/src/index.js", "position": { "endColumn": 14, "endLine": 6, diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index 228b8a86d..c863a1d2a 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -1,3 +1,4 @@ +import { cp, rm } from 'node:fs/promises'; import { join } from 'node:path'; import { afterEach } from 'vitest'; import { type Report, reportSchema } from '@code-pushup/models'; @@ -6,9 +7,18 @@ import { omitVariableReportData } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with eslint-plugin NPM package', () => { - const envRoot = 'e2e/plugin-eslint-e2e/__test-env__'; + const fixturesDir = join('e2e', 'plugin-eslint-e2e', 'mocks', 'fixtures'); + const envRoot = join('tmp', 'plugin-eslint-e2e', '__test-env__'); const outputDir = join(envRoot, '.code-pushup'); + beforeAll(async () => { + await cp(fixturesDir, envRoot, { recursive: true }); + }); + + afterAll(async () => { + await rm(envRoot, { recursive: true, force: true }); + }); + afterEach(async () => { await teardownTestFolder(outputDir); }); From fa90bcd5685ba7fe953ab2e08bf11722e8e47d80 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 18 Nov 2024 18:10:12 +0100 Subject: [PATCH 33/42] refactor e2e env setup --- .../fixtures/{ => old-version}/.eslintrc.json | 0 .../{ => old-version}/code-pushup.config.ts | 0 .../fixtures/{ => old-version}/src/index.js | 0 e2e/plugin-eslint-e2e/project.json | 10 ------ .../__snapshots__/collect.e2e.test.ts.snap | 4 +-- .../tests/collect.e2e.test.ts | 34 ++++++++++--------- nx.json | 3 +- 7 files changed, 22 insertions(+), 29 deletions(-) rename e2e/plugin-eslint-e2e/mocks/fixtures/{ => old-version}/.eslintrc.json (100%) rename e2e/plugin-eslint-e2e/mocks/fixtures/{ => old-version}/code-pushup.config.ts (100%) rename e2e/plugin-eslint-e2e/mocks/fixtures/{ => old-version}/src/index.js (100%) diff --git a/e2e/plugin-eslint-e2e/mocks/fixtures/.eslintrc.json b/e2e/plugin-eslint-e2e/mocks/fixtures/old-version/.eslintrc.json similarity index 100% rename from e2e/plugin-eslint-e2e/mocks/fixtures/.eslintrc.json rename to e2e/plugin-eslint-e2e/mocks/fixtures/old-version/.eslintrc.json diff --git a/e2e/plugin-eslint-e2e/mocks/fixtures/code-pushup.config.ts b/e2e/plugin-eslint-e2e/mocks/fixtures/old-version/code-pushup.config.ts similarity index 100% rename from e2e/plugin-eslint-e2e/mocks/fixtures/code-pushup.config.ts rename to e2e/plugin-eslint-e2e/mocks/fixtures/old-version/code-pushup.config.ts diff --git a/e2e/plugin-eslint-e2e/mocks/fixtures/src/index.js b/e2e/plugin-eslint-e2e/mocks/fixtures/old-version/src/index.js similarity index 100% rename from e2e/plugin-eslint-e2e/mocks/fixtures/src/index.js rename to e2e/plugin-eslint-e2e/mocks/fixtures/old-version/src/index.js diff --git a/e2e/plugin-eslint-e2e/project.json b/e2e/plugin-eslint-e2e/project.json index 9705c2b0e..4a23956d0 100644 --- a/e2e/plugin-eslint-e2e/project.json +++ b/e2e/plugin-eslint-e2e/project.json @@ -11,16 +11,6 @@ "lintFilePatterns": ["e2e/plugin-eslint-e2e/**/*.ts"] } }, - "nxv-e2e": { - "options": { - "environmentRoot": "tmp/plugin-eslint-e2e/__test-env__" - } - }, - "nxv-env-setup": { - "options": { - "environmentRoot": "tmp/plugin-eslint-e2e/__test-env__" - } - }, "e2e": { "executor": "@nx/vite:test", "options": { diff --git a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index c1cfbf75f..ea1b4434e 100644 --- a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -42,7 +42,7 @@ exports[`collect report with eslint-plugin NPM package > should run ESLint plugi "message": "'unusedFn' is defined but never used.", "severity": "error", "source": { - "file": "tmp/plugin-eslint-e2e/__test-env__/src/index.js", + "file": "tmp/e2e/plugin-eslint-e2e/old-version/src/index.js", "position": { "endColumn": 18, "endLine": 1, @@ -68,7 +68,7 @@ exports[`collect report with eslint-plugin NPM package > should run ESLint plugi "message": "Unexpected console statement.", "severity": "warning", "source": { - "file": "tmp/plugin-eslint-e2e/__test-env__/src/index.js", + "file": "tmp/e2e/plugin-eslint-e2e/old-version/src/index.js", "position": { "endColumn": 14, "endLine": 6, diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index c863a1d2a..784f54056 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -1,44 +1,46 @@ -import { cp, rm } from 'node:fs/promises'; +import { cp } from 'node:fs/promises'; import { join } from 'node:path'; -import { afterEach } from 'vitest'; +import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest'; import { type Report, reportSchema } from '@code-pushup/models'; import { teardownTestFolder } from '@code-pushup/test-setup'; import { omitVariableReportData } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with eslint-plugin NPM package', () => { - const fixturesDir = join('e2e', 'plugin-eslint-e2e', 'mocks', 'fixtures'); - const envRoot = join('tmp', 'plugin-eslint-e2e', '__test-env__'); - const outputDir = join(envRoot, '.code-pushup'); + const fixturesOldVersionDir = join( + 'e2e', + 'plugin-eslint-e2e', + 'mocks', + 'fixtures', + 'old-version', + ); + const envRoot = join('tmp', 'e2e', 'plugin-eslint-e2e'); + const oldVersionDir = join(envRoot, 'old-version'); + const oldVersionOutputDir = join(oldVersionDir, '.code-pushup'); beforeAll(async () => { - await cp(fixturesDir, envRoot, { recursive: true }); + await cp(fixturesOldVersionDir, oldVersionDir, { recursive: true }); }); afterAll(async () => { - await rm(envRoot, { recursive: true, force: true }); + await teardownTestFolder(oldVersionDir); }); afterEach(async () => { - await teardownTestFolder(outputDir); + await teardownTestFolder(oldVersionOutputDir); }); it('should run ESLint plugin and create report.json', async () => { const { code, stderr } = await executeProcess({ command: 'npx', - args: [ - '@code-pushup/cli', - 'collect', - '--no-progress', - '--onlyPlugins=eslint', - ], - cwd: envRoot, + args: ['@code-pushup/cli', 'collect', '--no-progress'], + cwd: oldVersionDir, }); expect(code).toBe(0); expect(stderr).toBe(''); - const report = await readJsonFile(join(outputDir, 'report.json')); + const report = await readJsonFile(join(oldVersionOutputDir, 'report.json')); expect(() => reportSchema.parse(report)).not.toThrow(); expect(omitVariableReportData(report as Report)).toMatchSnapshot(); diff --git a/nx.json b/nx.json index 105d57bc2..674b3b559 100644 --- a/nx.json +++ b/nx.json @@ -29,9 +29,10 @@ "dependsOn": ["^build"] }, "nxv-e2e": { - "executor": "@push-based/nx-verdaccio:env-setup" + "executor": "@push-based/nx-verdaccio:env-teardown" }, "nxv-env-setup": { + "cache": true, "executor": "@push-based/nx-verdaccio:env-setup" }, "@nx/vite:test": { From ded72c012de5c3c189c4e3a399d680a3bbb756cf Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 18 Nov 2024 18:36:40 +0100 Subject: [PATCH 34/42] refactor e2e env setup --- .../__test-env__/.gitignore | 3 -- .../__test-env__/project.json | 8 ---- .../basic-setup}/code-pushup.config.ts | 0 .../fixtures/basic-setup}/package.json | 4 -- .../fixtures/basic-setup}/src/index.mjs | 0 .../fixtures/basic-setup}/src/index.test.mjs | 0 .../fixtures/basic-setup}/vite.config.ts | 0 .../existing-report/code-pushup.config.ts} | 2 +- .../existing-report/coverage}/lcov.info | 0 e2e/plugin-coverage-e2e/project.json | 10 ----- .../tests/collect.e2e.test.ts | 42 +++++++++---------- 11 files changed, 22 insertions(+), 47 deletions(-) delete mode 100644 e2e/plugin-coverage-e2e/__test-env__/.gitignore delete mode 100644 e2e/plugin-coverage-e2e/__test-env__/project.json rename e2e/plugin-coverage-e2e/{__test-env__ => mocks/fixtures/basic-setup}/code-pushup.config.ts (100%) rename e2e/plugin-coverage-e2e/{__test-env__ => mocks/fixtures/basic-setup}/package.json (60%) rename e2e/plugin-coverage-e2e/{__test-env__ => mocks/fixtures/basic-setup}/src/index.mjs (100%) rename e2e/plugin-coverage-e2e/{__test-env__ => mocks/fixtures/basic-setup}/src/index.test.mjs (100%) rename e2e/plugin-coverage-e2e/{__test-env__ => mocks/fixtures/basic-setup}/vite.config.ts (100%) rename e2e/plugin-coverage-e2e/{__test-env__/code-pushup.existing-report.config.ts => mocks/fixtures/existing-report/code-pushup.config.ts} (89%) rename e2e/plugin-coverage-e2e/{__test-env__/mocks/fixtures => mocks/fixtures/existing-report/coverage}/lcov.info (100%) diff --git a/e2e/plugin-coverage-e2e/__test-env__/.gitignore b/e2e/plugin-coverage-e2e/__test-env__/.gitignore deleted file mode 100644 index 9e76e5c81..000000000 --- a/e2e/plugin-coverage-e2e/__test-env__/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -coverage -node_modules -.code-pushup diff --git a/e2e/plugin-coverage-e2e/__test-env__/project.json b/e2e/plugin-coverage-e2e/__test-env__/project.json deleted file mode 100644 index 4a70f3435..000000000 --- a/e2e/plugin-coverage-e2e/__test-env__/project.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "coverage-e2e-env", - "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "static-environments/coverage-e2e-env/src", - "projectType": "library", - "targets": {}, - "tags": ["scope:internal", "type:feature"] -} diff --git a/e2e/plugin-coverage-e2e/__test-env__/code-pushup.config.ts b/e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/code-pushup.config.ts similarity index 100% rename from e2e/plugin-coverage-e2e/__test-env__/code-pushup.config.ts rename to e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/code-pushup.config.ts diff --git a/e2e/plugin-coverage-e2e/__test-env__/package.json b/e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/package.json similarity index 60% rename from e2e/plugin-coverage-e2e/__test-env__/package.json rename to e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/package.json index ac964b1c9..61a96ca4c 100644 --- a/e2e/plugin-coverage-e2e/__test-env__/package.json +++ b/e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/package.json @@ -9,10 +9,6 @@ "author": "", "license": "ISC", "dependencies": { - "@code-pushup/core": "^0.54.0", - "@code-pushup/coverage-plugin": "^0.54.0", - "@code-pushup/models": "^0.54.0", - "@code-pushup/utils": "^0.54.0" }, "description": "" } diff --git a/e2e/plugin-coverage-e2e/__test-env__/src/index.mjs b/e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/src/index.mjs similarity index 100% rename from e2e/plugin-coverage-e2e/__test-env__/src/index.mjs rename to e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/src/index.mjs diff --git a/e2e/plugin-coverage-e2e/__test-env__/src/index.test.mjs b/e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/src/index.test.mjs similarity index 100% rename from e2e/plugin-coverage-e2e/__test-env__/src/index.test.mjs rename to e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/src/index.test.mjs diff --git a/e2e/plugin-coverage-e2e/__test-env__/vite.config.ts b/e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/vite.config.ts similarity index 100% rename from e2e/plugin-coverage-e2e/__test-env__/vite.config.ts rename to e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/vite.config.ts diff --git a/e2e/plugin-coverage-e2e/__test-env__/code-pushup.existing-report.config.ts b/e2e/plugin-coverage-e2e/mocks/fixtures/existing-report/code-pushup.config.ts similarity index 89% rename from e2e/plugin-coverage-e2e/__test-env__/code-pushup.existing-report.config.ts rename to e2e/plugin-coverage-e2e/mocks/fixtures/existing-report/code-pushup.config.ts index 9f6fffbb8..d955bbba0 100644 --- a/e2e/plugin-coverage-e2e/__test-env__/code-pushup.existing-report.config.ts +++ b/e2e/plugin-coverage-e2e/mocks/fixtures/existing-report/code-pushup.config.ts @@ -5,7 +5,7 @@ import type { CoreConfig } from '@code-pushup/models'; export default { plugins: [ await coveragePlugin({ - reports: [join('mocks', 'fixtures', 'lcov.info')], + reports: [join('coverage', 'lcov.info')], }), ], categories: [ diff --git a/e2e/plugin-coverage-e2e/__test-env__/mocks/fixtures/lcov.info b/e2e/plugin-coverage-e2e/mocks/fixtures/existing-report/coverage/lcov.info similarity index 100% rename from e2e/plugin-coverage-e2e/__test-env__/mocks/fixtures/lcov.info rename to e2e/plugin-coverage-e2e/mocks/fixtures/existing-report/coverage/lcov.info diff --git a/e2e/plugin-coverage-e2e/project.json b/e2e/plugin-coverage-e2e/project.json index 14dd9ca93..8a0932adf 100644 --- a/e2e/plugin-coverage-e2e/project.json +++ b/e2e/plugin-coverage-e2e/project.json @@ -11,16 +11,6 @@ "lintFilePatterns": ["e2e/plugin-coverage-e2e/**/*.ts"] } }, - "nxv-e2e": { - "options": { - "environmentRoot": "e2e/plugin-coverage-e2e/__test-env__" - } - }, - "nxv-env-setup": { - "options": { - "environmentRoot": "e2e/plugin-coverage-e2e/__test-env__" - } - }, "e2e": { "executor": "@nx/vite:test", "options": { diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index dd7081fa5..b5c285d44 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -1,36 +1,41 @@ +import { cp } from 'node:fs/promises'; import { join } from 'node:path'; -import { afterEach } from 'vitest'; +import { afterAll, afterEach, beforeAll } from 'vitest'; import { type Report, reportSchema } from '@code-pushup/models'; import { teardownTestFolder } from '@code-pushup/test-setup'; import { omitVariableReportData } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; describe('collect report with coverage-plugin NPM package', () => { - const envRoot = 'e2e/plugin-coverage-e2e/__test-env__'; - const coverageDir = join(envRoot, '.code-pushup'); + const envRoot = 'tmp/e2e/plugin-coverage-e2e'; + const fixtureDir = join('e2e', 'plugin-coverage-e2e', 'mocks', 'fixtures'); + const basicDir = join(envRoot, 'basic-setup'); + const existingDir = join(envRoot, 'existing-setup'); + beforeAll(async () => { + await cp(fixtureDir, envRoot, { recursive: true }); + }); + afterAll(async () => { + await teardownTestFolder(join(basicDir)); + await teardownTestFolder(join(existingDir)); + }); afterEach(async () => { - await teardownTestFolder(coverageDir); + await teardownTestFolder(join(basicDir, '.code-pushup')); + await teardownTestFolder(join(existingDir, '.code-pushup')); }); it('should run Code coverage plugin which collects passed results and creates report.json', async () => { const { code, stderr } = await executeProcess({ command: 'npx', - args: [ - '@code-pushup/cli', - 'collect', - '--no-progress', - `--config=code-pushup.existing-report.config.ts`, - '--onlyPlugins=coverage', - ], - cwd: envRoot, + args: ['@code-pushup/cli', 'collect', '--no-progress'], + cwd: basicDir, }); expect(code).toBe(0); expect(stderr).toBe(''); const report = await readJsonFile( - join(envRoot, '.code-pushup', 'report.json'), + join(basicDir, '.code-pushup', 'report.json'), ); expect(() => reportSchema.parse(report)).not.toThrow(); @@ -40,20 +45,15 @@ describe('collect report with coverage-plugin NPM package', () => { it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => { const { code, stderr } = await executeProcess({ command: 'npx', - args: [ - '@code-pushup/cli', - 'collect', - '--no-progress', - '--onlyPlugins=coverage', - ], - cwd: envRoot, + args: ['@code-pushup/cli', 'collect', '--no-progress'], + cwd: existingDir, }); expect(code).toBe(0); expect(stderr).toBe(''); const report = await readJsonFile( - join(envRoot, '.code-pushup/report.json'), + join(existingDir, '.code-pushup', 'report.json'), ); expect(() => reportSchema.parse(report)).not.toThrow(); From cb4e0f903e0160753f4e9be5e0965aa200e9df9a Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 18 Nov 2024 18:40:08 +0100 Subject: [PATCH 35/42] cleanup env setup --- .../__snapshots__/collect.e2e.test.ts.snap | 164 +++++++++--------- .../tests/collect.e2e.test.ts | 2 +- 2 files changed, 83 insertions(+), 83 deletions(-) diff --git a/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index 610e3b0a3..d15a8626b 100644 --- a/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/plugin-coverage-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -25,10 +25,20 @@ exports[`collect report with coverage-plugin NPM package > should run Code cover "details": { "issues": [ { - "message": "Function untested is not called in any test case.", + "message": "Function formatReportScore is not called in any test case.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-coverage-e2e/existing-report/src/lib/partly-covered/utils.ts", + "position": { + "startLine": 2, + }, + }, + }, + { + "message": "Function sortReport is not called in any test case.", "severity": "error", "source": { - "file": "static-environments/coverage-e2e-env/src/index.mjs", + "file": "tmp/e2e/plugin-coverage-e2e/existing-report/src/lib/not-covered/sorting.ts", "position": { "startLine": 1, }, @@ -36,67 +46,97 @@ exports[`collect report with coverage-plugin NPM package > should run Code cover }, ], }, - "displayValue": "66.7 %", - "score": 0.6667, + "displayValue": "60 %", + "score": 0.6, "slug": "function-coverage", "title": "Function coverage", - "value": 66.66666666666666, + "value": 60, }, { "description": "Measures how many branches were executed after conditional statements in at least one test.", "details": { "issues": [ { - "message": "1st branch is not taken in any test case.", + "message": "2nd branch is not taken in any test case.", "severity": "error", "source": { - "file": "static-environments/coverage-e2e-env/src/index.mjs", + "file": "tmp/e2e/plugin-coverage-e2e/existing-report/src/lib/partly-covered/utils.ts", + "position": { + "startLine": 6, + }, + }, + }, + { + "message": "2nd branch is not taken in any test case.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-coverage-e2e/existing-report/src/lib/partly-covered/utils.ts", "position": { "startLine": 10, }, }, }, + { + "message": "1st branch is not taken in any test case.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-coverage-e2e/existing-report/src/lib/not-covered/sorting.ts", + "position": { + "startLine": 7, + }, + }, + }, + { + "message": "2nd branch is not taken in any test case.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-coverage-e2e/existing-report/src/lib/not-covered/sorting.ts", + "position": { + "startLine": 7, + }, + }, + }, ], }, - "displayValue": "66.7 %", - "score": 0.6667, + "displayValue": "76.5 %", + "score": 0.7647, "slug": "branch-coverage", "title": "Branch coverage", - "value": 66.66666666666666, + "value": 76.47058823529412, }, { "description": "Measures how many lines of code were executed in at least one test.", "details": { "issues": [ { - "message": "Lines 2-3 are not covered in any test case.", + "message": "Lines 7-9 are not covered in any test case.", "severity": "warning", "source": { - "file": "static-environments/coverage-e2e-env/src/index.mjs", + "file": "tmp/e2e/plugin-coverage-e2e/existing-report/src/lib/partly-covered/utils.ts", "position": { - "endLine": 3, - "startLine": 2, + "endLine": 9, + "startLine": 7, }, }, }, { - "message": "Lines 11-12 are not covered in any test case.", + "message": "Lines 1-5 are not covered in any test case.", "severity": "warning", "source": { - "file": "static-environments/coverage-e2e-env/src/index.mjs", + "file": "tmp/e2e/plugin-coverage-e2e/existing-report/src/lib/not-covered/sorting.ts", "position": { - "endLine": 12, - "startLine": 11, + "endLine": 5, + "startLine": 1, }, }, }, ], }, - "displayValue": "73.3 %", - "score": 0.7333, + "displayValue": "68 %", + "score": 0.68, "slug": "line-coverage", "title": "Line coverage", - "value": 73.33333333333333, + "value": 68, }, ], "description": "Official Code PushUp code coverage plugin.", @@ -156,20 +196,10 @@ exports[`collect report with coverage-plugin NPM package > should run Code cover "details": { "issues": [ { - "message": "Function formatReportScore is not called in any test case.", - "severity": "error", - "source": { - "file": "static-environments/coverage-e2e-env/src/lib/partly-covered/utils.ts", - "position": { - "startLine": 2, - }, - }, - }, - { - "message": "Function sortReport is not called in any test case.", + "message": "Function untested is not called in any test case.", "severity": "error", "source": { - "file": "static-environments/coverage-e2e-env/src/lib/not-covered/sorting.ts", + "file": "tmp/e2e/plugin-coverage-e2e/basic-setup/src/index.mjs", "position": { "startLine": 1, }, @@ -177,97 +207,67 @@ exports[`collect report with coverage-plugin NPM package > should run Code cover }, ], }, - "displayValue": "60 %", - "score": 0.6, + "displayValue": "66.7 %", + "score": 0.6667, "slug": "function-coverage", "title": "Function coverage", - "value": 60, + "value": 66.66666666666666, }, { "description": "Measures how many branches were executed after conditional statements in at least one test.", "details": { "issues": [ - { - "message": "2nd branch is not taken in any test case.", - "severity": "error", - "source": { - "file": "static-environments/coverage-e2e-env/src/lib/partly-covered/utils.ts", - "position": { - "startLine": 6, - }, - }, - }, - { - "message": "2nd branch is not taken in any test case.", - "severity": "error", - "source": { - "file": "static-environments/coverage-e2e-env/src/lib/partly-covered/utils.ts", - "position": { - "startLine": 10, - }, - }, - }, { "message": "1st branch is not taken in any test case.", "severity": "error", "source": { - "file": "static-environments/coverage-e2e-env/src/lib/not-covered/sorting.ts", + "file": "tmp/e2e/plugin-coverage-e2e/basic-setup/src/index.mjs", "position": { - "startLine": 7, - }, - }, - }, - { - "message": "2nd branch is not taken in any test case.", - "severity": "error", - "source": { - "file": "static-environments/coverage-e2e-env/src/lib/not-covered/sorting.ts", - "position": { - "startLine": 7, + "startLine": 10, }, }, }, ], }, - "displayValue": "76.5 %", - "score": 0.7647, + "displayValue": "66.7 %", + "score": 0.6667, "slug": "branch-coverage", "title": "Branch coverage", - "value": 76.47058823529412, + "value": 66.66666666666666, }, { "description": "Measures how many lines of code were executed in at least one test.", "details": { "issues": [ { - "message": "Lines 7-9 are not covered in any test case.", + "message": "Lines 2-3 are not covered in any test case.", "severity": "warning", "source": { - "file": "static-environments/coverage-e2e-env/src/lib/partly-covered/utils.ts", + "file": "tmp/e2e/plugin-coverage-e2e/basic-setup/src/index.mjs", "position": { - "endLine": 9, - "startLine": 7, + "endLine": 3, + "startLine": 2, }, }, }, { - "message": "Lines 1-5 are not covered in any test case.", + "message": "Lines 11-12 are not covered in any test case.", "severity": "warning", "source": { - "file": "static-environments/coverage-e2e-env/src/lib/not-covered/sorting.ts", + "file": "tmp/e2e/plugin-coverage-e2e/basic-setup/src/index.mjs", "position": { - "endLine": 5, - "startLine": 1, + "endLine": 12, + "startLine": 11, }, }, }, ], }, - "displayValue": "68 %", - "score": 0.68, + "displayValue": "73.3 %", + "score": 0.7333, "slug": "line-coverage", "title": "Line coverage", - "value": 68, + "value": 73.33333333333333, }, ], "description": "Official Code PushUp code coverage plugin.", diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index b5c285d44..2a7fa6a08 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -10,7 +10,7 @@ describe('collect report with coverage-plugin NPM package', () => { const envRoot = 'tmp/e2e/plugin-coverage-e2e'; const fixtureDir = join('e2e', 'plugin-coverage-e2e', 'mocks', 'fixtures'); const basicDir = join(envRoot, 'basic-setup'); - const existingDir = join(envRoot, 'existing-setup'); + const existingDir = join(envRoot, 'existing-report'); beforeAll(async () => { await cp(fixtureDir, envRoot, { recursive: true }); From 22a6908554090ad5286b33d3add7110af477f04b Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 18 Nov 2024 18:45:17 +0100 Subject: [PATCH 36/42] fix snapshots --- .../__snapshots__/collect.e2e.test.ts.snap | 420 ------------------ 1 file changed, 420 deletions(-) diff --git a/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index 47a9e0f07..35945e037 100644 --- a/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -1,425 +1,5 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`CLI collect > should run Code coverage plugin that runs coverage tool and creates report.json 1`] = ` -{ - "categories": [ - { - "refs": [ - { - "plugin": "coverage", - "slug": "coverage", - "type": "group", - "weight": 1, - }, - ], - "slug": "code-coverage", - "title": "Code coverage", - }, - ], - "packageName": "@code-pushup/core", - "plugins": [ - { - "audits": [ - { - "description": "Measures how many functions were called in at least one test.", - "details": { - "issues": [ - { - "message": "Function onSubmit is not called in any test case.", - "severity": "error", - "source": { - "file": "examples/react-todos-app/src/components/CreateTodo.jsx", - "position": { - "startLine": 13, - }, - }, - }, - { - "message": "Function onInput is not called in any test case.", - "severity": "error", - "source": { - "file": "examples/react-todos-app/src/components/CreateTodo.jsx", - "position": { - "startLine": 21, - }, - }, - }, - { - "message": "Function onInput is not called in any test case.", - "severity": "error", - "source": { - "file": "examples/react-todos-app/src/components/TodoFilter.jsx", - "position": { - "startLine": 9, - }, - }, - }, - { - "message": "Function onChange is not called in any test case.", - "severity": "error", - "source": { - "file": "examples/react-todos-app/src/components/TodoFilter.jsx", - "position": { - "startLine": 17, - }, - }, - }, - ], - }, - "displayValue": "55.6 %", - "score": 0.5556, - "slug": "function-coverage", - "title": "Function coverage", - "value": 55.55555555555556, - }, - { - "description": "Measures how many branches were executed after conditional statements in at least one test.", - "details": { - "issues": [ - { - "message": "1st branch is not taken in any test case.", - "severity": "error", - "source": { - "file": "examples/react-todos-app/src/index.jsx", - "position": { - "startLine": 1, - }, - }, - }, - ], - }, - "displayValue": "87.5 %", - "score": 0.875, - "slug": "branch-coverage", - "title": "Branch coverage", - "value": 87.5, - }, - { - "description": "Measures how many lines of code were executed in at least one test.", - "details": { - "issues": [ - { - "message": "Lines 1-6 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/index.jsx", - "position": { - "endLine": 6, - "startLine": 1, - }, - }, - }, - { - "message": "Lines 14-17 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/CreateTodo.jsx", - "position": { - "endLine": 17, - "startLine": 14, - }, - }, - }, - { - "message": "Lines 22-23 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/CreateTodo.jsx", - "position": { - "endLine": 23, - "startLine": 22, - }, - }, - }, - { - "message": "Lines 10-11 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoFilter.jsx", - "position": { - "endLine": 11, - "startLine": 10, - }, - }, - }, - { - "message": "Lines 18-19 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoFilter.jsx", - "position": { - "endLine": 19, - "startLine": 18, - }, - }, - }, - { - "message": "Lines 7-28 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/components/TodoList.jsx", - "position": { - "endLine": 28, - "startLine": 7, - }, - }, - }, - { - "message": "Lines 12-13 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endLine": 13, - "startLine": 12, - }, - }, - }, - { - "message": "Lines 18-37 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endLine": 37, - "startLine": 18, - }, - }, - }, - { - "message": "Lines 41-45 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endLine": 45, - "startLine": 41, - }, - }, - }, - { - "message": "Lines 54-60 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "examples/react-todos-app/src/hooks/useTodos.js", - "position": { - "endLine": 60, - "startLine": 54, - }, - }, - }, - ], - }, - "displayValue": "62.1 %", - "score": 0.6211, - "slug": "line-coverage", - "title": "Line coverage", - "value": 62.10526315789474, - }, - ], - "description": "Official Code PushUp code coverage plugin.", - "docsUrl": "https://www.npmjs.com/package/@code-pushup/coverage-plugin/", - "groups": [ - { - "description": "Group containing all defined coverage types as audits.", - "refs": [ - { - "slug": "function-coverage", - "weight": 6, - }, - { - "slug": "branch-coverage", - "weight": 3, - }, - { - "slug": "line-coverage", - "weight": 1, - }, - ], - "slug": "coverage", - "title": "Code coverage metrics", - }, - ], - "icon": "folder-coverage-open", - "packageName": "@code-pushup/coverage-plugin", - "slug": "coverage", - "title": "Code coverage", - }, - ], -} -`; - -exports[`CLI collect > should run Code coverage plugin which collects passed results and creates report.json 1`] = ` -{ - "categories": [ - { - "refs": [ - { - "plugin": "coverage", - "slug": "coverage", - "type": "group", - "weight": 1, - }, - ], - "slug": "code-coverage", - "title": "Code coverage", - }, - ], - "packageName": "@code-pushup/core", - "plugins": [ - { - "audits": [ - { - "description": "Measures how many functions were called in at least one test.", - "details": { - "issues": [ - { - "message": "Function formatReportScore is not called in any test case.", - "severity": "error", - "source": { - "file": "src/lib/partly-covered/utils.ts", - "position": { - "startLine": 2, - }, - }, - }, - { - "message": "Function sortReport is not called in any test case.", - "severity": "error", - "source": { - "file": "src/lib/not-covered/sorting.ts", - "position": { - "startLine": 1, - }, - }, - }, - ], - }, - "displayValue": "60 %", - "score": 0.6, - "slug": "function-coverage", - "title": "Function coverage", - "value": 60, - }, - { - "description": "Measures how many branches were executed after conditional statements in at least one test.", - "details": { - "issues": [ - { - "message": "2nd branch is not taken in any test case.", - "severity": "error", - "source": { - "file": "src/lib/partly-covered/utils.ts", - "position": { - "startLine": 6, - }, - }, - }, - { - "message": "2nd branch is not taken in any test case.", - "severity": "error", - "source": { - "file": "src/lib/partly-covered/utils.ts", - "position": { - "startLine": 10, - }, - }, - }, - { - "message": "1st branch is not taken in any test case.", - "severity": "error", - "source": { - "file": "src/lib/not-covered/sorting.ts", - "position": { - "startLine": 7, - }, - }, - }, - { - "message": "2nd branch is not taken in any test case.", - "severity": "error", - "source": { - "file": "src/lib/not-covered/sorting.ts", - "position": { - "startLine": 7, - }, - }, - }, - ], - }, - "displayValue": "76.5 %", - "score": 0.7647, - "slug": "branch-coverage", - "title": "Branch coverage", - "value": 76.47058823529412, - }, - { - "description": "Measures how many lines of code were executed in at least one test.", - "details": { - "issues": [ - { - "message": "Lines 7-9 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "src/lib/partly-covered/utils.ts", - "position": { - "endLine": 9, - "startLine": 7, - }, - }, - }, - { - "message": "Lines 1-5 are not covered in any test case.", - "severity": "warning", - "source": { - "file": "src/lib/not-covered/sorting.ts", - "position": { - "endLine": 5, - "startLine": 1, - }, - }, - }, - ], - }, - "displayValue": "68 %", - "score": 0.68, - "slug": "line-coverage", - "title": "Line coverage", - "value": 68, - }, - ], - "description": "Official Code PushUp code coverage plugin.", - "docsUrl": "https://www.npmjs.com/package/@code-pushup/coverage-plugin/", - "groups": [ - { - "description": "Group containing all defined coverage types as audits.", - "refs": [ - { - "slug": "function-coverage", - "weight": 6, - }, - { - "slug": "branch-coverage", - "weight": 3, - }, - { - "slug": "line-coverage", - "weight": 1, - }, - ], - "slug": "coverage", - "title": "Code coverage metrics", - }, - ], - "icon": "folder-coverage-open", - "packageName": "@code-pushup/coverage-plugin", - "slug": "coverage", - "title": "Code coverage", - }, - ], -} -`; - exports[`CLI collect > should run ESLint plugin and create report.json 1`] = ` { "categories": [ From 0a477cbb6469f316be39eae23b5cedc8a9394d98 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 18 Nov 2024 18:50:25 +0100 Subject: [PATCH 37/42] remove check for warning and error --- e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index 2a7fa6a08..c4e387910 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -25,14 +25,13 @@ describe('collect report with coverage-plugin NPM package', () => { }); it('should run Code coverage plugin which collects passed results and creates report.json', async () => { - const { code, stderr } = await executeProcess({ + const { code } = await executeProcess({ command: 'npx', args: ['@code-pushup/cli', 'collect', '--no-progress'], cwd: basicDir, }); expect(code).toBe(0); - expect(stderr).toBe(''); const report = await readJsonFile( join(basicDir, '.code-pushup', 'report.json'), @@ -43,14 +42,13 @@ describe('collect report with coverage-plugin NPM package', () => { }); it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => { - const { code, stderr } = await executeProcess({ + const { code } = await executeProcess({ command: 'npx', args: ['@code-pushup/cli', 'collect', '--no-progress'], cwd: existingDir, }); expect(code).toBe(0); - expect(stderr).toBe(''); const report = await readJsonFile( join(existingDir, '.code-pushup', 'report.json'), From 1b066e0a2f0826fbded3dd459d0856b3c7f351fb Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:18:13 +0100 Subject: [PATCH 38/42] Update .github/workflows/ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8ad36da1..af4732928 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,7 +120,7 @@ jobs: - name: Install dependencies run: npm ci - name: E2E test affected projects - run: npx nx affected -t nxv-e2e --exclude cli-e2e --parallel=1 --verbose + run: npx nx affected -t nxv-e2e --exclude cli-e2e --parallel=1 - name: E2E test cli-e2e project (due to bugs in the setup it has to run last :( ) run: npx nx run cli-e2e:e2e-old From d165dddb44cd5d32107e984c99803d0641c02744 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:18:26 +0100 Subject: [PATCH 39/42] Update .github/workflows/ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af4732928..845def216 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,7 +120,7 @@ jobs: - name: Install dependencies run: npm ci - name: E2E test affected projects - run: npx nx affected -t nxv-e2e --exclude cli-e2e --parallel=1 + run: npx nx affected -t nxv-e2e --exclude cli-e2e --parallel=1 - name: E2E test cli-e2e project (due to bugs in the setup it has to run last :( ) run: npx nx run cli-e2e:e2e-old From acc59939dd76cf2dad25a628e7508908914762f7 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 18 Nov 2024 21:31:56 +0100 Subject: [PATCH 40/42] clean up merge --- e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap diff --git a/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap deleted file mode 100644 index 7424fd045..000000000 --- a/e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ /dev/null @@ -1,2 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - From 806ab5e2d87811e5957f14b127cec9e4afdddee6 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 18 Nov 2024 22:25:22 +0100 Subject: [PATCH 41/42] fix lint --- e2e/cli-e2e/tests/collect.e2e.test.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/e2e/cli-e2e/tests/collect.e2e.test.ts b/e2e/cli-e2e/tests/collect.e2e.test.ts index 7274fa3fc..8f4e4f630 100644 --- a/e2e/cli-e2e/tests/collect.e2e.test.ts +++ b/e2e/cli-e2e/tests/collect.e2e.test.ts @@ -1,11 +1,10 @@ -import { - type AuditReport, - type PluginReport, - type Report, - reportSchema, +import type { + AuditReport, + PluginReport, + Report, } from '@code-pushup/models'; import { cleanTestFolder } from '@code-pushup/test-setup'; -import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils'; +import { executeProcess, readTextFile } from '@code-pushup/utils'; describe('CLI collect', () => { const exampleCategoryTitle = 'Code style'; From a31d78fa7a2ff058be81aa6df61536c82bb3c23c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 18 Nov 2024 22:27:41 +0100 Subject: [PATCH 42/42] fix format --- e2e/cli-e2e/tests/collect.e2e.test.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/e2e/cli-e2e/tests/collect.e2e.test.ts b/e2e/cli-e2e/tests/collect.e2e.test.ts index 8f4e4f630..912068b58 100644 --- a/e2e/cli-e2e/tests/collect.e2e.test.ts +++ b/e2e/cli-e2e/tests/collect.e2e.test.ts @@ -1,8 +1,4 @@ -import type { - AuditReport, - PluginReport, - Report, -} from '@code-pushup/models'; +import type { AuditReport, PluginReport, Report } from '@code-pushup/models'; import { cleanTestFolder } from '@code-pushup/test-setup'; import { executeProcess, readTextFile } from '@code-pushup/utils';