Skip to content

Commit d903af7

Browse files
committed
vitest for core
1 parent c430039 commit d903af7

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

libs/core/project.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"sourceRoot": "libs/core/src",
55
"prefix": "platform",
6-
"tags": [],
76
"projectType": "library",
7+
"tags": [],
88
"targets": {
99
"build": {
1010
"executor": "@nx/angular:package",
@@ -61,11 +61,7 @@
6161
}
6262
},
6363
"test": {
64-
"executor": "@nx/jest:jest",
65-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
66-
"options": {
67-
"jestConfig": "libs/core/jest.config.ts"
68-
}
64+
"executor": "@analogjs/vitest-angular:test"
6965
},
7066
"lint": {
7167
"executor": "@nx/eslint:lint",

libs/core/src/test-setup.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
2-
globalThis.ngJest = {
3-
testEnvironmentOptions: {
4-
errorOnUnknownElements: true,
5-
errorOnUnknownProperties: true,
6-
},
7-
};
8-
import 'jest-preset-angular/setup-jest';
1+
import '@analogjs/vitest-angular/setup-zone';
2+
3+
import { getTestBed } from '@angular/core/testing';
4+
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
5+
6+
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());

libs/core/tsconfig.spec.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc",
5-
"module": "commonjs",
65
"target": "es2016",
7-
"types": ["jest", "node"]
6+
"types": ["node", "vitest/globals"]
87
},
98
"files": ["src/test-setup.ts"],
10-
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
9+
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
1110
}

libs/core/vite.config.mts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference types="vitest" />
2+
3+
import angular from '@analogjs/vite-plugin-angular';
4+
5+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
6+
7+
import { defineConfig } from 'vite';
8+
9+
// https://vitejs.dev/config/
10+
export default defineConfig(({ mode }) => {
11+
return {
12+
plugins: [angular(), nxViteTsPaths()],
13+
test: {
14+
globals: true,
15+
environment: 'jsdom',
16+
setupFiles: ['src/test-setup.ts'],
17+
include: ['**/*.spec.ts'],
18+
reporters: ['default'],
19+
},
20+
define: {
21+
'import.meta.vitest': mode !== 'production',
22+
},
23+
};
24+
});

0 commit comments

Comments
 (0)