perf(tests): use Angular recommended test config (#2632)
This commit is contained in:
+13
-1
@@ -136,7 +136,19 @@
|
||||
"test": {
|
||||
"builder": "@angular/build:unit-test",
|
||||
"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": {
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
"uuid": "^14.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@analogjs/vite-plugin-angular": "^2.6.4",
|
||||
"@angular-devkit/architect": "^0.2201.4",
|
||||
"@angular-devkit/schematics": "^22.1.4",
|
||||
"@angular/build": "22.1.4",
|
||||
@@ -69,10 +68,9 @@
|
||||
"@openng/optimus-ui-tailwindcss": "^2.0.1",
|
||||
"@playwright/test": "^1.62.1",
|
||||
"@tailwindcss/postcss": "^4.3.3",
|
||||
"@testing-library/jest-dom": "^7.0.1",
|
||||
"@types/markdown-it": "^14.1.2",
|
||||
"@types/node": "^24.13.2",
|
||||
"@vitest/coverage-v8": "^5.0.0",
|
||||
"@vitest/coverage-v8": "^4.1.11",
|
||||
"angular-eslint": "^22.1.0",
|
||||
"eslint": "^10.9.1",
|
||||
"jsdom": "^30.0.1",
|
||||
@@ -83,7 +81,6 @@
|
||||
"tailwindcss": "^4.3.3",
|
||||
"typescript": "~6.0.3",
|
||||
"typescript-eslint": "^8.67.0",
|
||||
"vitest": "^4.1.11",
|
||||
"vitest-canvas-mock": "^1.1.4"
|
||||
"vitest": "^4.1.11"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}}
|
||||
);
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts",
|
||||
"src/test-setup.ts"
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
import {defineConfig} from 'vitest/config';
|
||||
import angular from '@analogjs/vite-plugin-angular';
|
||||
|
||||
const shouldEnforceCoverageGate = process.env['COVERAGE_GATE'] === '1';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [angular({tsconfig: 'tsconfig.spec.json'})],
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'jsdom',
|
||||
isolate: true,
|
||||
reporters: [
|
||||
['default', {summary: false}],
|
||||
['junit', {outputFile: 'test-results/vitest-results.xml'}]
|
||||
],
|
||||
pool: 'threads',
|
||||
maxWorkers: '50%',
|
||||
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 ? {
|
||||
statements: 90,
|
||||
branches: 90,
|
||||
|
||||
@@ -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'],
|
||||
}
|
||||
}));
|
||||
Generated
+49
-513
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user