perf(tests): use Angular recommended test config (#2632)

This commit is contained in:
Alex
2026-09-14 15:58:30 +01:00
committed by GitHub
parent 9b38a091e1
commit 6bfb345c81
7 changed files with 67 additions and 668 deletions
+13 -1
View File
@@ -136,7 +136,19 @@
"test": { "test": {
"builder": "@angular/build:unit-test", "builder": "@angular/build:unit-test",
"options": { "options": {
"runnerConfig": "vitest-base.config.ts" "runnerConfig": "vitest-base.config.ts",
"isolate": true,
"reporters": [
["default", {"summary": false}],
["junit", {"outputFile": "test-results/vitest-results.xml"}]
],
"coverageInclude": ["src/app/**/*.ts", "src/main.ts"],
"coverageExclude": [
"src/app/**/*.spec.ts",
"src/app/**/*.module.ts",
"src/**/*.d.ts"
],
"coverageReporters": ["text", "html", "json", "json-summary", "lcov"]
} }
}, },
"lint": { "lint": {
+2 -5
View File
@@ -59,7 +59,6 @@
"uuid": "^14.0.2" "uuid": "^14.0.2"
}, },
"devDependencies": { "devDependencies": {
"@analogjs/vite-plugin-angular": "^2.6.4",
"@angular-devkit/architect": "^0.2201.4", "@angular-devkit/architect": "^0.2201.4",
"@angular-devkit/schematics": "^22.1.4", "@angular-devkit/schematics": "^22.1.4",
"@angular/build": "22.1.4", "@angular/build": "22.1.4",
@@ -69,10 +68,9 @@
"@openng/optimus-ui-tailwindcss": "^2.0.1", "@openng/optimus-ui-tailwindcss": "^2.0.1",
"@playwright/test": "^1.62.1", "@playwright/test": "^1.62.1",
"@tailwindcss/postcss": "^4.3.3", "@tailwindcss/postcss": "^4.3.3",
"@testing-library/jest-dom": "^7.0.1",
"@types/markdown-it": "^14.1.2", "@types/markdown-it": "^14.1.2",
"@types/node": "^24.13.2", "@types/node": "^24.13.2",
"@vitest/coverage-v8": "^5.0.0", "@vitest/coverage-v8": "^4.1.11",
"angular-eslint": "^22.1.0", "angular-eslint": "^22.1.0",
"eslint": "^10.9.1", "eslint": "^10.9.1",
"jsdom": "^30.0.1", "jsdom": "^30.0.1",
@@ -83,7 +81,6 @@
"tailwindcss": "^4.3.3", "tailwindcss": "^4.3.3",
"typescript": "~6.0.3", "typescript": "~6.0.3",
"typescript-eslint": "^8.67.0", "typescript-eslint": "^8.67.0",
"vitest": "^4.1.11", "vitest": "^4.1.11"
"vitest-canvas-mock": "^1.1.4"
} }
} }
-123
View File
@@ -1,123 +0,0 @@
import '@angular/compiler';
import {vi} from 'vitest';
import '@testing-library/jest-dom/vitest';
import 'vitest-canvas-mock';
import {TestBed} from '@angular/core/testing';
import {BrowserTestingModule, platformBrowserTesting} from '@angular/platform-browser/testing';
declare global {
var __ANGULAR_TESTBED_INITIALIZED__: boolean | undefined;
}
class MockResizeObserver {
observe(): undefined { return undefined; }
unobserve(): undefined { return undefined; }
disconnect(): undefined { return undefined; }
}
class MockIntersectionObserver {
readonly root = null;
readonly rootMargin = '';
readonly thresholds = [0];
readonly scrollMargin = '';
observe(): undefined { return undefined; }
unobserve(): undefined { return undefined; }
disconnect(): undefined { return undefined; }
takeRecords(): IntersectionObserverEntry[] {
return [];
}
}
// Standard mock for matchMedia to support Optimus UI and other UI libraries in JSDOM
const matchMediaMock = (query: string): MediaQueryList => ({
matches: false,
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
addListener: vi.fn(), // Deprecated but still used by some libraries
removeListener: vi.fn(), // Deprecated
dispatchEvent: vi.fn(),
});
Object.defineProperty(globalThis, 'matchMedia', {
writable: true,
configurable: true,
enumerable: true,
value: matchMediaMock,
});
Object.defineProperty(window, 'matchMedia', {
writable: true,
configurable: true,
enumerable: true,
value: matchMediaMock,
});
if (process.env['GITHUB_ACTIONS']) {
console.log('Test setup: Applied robust window.matchMedia mock');
}
if (!globalThis.ResizeObserver) {
globalThis.ResizeObserver = MockResizeObserver as typeof ResizeObserver;
}
if (!globalThis.IntersectionObserver) {
globalThis.IntersectionObserver = MockIntersectionObserver as typeof IntersectionObserver;
}
if (!globalThis.PointerEvent) {
globalThis.PointerEvent = MouseEvent as typeof PointerEvent;
}
if (!globalThis.DOMRect) {
globalThis.DOMRect = class DOMRectMock implements DOMRect {
bottom = 0;
height = 0;
left = 0;
right = 0;
top = 0;
width = 0;
x = 0;
y = 0;
toJSON(): Record<string, number> {
return {
bottom: this.bottom,
height: this.height,
left: this.left,
right: this.right,
top: this.top,
width: this.width,
x: this.x,
y: this.y
};
}
} as typeof DOMRect;
}
if (!window.scrollTo) {
window.scrollTo = () => undefined;
}
if (!window.HTMLElement.prototype.scrollIntoView) {
window.HTMLElement.prototype.scrollIntoView = () => undefined;
}
if (!window.URL.createObjectURL) {
window.URL.createObjectURL = () => 'blob:mock-url';
}
if (!window.URL.revokeObjectURL) {
window.URL.revokeObjectURL = () => undefined;
}
// Only initialize if not already initialized
if (!globalThis.__ANGULAR_TESTBED_INITIALIZED__) {
globalThis.__ANGULAR_TESTBED_INITIALIZED__ = true;
TestBed.initTestEnvironment(
BrowserTestingModule,
platformBrowserTesting(),
{teardown: {destroyAfterEach: true}}
);
}
+1 -2
View File
@@ -8,7 +8,6 @@
}, },
"include": [ "include": [
"src/**/*.spec.ts", "src/**/*.spec.ts",
"src/**/*.d.ts", "src/**/*.d.ts"
"src/test-setup.ts"
] ]
} }
+2 -14
View File
@@ -1,24 +1,12 @@
import {defineConfig} from 'vitest/config'; import {defineConfig} from 'vitest/config';
import angular from '@analogjs/vite-plugin-angular';
const shouldEnforceCoverageGate = process.env['COVERAGE_GATE'] === '1'; const shouldEnforceCoverageGate = process.env['COVERAGE_GATE'] === '1';
export default defineConfig({ export default defineConfig({
plugins: [angular({tsconfig: 'tsconfig.spec.json'})],
test: { test: {
globals: true, pool: 'threads',
environment: 'jsdom', maxWorkers: '50%',
isolate: true,
reporters: [
['default', {summary: false}],
['junit', {outputFile: 'test-results/vitest-results.xml'}]
],
coverage: { coverage: {
provider: 'v8',
reporter: ['text', 'html', 'json', 'json-summary', 'lcov'],
reportsDirectory: 'coverage/grimmory',
include: ['src/app/**/*.ts', 'src/main.ts'],
exclude: ['src/app/**/*.spec.ts', 'src/app/**/*.module.ts', 'src/**/*.d.ts'],
thresholds: shouldEnforceCoverageGate ? { thresholds: shouldEnforceCoverageGate ? {
statements: 90, statements: 90,
branches: 90, branches: 90,
-10
View File
@@ -1,10 +0,0 @@
import {defineConfig, mergeConfig} from 'vitest/config';
import baseConfig from './vitest-base.config';
export default mergeConfig(baseConfig, defineConfig({
test: {
include: ['src/**/*.spec.ts'],
setupFiles: ['./src/test-setup.ts'],
}
}));
+49 -513
View File
File diff suppressed because it is too large Load Diff