Skip to content

Commit 74cc298

Browse files
test(plugin-typescript-e2e): add basic e2e tests (#974)
**Percondition:** - #975 This PR includes: - add e2e project & fixtures --------- Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> Co-authored-by: Matěj Chalk <matej.chalk@flowup.cz>
1 parent d67d97c commit 74cc298

File tree

18 files changed

+468
-11
lines changed

18 files changed

+468
-11
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import tseslint from 'typescript-eslint';
2+
import baseConfig from '../../eslint.config.js';
3+
4+
export default tseslint.config(...baseConfig, {
5+
files: ['**/*.ts'],
6+
languageOptions: {
7+
parserOptions: {
8+
projectService: true,
9+
tsconfigRootDir: import.meta.dirname,
10+
},
11+
},
12+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { CoreConfig } from '@code-pushup/models';
2+
import {
3+
getCategoryRefsFromGroups,
4+
typescriptPlugin,
5+
} from '@code-pushup/typescript-plugin';
6+
7+
export default {
8+
plugins: [await typescriptPlugin()],
9+
categories: [
10+
{
11+
slug: 'typescript-quality',
12+
title: 'Typescript',
13+
refs: getCategoryRefsFromGroups(),
14+
},
15+
],
16+
} satisfies CoreConfig;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function test() {
2+
return 'test';
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const a = { ; // Error: TS1136: Property assignment expected
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// 2683 - NoImplicitThis: 'this' implicitly has type 'any'.
2+
function noImplicitThisTS2683() {
3+
console.log(this.value); // Error 2683
4+
}
5+
6+
// 2531 - StrictNullChecks: Object is possibly 'null'.
7+
const strictNullChecksTS2531: string = null;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Standalone {
2+
override method() { // Error: TS4114 - 'override' modifier can only be used in a class derived from a base class.
3+
console.log("Standalone method");
4+
}
5+
}
6+
const s = Standalone;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { test } from '../exclude/utils';
2+
3+
// TS6059:: File 'exclude/utils.ts' is not under 'rootDir' '.../configuration-errors'. 'rootDir' is expected to contain all source files.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"rootDir": "./src",
4+
"target": "ES6",
5+
"module": "CommonJS",
6+
"strict": true,
7+
"verbatimModuleSyntax": false
8+
},
9+
"include": ["src/**/*.ts"]
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "plugin-typescript-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "e2e/plugin-typescript-e2e/src",
5+
"projectType": "application",
6+
"targets": {
7+
"lint": {
8+
"executor": "@nx/linter:eslint",
9+
"outputs": ["{options.outputFile}"],
10+
"options": {
11+
"lintFilePatterns": ["e2e/plugin-typescript-e2e/**/*.ts"]
12+
}
13+
},
14+
"e2e": {
15+
"executor": "@nx/vite:test",
16+
"options": {
17+
"configFile": "e2e/plugin-typescript-e2e/vite.config.e2e.ts"
18+
}
19+
}
20+
},
21+
"implicitDependencies": ["cli", "plugin-typescript"],
22+
"tags": ["scope:plugin", "type:e2e"]
23+
}
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`PLUGIN collect report with typescript-plugin NPM package > should run plugin over CLI and creates report.json 1`] = `
4+
{
5+
"categories": [
6+
{
7+
"refs": [
8+
{
9+
"plugin": "typescript",
10+
"slug": "problems",
11+
"type": "group",
12+
"weight": 1,
13+
},
14+
{
15+
"plugin": "typescript",
16+
"slug": "ts-configuration",
17+
"type": "group",
18+
"weight": 1,
19+
},
20+
{
21+
"plugin": "typescript",
22+
"slug": "miscellaneous",
23+
"type": "group",
24+
"weight": 1,
25+
},
26+
],
27+
"slug": "typescript-quality",
28+
"title": "Typescript",
29+
},
30+
],
31+
"packageName": "@code-pushup/core",
32+
"plugins": [
33+
{
34+
"audits": [
35+
{
36+
"description": "Errors that occur during parsing and lexing of TypeScript source code",
37+
"details": {
38+
"issues": [
39+
{
40+
"message": "TS1136: Property assignment expected.",
41+
"severity": "error",
42+
"source": {
43+
"file": "tmp/e2e/plugin-typescript-e2e/src/1-syntax-errors.ts",
44+
"position": {
45+
"startLine": 1,
46+
},
47+
},
48+
},
49+
],
50+
},
51+
"displayValue": "1 issue",
52+
"score": 0,
53+
"slug": "syntax-errors",
54+
"title": "Syntax errors",
55+
"value": 1,
56+
},
57+
{
58+
"description": "Errors that occur during type checking and type inference",
59+
"details": {
60+
"issues": [
61+
{
62+
"message": "TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.",
63+
"severity": "error",
64+
"source": {
65+
"file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts",
66+
"position": {
67+
"startLine": 3,
68+
},
69+
},
70+
},
71+
{
72+
"message": "TS2322: Type 'null' is not assignable to type 'string'.",
73+
"severity": "error",
74+
"source": {
75+
"file": "tmp/e2e/plugin-typescript-e2e/src/2-semantic-errors.ts",
76+
"position": {
77+
"startLine": 7,
78+
},
79+
},
80+
},
81+
],
82+
},
83+
"displayValue": "2 issues",
84+
"score": 0,
85+
"slug": "semantic-errors",
86+
"title": "Semantic errors",
87+
"value": 2,
88+
},
89+
{
90+
"description": "Errors that occur during TypeScript language service operations",
91+
"details": {
92+
"issues": [
93+
{
94+
"message": "TS4112: This member cannot have an 'override' modifier because its containing class 'Standalone' does not extend another class.",
95+
"severity": "error",
96+
"source": {
97+
"file": "tmp/e2e/plugin-typescript-e2e/src/4-languale-service.ts",
98+
"position": {
99+
"startLine": 2,
100+
},
101+
},
102+
},
103+
],
104+
},
105+
"displayValue": "1 issue",
106+
"score": 0,
107+
"slug": "declaration-and-language-service-errors",
108+
"title": "Declaration and language service errors",
109+
"value": 1,
110+
},
111+
{
112+
"description": "Errors that occur during TypeScript internal operations",
113+
"displayValue": "0 issues",
114+
"score": 1,
115+
"slug": "internal-errors",
116+
"title": "Internal errors",
117+
"value": 0,
118+
},
119+
{
120+
"description": "Errors that occur when parsing TypeScript configuration files",
121+
"details": {
122+
"issues": [
123+
{
124+
"message": "TS6059: File './exclude/utils.ts' is not under 'rootDir' 'src'. 'rootDir' is expected to contain all source files.",
125+
"severity": "error",
126+
"source": {
127+
"file": "tmp/e2e/plugin-typescript-e2e/src/6-configuration-errors.ts",
128+
"position": {
129+
"startLine": 1,
130+
},
131+
},
132+
},
133+
],
134+
},
135+
"displayValue": "1 issue",
136+
"score": 0,
137+
"slug": "configuration-errors",
138+
"title": "Configuration errors",
139+
"value": 1,
140+
},
141+
{
142+
"description": "Errors related to no implicit any compiler option",
143+
"displayValue": "0 issues",
144+
"score": 1,
145+
"slug": "no-implicit-any-errors",
146+
"title": "No implicit any errors",
147+
"value": 0,
148+
},
149+
{
150+
"description": "Errors that do not match any known TypeScript error code",
151+
"displayValue": "0 issues",
152+
"score": 1,
153+
"slug": "unknown-codes",
154+
"title": "Unknown codes",
155+
"value": 0,
156+
},
157+
],
158+
"description": "Official Code PushUp Typescript plugin.",
159+
"docsUrl": "https://www.npmjs.com/package/@code-pushup/typescript-plugin/",
160+
"groups": [
161+
{
162+
"description": "Syntax, semantic, and internal compiler errors are critical for identifying and preventing bugs.",
163+
"refs": [
164+
{
165+
"slug": "syntax-errors",
166+
"weight": 1,
167+
},
168+
{
169+
"slug": "semantic-errors",
170+
"weight": 1,
171+
},
172+
{
173+
"slug": "no-implicit-any-errors",
174+
"weight": 1,
175+
},
176+
],
177+
"slug": "problems",
178+
"title": "Problems",
179+
},
180+
{
181+
"description": "TypeScript configuration and options errors ensure correct project setup, reducing risks from misconfiguration.",
182+
"refs": [
183+
{
184+
"slug": "configuration-errors",
185+
"weight": 1,
186+
},
187+
],
188+
"slug": "ts-configuration",
189+
"title": "Configuration",
190+
},
191+
{
192+
"description": "Errors that do not bring any specific value to the developer, but are still useful to know.",
193+
"refs": [
194+
{
195+
"slug": "unknown-codes",
196+
"weight": 1,
197+
},
198+
{
199+
"slug": "internal-errors",
200+
"weight": 1,
201+
},
202+
{
203+
"slug": "declaration-and-language-service-errors",
204+
"weight": 1,
205+
},
206+
],
207+
"slug": "miscellaneous",
208+
"title": "Miscellaneous",
209+
},
210+
],
211+
"icon": "typescript",
212+
"packageName": "@code-pushup/typescript-plugin",
213+
"slug": "typescript",
214+
"title": "Typescript",
215+
},
216+
],
217+
}
218+
`;

0 commit comments

Comments
 (0)