From bd1b8e1bf570097f6590d8962f9381623a3765f5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 9 Nov 2024 02:02:36 +0100 Subject: [PATCH 1/2] 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 2/2] 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",