From 2ccceb6cb26fa8f341eda307a9a5763e28ddc755 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 10 Mar 2025 17:34:19 +0100 Subject: [PATCH 01/10] test(plugin-typescript-e2e): setup e2e --- e2e/plugin-ts-e2e/eslint.config.js | 12 ++++++++++ .../minimal-setup/code-pushup.config.ts | 5 ++++ .../minimal-setup/src/app.component.ts | 18 +++++++++++++++ .../minimal-setup/src/map-event.function.ts | 10 ++++++++ e2e/plugin-ts-e2e/project.json | 23 +++++++++++++++++++ e2e/plugin-ts-e2e/tsconfig.json | 20 ++++++++++++++++ e2e/plugin-ts-e2e/tsconfig.test.json | 15 ++++++++++++ e2e/plugin-ts-e2e/vite.config.e2e.ts | 21 +++++++++++++++++ 8 files changed, 124 insertions(+) create mode 100644 e2e/plugin-ts-e2e/eslint.config.js create mode 100644 e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts create mode 100644 e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/app.component.ts create mode 100644 e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts create mode 100644 e2e/plugin-ts-e2e/project.json create mode 100644 e2e/plugin-ts-e2e/tsconfig.json create mode 100644 e2e/plugin-ts-e2e/tsconfig.test.json create mode 100644 e2e/plugin-ts-e2e/vite.config.e2e.ts diff --git a/e2e/plugin-ts-e2e/eslint.config.js b/e2e/plugin-ts-e2e/eslint.config.js new file mode 100644 index 000000000..2656b27cb --- /dev/null +++ b/e2e/plugin-ts-e2e/eslint.config.js @@ -0,0 +1,12 @@ +import tseslint from 'typescript-eslint'; +import baseConfig from '../../eslint.config.js'; + +export default tseslint.config(...baseConfig, { + files: ['**/*.ts'], + languageOptions: { + parserOptions: { + projectService: true, + tsconfigRootDir: import.meta.dirname, + }, + }, +}); diff --git a/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts b/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts new file mode 100644 index 000000000..1430904f5 --- /dev/null +++ b/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts @@ -0,0 +1,5 @@ +import tsPlugin from '@code-pushup/ts-plugin'; + +export default { + plugins: [tsPlugin(['**/*.ts'])], +}; diff --git a/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/app.component.ts b/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/app.component.ts new file mode 100644 index 000000000..2fc2b165f --- /dev/null +++ b/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/app.component.ts @@ -0,0 +1,18 @@ +/** + * Basic Angular component that displays a welcome message + */ +export class AppComponent { + protected readonly title = 'My Angular App'; + + /** + * Dummy method that returns a welcome message + * @returns {string} - The welcome message + */ + getWelcomeMessage() { + return 'Welcome to My Angular App!'; + } + + sendEvent() { + return 'Event sent'; + } +} diff --git a/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts b/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts new file mode 100644 index 000000000..55f343e7c --- /dev/null +++ b/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts @@ -0,0 +1,10 @@ +export const someVariable = 'Hello World 1'; + +export function mapEventToCustomEvent(event: string) { + return event; +} + +/** Commented */ +export function mapCustomEventToEvent(event: string) { + return event; +} diff --git a/e2e/plugin-ts-e2e/project.json b/e2e/plugin-ts-e2e/project.json new file mode 100644 index 000000000..a8134d6fd --- /dev/null +++ b/e2e/plugin-ts-e2e/project.json @@ -0,0 +1,23 @@ +{ + "name": "plugin-typescript-e2e", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "e2e/plugin-typescript-e2e/src", + "projectType": "application", + "tags": ["scope:plugin", "type:e2e"], + "implicitDependencies": ["cli", "plugin-typescript"], + "targets": { + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["e2e/plugin-typescript-e2e/**/*.ts"] + } + }, + "e2e": { + "executor": "@nx/vite:test", + "options": { + "configFile": "e2e/plugin-typescript-e2e/vite.config.e2e.ts" + } + } + } +} diff --git a/e2e/plugin-ts-e2e/tsconfig.json b/e2e/plugin-ts-e2e/tsconfig.json new file mode 100644 index 000000000..f5a2f890a --- /dev/null +++ b/e2e/plugin-ts-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-ts-e2e/tsconfig.test.json b/e2e/plugin-ts-e2e/tsconfig.test.json new file mode 100644 index 000000000..34f35e30f --- /dev/null +++ b/e2e/plugin-ts-e2e/tsconfig.test.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"], + "target": "ES2020" + }, + "exclude": ["__test-env__/**"], + "include": [ + "vite.config.e2e.ts", + "tests/**/*.e2e.test.ts", + "tests/**/*.d.ts", + "mocks/**/*.ts" + ] +} diff --git a/e2e/plugin-ts-e2e/vite.config.e2e.ts b/e2e/plugin-ts-e2e/vite.config.e2e.ts new file mode 100644 index 000000000..042b1bca2 --- /dev/null +++ b/e2e/plugin-ts-e2e/vite.config.e2e.ts @@ -0,0 +1,21 @@ +/// +import { defineConfig } from 'vite'; +import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js'; + +export default defineConfig({ + cacheDir: '../../node_modules/.vite/plugin-typescript-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 fba29e7b47241bbe9629351e4c37d1a7ab66956f Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 10 Mar 2025 17:35:08 +0100 Subject: [PATCH 02/10] test(plugin-typescript-e2e): wip --- .../mocks/fixtures/minimal-setup/code-pushup.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts b/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts index 1430904f5..432928c5d 100644 --- a/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts +++ b/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts @@ -1,5 +1,5 @@ -import tsPlugin from '@code-pushup/ts-plugin'; +import typescriptPlugin from '@code-pushup/typescript-plugin'; export default { - plugins: [tsPlugin(['**/*.ts'])], + plugins: [typescriptPlugin(['**/*.ts'])], }; From 7a695061658aeaa1d6b5a42da5c1233603feb5c1 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 10 Mar 2025 17:40:39 +0100 Subject: [PATCH 03/10] test(plugin-typescript-e2e): wip --- e2e/{plugin-ts-e2e => plugin-typescript-e2e}/eslint.config.js | 0 .../mocks/fixtures/minimal-setup/code-pushup.config.ts | 0 .../mocks/fixtures/minimal-setup/src/app.component.ts | 0 .../mocks/fixtures/minimal-setup/src/map-event.function.ts | 0 e2e/{plugin-ts-e2e => plugin-typescript-e2e}/project.json | 0 e2e/{plugin-ts-e2e => plugin-typescript-e2e}/tsconfig.json | 0 e2e/{plugin-ts-e2e => plugin-typescript-e2e}/tsconfig.test.json | 0 e2e/{plugin-ts-e2e => plugin-typescript-e2e}/vite.config.e2e.ts | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename e2e/{plugin-ts-e2e => plugin-typescript-e2e}/eslint.config.js (100%) rename e2e/{plugin-ts-e2e => plugin-typescript-e2e}/mocks/fixtures/minimal-setup/code-pushup.config.ts (100%) rename e2e/{plugin-ts-e2e => plugin-typescript-e2e}/mocks/fixtures/minimal-setup/src/app.component.ts (100%) rename e2e/{plugin-ts-e2e => plugin-typescript-e2e}/mocks/fixtures/minimal-setup/src/map-event.function.ts (100%) rename e2e/{plugin-ts-e2e => plugin-typescript-e2e}/project.json (100%) rename e2e/{plugin-ts-e2e => plugin-typescript-e2e}/tsconfig.json (100%) rename e2e/{plugin-ts-e2e => plugin-typescript-e2e}/tsconfig.test.json (100%) rename e2e/{plugin-ts-e2e => plugin-typescript-e2e}/vite.config.e2e.ts (100%) diff --git a/e2e/plugin-ts-e2e/eslint.config.js b/e2e/plugin-typescript-e2e/eslint.config.js similarity index 100% rename from e2e/plugin-ts-e2e/eslint.config.js rename to e2e/plugin-typescript-e2e/eslint.config.js diff --git a/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts similarity index 100% rename from e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts rename to e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts diff --git a/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/app.component.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/app.component.ts similarity index 100% rename from e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/app.component.ts rename to e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/app.component.ts diff --git a/e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts similarity index 100% rename from e2e/plugin-ts-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts rename to e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts diff --git a/e2e/plugin-ts-e2e/project.json b/e2e/plugin-typescript-e2e/project.json similarity index 100% rename from e2e/plugin-ts-e2e/project.json rename to e2e/plugin-typescript-e2e/project.json diff --git a/e2e/plugin-ts-e2e/tsconfig.json b/e2e/plugin-typescript-e2e/tsconfig.json similarity index 100% rename from e2e/plugin-ts-e2e/tsconfig.json rename to e2e/plugin-typescript-e2e/tsconfig.json diff --git a/e2e/plugin-ts-e2e/tsconfig.test.json b/e2e/plugin-typescript-e2e/tsconfig.test.json similarity index 100% rename from e2e/plugin-ts-e2e/tsconfig.test.json rename to e2e/plugin-typescript-e2e/tsconfig.test.json diff --git a/e2e/plugin-ts-e2e/vite.config.e2e.ts b/e2e/plugin-typescript-e2e/vite.config.e2e.ts similarity index 100% rename from e2e/plugin-ts-e2e/vite.config.e2e.ts rename to e2e/plugin-typescript-e2e/vite.config.e2e.ts From e61be1355c29338475e9d16b3d075d007dde9975 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 10 Mar 2025 17:45:58 +0100 Subject: [PATCH 04/10] test(plugin-typescript-e2e): wip --- .../default-setup/code-pushup.config.ts | 22 ++ .../fixtures/default-setup/exclude/utils.ts | 3 + .../default-setup/src/1-syntax-errors.ts | 1 + .../default-setup/src/2-semantic-errors.ts | 7 + .../default-setup/src/4-languale-service.ts | 6 + .../src/6-configuration-errors.ts | 3 + .../fixtures/default-setup/tsconfig.json | 10 + .../minimal-setup/code-pushup.config.ts | 5 - .../minimal-setup/src/app.component.ts | 18 -- .../minimal-setup/src/map-event.function.ts | 10 - e2e/plugin-typescript-e2e/project.json | 6 +- .../typescript-plugin-json-report.json | 219 ++++++++++++++++++ .../tests/collect.e2e.test.ts | 89 +++++++ e2e/plugin-typescript-e2e/tsconfig.test.json | 1 - e2e/plugin-typescript-e2e/vite.config.e2e.ts | 5 + 15 files changed, 368 insertions(+), 37 deletions(-) create mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/code-pushup.config.ts create mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/exclude/utils.ts create mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/1-syntax-errors.ts create mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/2-semantic-errors.ts create mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/4-languale-service.ts create mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/6-configuration-errors.ts create mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/tsconfig.json delete mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts delete mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/app.component.ts delete mode 100644 e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts create mode 100644 e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json create mode 100644 e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/code-pushup.config.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/code-pushup.config.ts new file mode 100644 index 000000000..0d6856059 --- /dev/null +++ b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/code-pushup.config.ts @@ -0,0 +1,22 @@ +import type { CoreConfig } from '@code-pushup/models'; +import { + getCategoryRefsFromGroups, + typescriptPlugin, +} from '@code-pushup/typescript-plugin'; + +export default { + plugins: [ + await typescriptPlugin({ + tsConfigPath: 'tsconfig.json', + }), + ], + categories: [ + { + slug: 'typescript-quality', + title: 'Typescript', + refs: await getCategoryRefsFromGroups({ + tsConfigPath: 'tsconfig.json', + }), + }, + ], +} satisfies CoreConfig; diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/exclude/utils.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/exclude/utils.ts new file mode 100644 index 000000000..20f47ca5d --- /dev/null +++ b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/exclude/utils.ts @@ -0,0 +1,3 @@ +export function test() { + return 'test'; +} diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/1-syntax-errors.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/1-syntax-errors.ts new file mode 100644 index 000000000..5ba0acd92 --- /dev/null +++ b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/1-syntax-errors.ts @@ -0,0 +1 @@ +const a = { ; // Error: TS1136: Property assignment expected diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/2-semantic-errors.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/2-semantic-errors.ts new file mode 100644 index 000000000..f29009cea --- /dev/null +++ b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/2-semantic-errors.ts @@ -0,0 +1,7 @@ +// 2683 - NoImplicitThis: 'this' implicitly has type 'any'. +function noImplicitThisTS2683() { + console.log(this.value); // Error 2683 +} + +// 2531 - StrictNullChecks: Object is possibly 'null'. +const strictNullChecksTS2531: string = null; diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/4-languale-service.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/4-languale-service.ts new file mode 100644 index 000000000..444811dfb --- /dev/null +++ b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/4-languale-service.ts @@ -0,0 +1,6 @@ +class Standalone { + override method() { // Error: TS4114 - 'override' modifier can only be used in a class derived from a base class. + console.log("Standalone method"); + } +} +const s = Standalone; diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/6-configuration-errors.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/6-configuration-errors.ts new file mode 100644 index 000000000..c5388fe05 --- /dev/null +++ b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/src/6-configuration-errors.ts @@ -0,0 +1,3 @@ +import { test } from '../exclude/utils'; + +// TS6059:: File 'exclude/utils.ts' is not under 'rootDir' '.../configuration-errors'. 'rootDir' is expected to contain all source files. diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/tsconfig.json b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/tsconfig.json new file mode 100644 index 000000000..b9dd367e9 --- /dev/null +++ b/e2e/plugin-typescript-e2e/mocks/fixtures/default-setup/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "rootDir": "./src", + "target": "ES6", + "module": "CommonJS", + "strict": true, + "verbatimModuleSyntax": false + }, + "include": ["src/**/*.ts"] +} diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts deleted file mode 100644 index 432928c5d..000000000 --- a/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/code-pushup.config.ts +++ /dev/null @@ -1,5 +0,0 @@ -import typescriptPlugin from '@code-pushup/typescript-plugin'; - -export default { - plugins: [typescriptPlugin(['**/*.ts'])], -}; diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/app.component.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/app.component.ts deleted file mode 100644 index 2fc2b165f..000000000 --- a/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/app.component.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Basic Angular component that displays a welcome message - */ -export class AppComponent { - protected readonly title = 'My Angular App'; - - /** - * Dummy method that returns a welcome message - * @returns {string} - The welcome message - */ - getWelcomeMessage() { - return 'Welcome to My Angular App!'; - } - - sendEvent() { - return 'Event sent'; - } -} diff --git a/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts b/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts deleted file mode 100644 index 55f343e7c..000000000 --- a/e2e/plugin-typescript-e2e/mocks/fixtures/minimal-setup/src/map-event.function.ts +++ /dev/null @@ -1,10 +0,0 @@ -export const someVariable = 'Hello World 1'; - -export function mapEventToCustomEvent(event: string) { - return event; -} - -/** Commented */ -export function mapCustomEventToEvent(event: string) { - return event; -} diff --git a/e2e/plugin-typescript-e2e/project.json b/e2e/plugin-typescript-e2e/project.json index a8134d6fd..4ec3f7c8a 100644 --- a/e2e/plugin-typescript-e2e/project.json +++ b/e2e/plugin-typescript-e2e/project.json @@ -3,8 +3,6 @@ "$schema": "../../node_modules/nx/schemas/project-schema.json", "sourceRoot": "e2e/plugin-typescript-e2e/src", "projectType": "application", - "tags": ["scope:plugin", "type:e2e"], - "implicitDependencies": ["cli", "plugin-typescript"], "targets": { "lint": { "executor": "@nx/linter:eslint", @@ -19,5 +17,7 @@ "configFile": "e2e/plugin-typescript-e2e/vite.config.e2e.ts" } } - } + }, + "implicitDependencies": ["cli", "plugin-typescript"], + "tags": ["scope:plugin", "type:e2e"] } diff --git a/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json b/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json new file mode 100644 index 000000000..e45d4905b --- /dev/null +++ b/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json @@ -0,0 +1,219 @@ +{ + "categories": [ + { + "refs": [ + { + "plugin": "typescript", + "slug": "problems-group", + "type": "group", + "weight": 1, + }, + { + "plugin": "typescript", + "slug": "ts-configuration-group", + "type": "group", + "weight": 1, + }, + { + "plugin": "typescript", + "slug": "miscellaneous-group", + "type": "group", + "weight": 1, + }, + ], + "slug": "typescript-quality", + "title": "Typescript", + }, + ], + "packageName": "@code-pushup/core", + "plugins": [ + { + "audits": [ + { + "description": "Errors that occur during parsing and lexing of TypeScript source code", + "details": { + "issues": [ + { + "message": "TS1136: Property assignment expected.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/1-syntax-errors.ts", + "position": { + "startLine": 1, + }, + }, + }, + ], + }, + "score": 0, + "slug": "syntax-errors", + "title": "Syntax-Errors", + "value": 1, + }, + { + "description": "Errors that occur during type checking and type inference", + "details": { + "issues": [ + { + "message": "TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", + "position": { + "startLine": 3, + }, + }, + }, + { + "message": "TS2322: Type 'null' is not assignable to type 'string'.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", + "position": { + "startLine": 7, + }, + }, + }, + ], + }, + "score": 0, + "slug": "semantic-errors", + "title": "Semantic-Errors", + "value": 2, + }, + { + "description": "Errors that occur during TypeScript language service operations", + "details": { + "issues": [ + { + "message": "TS4112: This member cannot have an 'override' modifier because its containing class 'Standalone' does not extend another class.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/4-languale-service.ts", + "position": { + "startLine": 2, + }, + }, + }, + ], + }, + "score": 0, + "slug": "declaration-and-language-service-errors", + "title": "Declaration-And-Language-Service-Errors", + "value": 1, + }, + { + "description": "Errors that occur during TypeScript internal operations", + "details": { + "issues": [], + }, + "score": 1, + "slug": "internal-errors", + "title": "Internal-Errors", + "value": 0, + }, + { + "description": "Errors that occur when parsing TypeScript configuration files", + "details": { + "issues": [ + { + "message": "TS6059: File '/Users/michael_hladky/WebstormProjects/quality-metrics-cli/tmp/e2e/plugin-typescript-e2e/exclude/utils.ts' is not under 'rootDir' 'src'. 'rootDir' is expected to contain all source files.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/6-configuration-errors.ts", + "position": { + "startLine": 1, + }, + }, + }, + ], + }, + "score": 0, + "slug": "configuration-errors", + "title": "Configuration-Errors", + "value": 1, + }, + { + "description": "Errors related to no implicit any compiler option", + "details": { + "issues": [], + }, + "score": 1, + "slug": "no-implicit-any-errors", + "title": "No-Implicit-Any-Errors", + "value": 0, + }, + { + "description": "Errors that do not match any known TypeScript error code", + "details": { + "issues": [], + }, + "score": 1, + "slug": "unknown-codes", + "title": "Unknown-Codes", + "value": 0, + }, + ], + "date": "2025-01-10T17:22:29.075Z", + "description": "Official Code PushUp Typescript plugin.", + "docsUrl": "https://www.npmjs.com/package/@code-pushup/typescript-plugin/", + "duration": 2091, + "groups": [ + { + "description": "Syntax, semantic, and internal compiler errors are critical for identifying and preventing bugs.", + "refs": [ + { + "slug": "syntax-errors", + "weight": 1, + }, + { + "slug": "semantic-errors", + "weight": 1, + }, + { + "slug": "internal-errors", + "weight": 1, + }, + { + "slug": "no-implicit-any-errors", + "weight": 1, + }, + ], + "slug": "problems-group", + "title": "Problems", + }, + { + "description": "TypeScript configuration and options errors ensure correct project setup, reducing risks from misconfiguration.", + "refs": [ + { + "slug": "configuration-errors", + "weight": 1, + }, + ], + "slug": "ts-configuration-group", + "title": "Configuration", + }, + { + "description": "Errors that do not bring any specific value to the developer, but are still useful to know.", + "refs": [ + { + "slug": "unknown-codes", + "weight": 1, + }, + { + "slug": "declaration-and-language-service-errors", + "weight": 1, + }, + ], + "slug": "miscellaneous-group", + "title": "Miscellaneous", + }, + ], + "icon": "typescript", + "packageName": "@code-pushup/typescript-plugin", + "slug": "typescript", + "title": "Typescript", + "version": "0.57.0", + }, + ], +} \ No newline at end of file diff --git a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts new file mode 100644 index 000000000..87fd1dd2b --- /dev/null +++ b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts @@ -0,0 +1,89 @@ +import { cp } from 'node:fs/promises'; +// eslint-disable-next-line unicorn/import-style +import path, { join } from 'node:path'; +import { afterAll, beforeAll, expect } from 'vitest'; +import { type Report, reportSchema } from '@code-pushup/models'; +import { nxTargetProject } from '@code-pushup/test-nx-utils'; +import { teardownTestFolder } from '@code-pushup/test-setup'; +import { + E2E_ENVIRONMENTS_DIR, + TEST_OUTPUT_DIR, + omitVariableReportData, + osAgnosticPath, + removeColorCodes, +} from '@code-pushup/test-utils'; +import { executeProcess, readJsonFile } from '@code-pushup/utils'; + +describe('PLUGIN collect report with typescript-plugin NPM package', () => { + const envRoot = join(E2E_ENVIRONMENTS_DIR, nxTargetProject()); + const distRoot = join(envRoot, TEST_OUTPUT_DIR); + + const fixturesDir = join( + 'e2e', + nxTargetProject(), + 'mocks', + 'fixtures', + 'default-setup', + ); + + beforeAll(async () => { + await cp(fixturesDir, envRoot, { recursive: true }); + }); + + afterAll(async () => { + await teardownTestFolder(distRoot); + }); + + it('should run plugin over CLI and creates report.json', async () => { + const outputDir = join( + path.relative(envRoot, distRoot), + 'create-report', + '.code-pushup', + ); + + const { code, stdout } = await executeProcess({ + command: 'npx', + // verbose exposes audits with perfect scores that are hidden in the default stdout + args: [ + '@code-pushup/cli', + 'collect', + '--no-progress', + '--verbose', + `--persist.outputDir=${outputDir}`, + ], + cwd: envRoot, + }); + + expect(code).toBe(0); + const cleanStdout = removeColorCodes(stdout); + + // @TODO should be 1 test failing => /● NoImplicitAny\s+1/ + expect(cleanStdout).toMatch(/● Configuration-Errors\s+\d+/); + + const reportJson = await readJsonFile( + join(envRoot, outputDir, 'report.json'), + ); + expect(() => reportSchema.parse(reportJson)).not.toThrow(); + expect({ + ...omitVariableReportData(reportJson, { omitAuditData: false }), + plugins: reportJson.plugins.map(plugin => ({ + ...plugin, + audits: plugin.audits.map(audit => ({ + ...audit, + details: { + ...audit.details, + issues: (audit?.details?.issues ?? []).map(issue => ({ + ...issue, + source: { + ...issue.source, + ...(issue?.source?.file + ? { file: osAgnosticPath(issue?.source?.file) } + : {}), + }, + })), + }, + })), + })), + }).toMatchFileSnapshot('__snapshots__/typescript-plugin-json-report.json'); + }); +}); diff --git a/e2e/plugin-typescript-e2e/tsconfig.test.json b/e2e/plugin-typescript-e2e/tsconfig.test.json index 34f35e30f..10c7f79de 100644 --- a/e2e/plugin-typescript-e2e/tsconfig.test.json +++ b/e2e/plugin-typescript-e2e/tsconfig.test.json @@ -5,7 +5,6 @@ "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/e2e/plugin-typescript-e2e/vite.config.e2e.ts b/e2e/plugin-typescript-e2e/vite.config.e2e.ts index 042b1bca2..e6b460427 100644 --- a/e2e/plugin-typescript-e2e/vite.config.e2e.ts +++ b/e2e/plugin-typescript-e2e/vite.config.e2e.ts @@ -11,6 +11,11 @@ export default defineConfig({ alias: tsconfigPathAliases(), pool: 'threads', poolOptions: { threads: { singleThread: true } }, + coverage: { + reporter: ['text', 'lcov'], + reportsDirectory: '../../coverage/plugin-typescript-e2e/e2e-tests', + exclude: ['mocks/**', '**/types.ts'], + }, cache: { dir: '../../node_modules/.vitest', }, From b656fb777ddda9f0de975555bfd99a1aa58f9132 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 10 Mar 2025 18:18:46 +0100 Subject: [PATCH 05/10] test(plugin-typescript-e2e): wip --- e2e/plugin-typescript-e2e/tsconfig.json | 6 +++++- e2e/plugin-typescript-e2e/tsconfig.test.json | 8 ++++++++ e2e/plugin-typescript-e2e/vite.config.e2e.ts | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/e2e/plugin-typescript-e2e/tsconfig.json b/e2e/plugin-typescript-e2e/tsconfig.json index f5a2f890a..221c94c8f 100644 --- a/e2e/plugin-typescript-e2e/tsconfig.json +++ b/e2e/plugin-typescript-e2e/tsconfig.json @@ -8,7 +8,11 @@ "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, - "types": ["vitest"] + "types": ["vitest"], + "paths": { + "@code-pushup/test-setup": ["../../testing/test-setup/src/index.ts"], + "@code-pushup/test-nx-setup": ["../../testing/test-nx-setup/src/index.ts"] + } }, "files": [], "include": [], diff --git a/e2e/plugin-typescript-e2e/tsconfig.test.json b/e2e/plugin-typescript-e2e/tsconfig.test.json index 10c7f79de..0e57f62c7 100644 --- a/e2e/plugin-typescript-e2e/tsconfig.test.json +++ b/e2e/plugin-typescript-e2e/tsconfig.test.json @@ -5,6 +5,14 @@ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"], "target": "ES2020" }, + "references": [ + { + "path": "../../testing/test-setup/tsconfig.json" + }, + { + "path": "../../testing/test-nx-utils/tsconfig.json" + } + ], "include": [ "vite.config.e2e.ts", "tests/**/*.e2e.test.ts", diff --git a/e2e/plugin-typescript-e2e/vite.config.e2e.ts b/e2e/plugin-typescript-e2e/vite.config.e2e.ts index e6b460427..3035c644b 100644 --- a/e2e/plugin-typescript-e2e/vite.config.e2e.ts +++ b/e2e/plugin-typescript-e2e/vite.config.e2e.ts @@ -4,6 +4,13 @@ import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases.js export default defineConfig({ cacheDir: '../../node_modules/.vite/plugin-typescript-e2e', + resolve: { + alias: { + '@code-pushup/test-nx-utils': '../../test-nx-utils/index.js', + '@code-pushup/test-setup': '../../test-setup/index.js', + '@code-pushup/test-utils': '../../test-utils/index.js', + }, + }, test: { reporters: ['basic'], testTimeout: 120_000, From 1a01bd97403f9ce2b61525e3010876dfd4602d80 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Mar 2025 12:46:54 +0100 Subject: [PATCH 06/10] test(plugin-typescript-e2e): fix --- .../typescript-plugin-json-report.json | 219 ------------------ .../tests/collect.e2e.test.ts | 2 +- e2e/plugin-typescript-e2e/tsconfig.json | 6 +- e2e/plugin-typescript-e2e/tsconfig.test.json | 8 - 4 files changed, 2 insertions(+), 233 deletions(-) delete mode 100644 e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json diff --git a/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json b/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json deleted file mode 100644 index e45d4905b..000000000 --- a/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json +++ /dev/null @@ -1,219 +0,0 @@ -{ - "categories": [ - { - "refs": [ - { - "plugin": "typescript", - "slug": "problems-group", - "type": "group", - "weight": 1, - }, - { - "plugin": "typescript", - "slug": "ts-configuration-group", - "type": "group", - "weight": 1, - }, - { - "plugin": "typescript", - "slug": "miscellaneous-group", - "type": "group", - "weight": 1, - }, - ], - "slug": "typescript-quality", - "title": "Typescript", - }, - ], - "packageName": "@code-pushup/core", - "plugins": [ - { - "audits": [ - { - "description": "Errors that occur during parsing and lexing of TypeScript source code", - "details": { - "issues": [ - { - "message": "TS1136: Property assignment expected.", - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/1-syntax-errors.ts", - "position": { - "startLine": 1, - }, - }, - }, - ], - }, - "score": 0, - "slug": "syntax-errors", - "title": "Syntax-Errors", - "value": 1, - }, - { - "description": "Errors that occur during type checking and type inference", - "details": { - "issues": [ - { - "message": "TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.", - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", - "position": { - "startLine": 3, - }, - }, - }, - { - "message": "TS2322: Type 'null' is not assignable to type 'string'.", - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", - "position": { - "startLine": 7, - }, - }, - }, - ], - }, - "score": 0, - "slug": "semantic-errors", - "title": "Semantic-Errors", - "value": 2, - }, - { - "description": "Errors that occur during TypeScript language service operations", - "details": { - "issues": [ - { - "message": "TS4112: This member cannot have an 'override' modifier because its containing class 'Standalone' does not extend another class.", - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/4-languale-service.ts", - "position": { - "startLine": 2, - }, - }, - }, - ], - }, - "score": 0, - "slug": "declaration-and-language-service-errors", - "title": "Declaration-And-Language-Service-Errors", - "value": 1, - }, - { - "description": "Errors that occur during TypeScript internal operations", - "details": { - "issues": [], - }, - "score": 1, - "slug": "internal-errors", - "title": "Internal-Errors", - "value": 0, - }, - { - "description": "Errors that occur when parsing TypeScript configuration files", - "details": { - "issues": [ - { - "message": "TS6059: File '/Users/michael_hladky/WebstormProjects/quality-metrics-cli/tmp/e2e/plugin-typescript-e2e/exclude/utils.ts' is not under 'rootDir' 'src'. 'rootDir' is expected to contain all source files.", - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/6-configuration-errors.ts", - "position": { - "startLine": 1, - }, - }, - }, - ], - }, - "score": 0, - "slug": "configuration-errors", - "title": "Configuration-Errors", - "value": 1, - }, - { - "description": "Errors related to no implicit any compiler option", - "details": { - "issues": [], - }, - "score": 1, - "slug": "no-implicit-any-errors", - "title": "No-Implicit-Any-Errors", - "value": 0, - }, - { - "description": "Errors that do not match any known TypeScript error code", - "details": { - "issues": [], - }, - "score": 1, - "slug": "unknown-codes", - "title": "Unknown-Codes", - "value": 0, - }, - ], - "date": "2025-01-10T17:22:29.075Z", - "description": "Official Code PushUp Typescript plugin.", - "docsUrl": "https://www.npmjs.com/package/@code-pushup/typescript-plugin/", - "duration": 2091, - "groups": [ - { - "description": "Syntax, semantic, and internal compiler errors are critical for identifying and preventing bugs.", - "refs": [ - { - "slug": "syntax-errors", - "weight": 1, - }, - { - "slug": "semantic-errors", - "weight": 1, - }, - { - "slug": "internal-errors", - "weight": 1, - }, - { - "slug": "no-implicit-any-errors", - "weight": 1, - }, - ], - "slug": "problems-group", - "title": "Problems", - }, - { - "description": "TypeScript configuration and options errors ensure correct project setup, reducing risks from misconfiguration.", - "refs": [ - { - "slug": "configuration-errors", - "weight": 1, - }, - ], - "slug": "ts-configuration-group", - "title": "Configuration", - }, - { - "description": "Errors that do not bring any specific value to the developer, but are still useful to know.", - "refs": [ - { - "slug": "unknown-codes", - "weight": 1, - }, - { - "slug": "declaration-and-language-service-errors", - "weight": 1, - }, - ], - "slug": "miscellaneous-group", - "title": "Miscellaneous", - }, - ], - "icon": "typescript", - "packageName": "@code-pushup/typescript-plugin", - "slug": "typescript", - "title": "Typescript", - "version": "0.57.0", - }, - ], -} \ No newline at end of file diff --git a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts index 87fd1dd2b..2f975c24b 100644 --- a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts @@ -4,13 +4,13 @@ import path, { join } from 'node:path'; import { afterAll, beforeAll, expect } from 'vitest'; import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; -import { teardownTestFolder } from '@code-pushup/test-setup'; import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR, omitVariableReportData, osAgnosticPath, removeColorCodes, + teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; diff --git a/e2e/plugin-typescript-e2e/tsconfig.json b/e2e/plugin-typescript-e2e/tsconfig.json index 221c94c8f..f5a2f890a 100644 --- a/e2e/plugin-typescript-e2e/tsconfig.json +++ b/e2e/plugin-typescript-e2e/tsconfig.json @@ -8,11 +8,7 @@ "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, - "types": ["vitest"], - "paths": { - "@code-pushup/test-setup": ["../../testing/test-setup/src/index.ts"], - "@code-pushup/test-nx-setup": ["../../testing/test-nx-setup/src/index.ts"] - } + "types": ["vitest"] }, "files": [], "include": [], diff --git a/e2e/plugin-typescript-e2e/tsconfig.test.json b/e2e/plugin-typescript-e2e/tsconfig.test.json index 0e57f62c7..10c7f79de 100644 --- a/e2e/plugin-typescript-e2e/tsconfig.test.json +++ b/e2e/plugin-typescript-e2e/tsconfig.test.json @@ -5,14 +5,6 @@ "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"], "target": "ES2020" }, - "references": [ - { - "path": "../../testing/test-setup/tsconfig.json" - }, - { - "path": "../../testing/test-nx-utils/tsconfig.json" - } - ], "include": [ "vite.config.e2e.ts", "tests/**/*.e2e.test.ts", From fa40fe157212b5ece5cf58a7253273ee4ba134b7 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Mar 2025 15:29:45 +0100 Subject: [PATCH 07/10] test(plugin-typescript): add e2e test --- .../typescript-plugin-json-report.json | 226 ++++++++++++++++++ .../tests/collect.e2e.test.ts | 10 +- packages/plugin-typescript/src/index.ts | 2 +- 3 files changed, 235 insertions(+), 3 deletions(-) create mode 100644 e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json diff --git a/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json b/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json new file mode 100644 index 000000000..0777d9f9e --- /dev/null +++ b/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json @@ -0,0 +1,226 @@ +{ + "categories": [ + { + "refs": [ + { + "plugin": "typescript", + "slug": "problems", + "type": "group", + "weight": 1, + }, + { + "plugin": "typescript", + "slug": "ts-configuration", + "type": "group", + "weight": 1, + }, + { + "plugin": "typescript", + "slug": "miscellaneous", + "type": "group", + "weight": 1, + }, + ], + "slug": "typescript-quality", + "title": "Typescript", + }, + ], + "packageName": "@code-pushup/core", + "plugins": [ + { + "audits": [ + { + "description": "Errors that occur during parsing and lexing of TypeScript source code", + "details": { + "issues": [ + { + "message": "TS1136: Property assignment expected.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/1-syntax-errors.ts", + "position": { + "startLine": 1, + }, + }, + }, + ], + }, + "displayValue": "1 issue", + "score": 0, + "slug": "syntax-errors", + "title": "Syntax errors", + "value": 1, + }, + { + "description": "Errors that occur during type checking and type inference", + "details": { + "issues": [ + { + "message": "TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", + "position": { + "startLine": 3, + }, + }, + }, + { + "message": "TS2322: Type 'null' is not assignable to type 'string'.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", + "position": { + "startLine": 7, + }, + }, + }, + ], + }, + "displayValue": "2 issues", + "score": 0, + "slug": "semantic-errors", + "title": "Semantic errors", + "value": 2, + }, + { + "description": "Errors that occur during TypeScript language service operations", + "details": { + "issues": [ + { + "message": "TS4112: This member cannot have an 'override' modifier because its containing class 'Standalone' does not extend another class.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/4-languale-service.ts", + "position": { + "startLine": 2, + }, + }, + }, + ], + }, + "displayValue": "1 issue", + "score": 0, + "slug": "declaration-and-language-service-errors", + "title": "Declaration and language service errors", + "value": 1, + }, + { + "description": "Errors that occur during TypeScript internal operations", + "details": { + "issues": [], + }, + "displayValue": "0 issues", + "score": 1, + "slug": "internal-errors", + "title": "Internal errors", + "value": 0, + }, + { + "description": "Errors that occur when parsing TypeScript configuration files", + "details": { + "issues": [ + { + "message": "TS6059: File '/Users/michael_hladky/WebstormProjects/quality-metrics-cli/tmp/e2e/plugin-typescript-e2e/exclude/utils.ts' is not under 'rootDir' 'src'. 'rootDir' is expected to contain all source files.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-typescript-e2e/src/6-configuration-errors.ts", + "position": { + "startLine": 1, + }, + }, + }, + ], + }, + "displayValue": "1 issue", + "score": 0, + "slug": "configuration-errors", + "title": "Configuration errors", + "value": 1, + }, + { + "description": "Errors related to no implicit any compiler option", + "details": { + "issues": [], + }, + "displayValue": "0 issues", + "score": 1, + "slug": "no-implicit-any-errors", + "title": "No implicit any errors", + "value": 0, + }, + { + "description": "Errors that do not match any known TypeScript error code", + "details": { + "issues": [], + }, + "displayValue": "0 issues", + "score": 1, + "slug": "unknown-codes", + "title": "Unknown codes", + "value": 0, + }, + ], + "date": "2025-03-21T14:28:54.857Z", + "description": "Official Code PushUp Typescript plugin.", + "docsUrl": "https://www.npmjs.com/package/@code-pushup/typescript-plugin/", + "duration": 2251, + "groups": [ + { + "description": "Syntax, semantic, and internal compiler errors are critical for identifying and preventing bugs.", + "refs": [ + { + "slug": "syntax-errors", + "weight": 1, + }, + { + "slug": "semantic-errors", + "weight": 1, + }, + { + "slug": "no-implicit-any-errors", + "weight": 1, + }, + ], + "slug": "problems", + "title": "Problems", + }, + { + "description": "TypeScript configuration and options errors ensure correct project setup, reducing risks from misconfiguration.", + "refs": [ + { + "slug": "configuration-errors", + "weight": 1, + }, + ], + "slug": "ts-configuration", + "title": "Configuration", + }, + { + "description": "Errors that do not bring any specific value to the developer, but are still useful to know.", + "refs": [ + { + "slug": "unknown-codes", + "weight": 1, + }, + { + "slug": "internal-errors", + "weight": 1, + }, + { + "slug": "declaration-and-language-service-errors", + "weight": 1, + }, + ], + "slug": "miscellaneous", + "title": "Miscellaneous", + }, + ], + "icon": "typescript", + "packageName": "@code-pushup/typescript-plugin", + "slug": "typescript", + "title": "Typescript", + "version": "0.57.0", + }, + ], +} \ No newline at end of file diff --git a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts index 2f975c24b..363a5df4e 100644 --- a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts @@ -57,8 +57,14 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => { expect(code).toBe(0); const cleanStdout = removeColorCodes(stdout); - // @TODO should be 1 test failing => /● NoImplicitAny\s+1/ - expect(cleanStdout).toMatch(/● Configuration-Errors\s+\d+/); + expect(cleanStdout).toMatch(/● Semantic errors\s+\d+ issue/); + expect(cleanStdout).toMatch(/● Configuration errors\s+\d+ issue/); + expect(cleanStdout).toMatch( + /● Declaration and language service errors\s+\d+ issue/, + ); + expect(cleanStdout).toMatch(/● Syntax errors\s+\d+ issue/); + expect(cleanStdout).toMatch(/● Internal errors\s+\d+ issue/); + expect(cleanStdout).toMatch(/● No implicit any errors\s+\d+ issue/); const reportJson = await readJsonFile( join(envRoot, outputDir, 'report.json'), diff --git a/packages/plugin-typescript/src/index.ts b/packages/plugin-typescript/src/index.ts index de384e130..7dbcf52bb 100644 --- a/packages/plugin-typescript/src/index.ts +++ b/packages/plugin-typescript/src/index.ts @@ -1,6 +1,6 @@ export { TYPESCRIPT_PLUGIN_SLUG } from './lib/constants.js'; export { typescriptPlugin } from './lib/typescript-plugin.js'; -export { getCategories } from './lib/utils.js'; +export { getCategories, getCategoryRefsFromGroups } from './lib/utils.js'; export { type TypescriptPluginConfig, type TypescriptPluginOptions, From 97358eb6f4576772184b29a047ed5e4a582bd24c Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Mar 2025 16:11:41 +0100 Subject: [PATCH 08/10] test(plugin-typescript): adjust e2e test --- .../typescript-plugin-json-report.json | 9 ++------- .../tests/collect.e2e.test.ts | 20 ++++++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json b/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json index 0777d9f9e..1d762961d 100644 --- a/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json +++ b/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json @@ -34,7 +34,6 @@ "details": { "issues": [ { - "message": "TS1136: Property assignment expected.", "severity": "error", "source": { "file": "tmp/e2e/plugin-typescript-e2e/src/1-syntax-errors.ts", @@ -56,7 +55,6 @@ "details": { "issues": [ { - "message": "TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.", "severity": "error", "source": { "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", @@ -66,7 +64,6 @@ }, }, { - "message": "TS2322: Type 'null' is not assignable to type 'string'.", "severity": "error", "source": { "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", @@ -88,7 +85,6 @@ "details": { "issues": [ { - "message": "TS4112: This member cannot have an 'override' modifier because its containing class 'Standalone' does not extend another class.", "severity": "error", "source": { "file": "tmp/e2e/plugin-typescript-e2e/src/4-languale-service.ts", @@ -121,7 +117,6 @@ "details": { "issues": [ { - "message": "TS6059: File '/Users/michael_hladky/WebstormProjects/quality-metrics-cli/tmp/e2e/plugin-typescript-e2e/exclude/utils.ts' is not under 'rootDir' 'src'. 'rootDir' is expected to contain all source files.", "severity": "error", "source": { "file": "tmp/e2e/plugin-typescript-e2e/src/6-configuration-errors.ts", @@ -161,10 +156,10 @@ "value": 0, }, ], - "date": "2025-03-21T14:28:54.857Z", + "date": "2025-03-21T15:11:20.928Z", "description": "Official Code PushUp Typescript plugin.", "docsUrl": "https://www.npmjs.com/package/@code-pushup/typescript-plugin/", - "duration": 2251, + "duration": 2173, "groups": [ { "description": "Syntax, semantic, and internal compiler errors are critical for identifying and preventing bugs.", diff --git a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts index 363a5df4e..23e2ff5aa 100644 --- a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts @@ -78,15 +78,17 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => { ...audit, details: { ...audit.details, - issues: (audit?.details?.issues ?? []).map(issue => ({ - ...issue, - source: { - ...issue.source, - ...(issue?.source?.file - ? { file: osAgnosticPath(issue?.source?.file) } - : {}), - }, - })), + issues: (audit?.details?.issues ?? []).map( + ({ message, ...issue }) => ({ + ...issue, + source: { + ...issue.source, + ...(issue?.source?.file + ? { file: osAgnosticPath(issue?.source?.file) } + : {}), + }, + }), + ), }, })), })), From 5a270128078d5f7681ae444a9565f0aaf6db84d4 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Mar 2025 12:24:29 +0100 Subject: [PATCH 09/10] test(plugin-typescript): adjust e2e snapshot --- .../typescript-plugin-json-report.json | 94 ------------------- .../tests/collect.e2e.test.ts | 28 +----- 2 files changed, 4 insertions(+), 118 deletions(-) diff --git a/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json b/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json index 1d762961d..0ec3a50da 100644 --- a/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json +++ b/e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json @@ -31,135 +31,42 @@ "audits": [ { "description": "Errors that occur during parsing and lexing of TypeScript source code", - "details": { - "issues": [ - { - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/1-syntax-errors.ts", - "position": { - "startLine": 1, - }, - }, - }, - ], - }, - "displayValue": "1 issue", - "score": 0, "slug": "syntax-errors", "title": "Syntax errors", - "value": 1, }, { "description": "Errors that occur during type checking and type inference", - "details": { - "issues": [ - { - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", - "position": { - "startLine": 3, - }, - }, - }, - { - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts", - "position": { - "startLine": 7, - }, - }, - }, - ], - }, - "displayValue": "2 issues", - "score": 0, "slug": "semantic-errors", "title": "Semantic errors", - "value": 2, }, { "description": "Errors that occur during TypeScript language service operations", - "details": { - "issues": [ - { - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/4-languale-service.ts", - "position": { - "startLine": 2, - }, - }, - }, - ], - }, - "displayValue": "1 issue", - "score": 0, "slug": "declaration-and-language-service-errors", "title": "Declaration and language service errors", - "value": 1, }, { "description": "Errors that occur during TypeScript internal operations", - "details": { - "issues": [], - }, - "displayValue": "0 issues", - "score": 1, "slug": "internal-errors", "title": "Internal errors", - "value": 0, }, { "description": "Errors that occur when parsing TypeScript configuration files", - "details": { - "issues": [ - { - "severity": "error", - "source": { - "file": "tmp/e2e/plugin-typescript-e2e/src/6-configuration-errors.ts", - "position": { - "startLine": 1, - }, - }, - }, - ], - }, - "displayValue": "1 issue", - "score": 0, "slug": "configuration-errors", "title": "Configuration errors", - "value": 1, }, { "description": "Errors related to no implicit any compiler option", - "details": { - "issues": [], - }, - "displayValue": "0 issues", - "score": 1, "slug": "no-implicit-any-errors", "title": "No implicit any errors", - "value": 0, }, { "description": "Errors that do not match any known TypeScript error code", - "details": { - "issues": [], - }, - "displayValue": "0 issues", - "score": 1, "slug": "unknown-codes", "title": "Unknown codes", - "value": 0, }, ], - "date": "2025-03-21T15:11:20.928Z", "description": "Official Code PushUp Typescript plugin.", "docsUrl": "https://www.npmjs.com/package/@code-pushup/typescript-plugin/", - "duration": 2173, "groups": [ { "description": "Syntax, semantic, and internal compiler errors are critical for identifying and preventing bugs.", @@ -215,7 +122,6 @@ "packageName": "@code-pushup/typescript-plugin", "slug": "typescript", "title": "Typescript", - "version": "0.57.0", }, ], } \ No newline at end of file diff --git a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts index 23e2ff5aa..67453f56b 100644 --- a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts @@ -7,8 +7,8 @@ import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR, + omitVariablePluginData, omitVariableReportData, - osAgnosticPath, removeColorCodes, teardownTestFolder, } from '@code-pushup/test-utils'; @@ -70,28 +70,8 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => { join(envRoot, outputDir, 'report.json'), ); expect(() => reportSchema.parse(reportJson)).not.toThrow(); - expect({ - ...omitVariableReportData(reportJson, { omitAuditData: false }), - plugins: reportJson.plugins.map(plugin => ({ - ...plugin, - audits: plugin.audits.map(audit => ({ - ...audit, - details: { - ...audit.details, - issues: (audit?.details?.issues ?? []).map( - ({ message, ...issue }) => ({ - ...issue, - source: { - ...issue.source, - ...(issue?.source?.file - ? { file: osAgnosticPath(issue?.source?.file) } - : {}), - }, - }), - ), - }, - })), - })), - }).toMatchFileSnapshot('__snapshots__/typescript-plugin-json-report.json'); + expect( + omitVariableReportData(reportJson, { omitAuditData: true }), + ).toMatchFileSnapshot('__snapshots__/typescript-plugin-json-report.json'); }); }); From 675e57571b3b07ba8c3ef35ba926a89e4d5efbc3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Mar 2025 12:26:19 +0100 Subject: [PATCH 10/10] test(plugin-typescript-e2e): wip --- e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts index 67453f56b..81ea51d6d 100644 --- a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts @@ -7,7 +7,6 @@ import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR, - omitVariablePluginData, omitVariableReportData, removeColorCodes, teardownTestFolder,