Skip to content

Commit d63dd34

Browse files
committed
chore(router-store): setup and configure vitest
1 parent 66ff495 commit d63dd34

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed

modules/router-store/project.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@
4343
"outputs": ["{options.outputFile}"]
4444
},
4545
"test": {
46-
"executor": "@nx/jest:jest",
47-
"options": {
48-
"jestConfig": "modules/router-store/jest.config.ts",
49-
"runInBand": true,
50-
"passWithNoTests": false
51-
},
46+
"executor": "@analogjs/vitest-angular:test",
47+
"dependsOn": ["build"],
5248
"outputs": ["{workspaceRoot}/coverage/modules/router-store"]
5349
}
5450
}

modules/router-store/test-setup.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,33 @@
1-
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
1+
import {
2+
TextEncoder as NodeTextEncoder,
3+
TextDecoder as NodeTextDecoder,
4+
} from 'util';
25

3-
setupZoneTestEnv();
4-
Object.assign(global, { TextDecoder, TextEncoder });
6+
// Only assign if not already defined, using type assertion to satisfy TypeScript
7+
if (typeof globalThis.TextEncoder === 'undefined') {
8+
globalThis.TextEncoder = NodeTextEncoder as unknown as {
9+
new (): TextEncoder;
10+
prototype: TextEncoder;
11+
};
12+
}
13+
14+
if (typeof globalThis.TextDecoder === 'undefined') {
15+
globalThis.TextDecoder = NodeTextDecoder as unknown as {
16+
new (): TextDecoder;
17+
prototype: TextDecoder;
18+
};
19+
}
20+
21+
import '@angular/compiler';
22+
import '@analogjs/vitest-angular/setup-zone';
23+
24+
import {
25+
BrowserTestingModule,
26+
platformBrowserTesting,
27+
} from '@angular/platform-browser/testing';
28+
import { getTestBed } from '@angular/core/testing';
29+
30+
getTestBed().initTestEnvironment(
31+
BrowserTestingModule,
32+
platformBrowserTesting()
33+
);

modules/router-store/tsconfig.schematics.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"rootDir": ".",
55
"stripInternal": true,
66
"experimentalDecorators": true,
7-
"module": "preserve",
8-
"moduleResolution": "bundler",
7+
"module": "nodenext",
8+
"target": "es2022",
9+
"moduleResolution": "nodenext",
910
"downlevelIteration": true,
1011
"outDir": "../../dist/modules/router-store",
1112
"paths": {

modules/router-store/tsconfig.spec.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc",
5-
"module": "commonjs",
6-
"types": ["jest", "node"],
5+
"module": "es2022",
6+
"types": ["node", "vitest", "vitest/globals"],
77
"target": "es2016"
88
},
99
"files": ["test-setup.ts"],
10-
"include": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts", "**/*.d.ts"]
10+
"include": ["**/*.spec.ts", "**/*.test.ts", "**/*.d.ts"]
1111
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
root: __dirname,
13+
plugins: [
14+
angular(),
15+
nxViteTsPaths(),
16+
],
17+
test: {
18+
globals: true,
19+
pool: 'forks',
20+
environment: 'jsdom',
21+
setupFiles: ['test-setup.ts'],
22+
include: ['**/*.spec.ts'],
23+
reporters: ['default']
24+
},
25+
define: {
26+
'import.meta.vitest': mode !== 'production',
27+
},
28+
};
29+
});

0 commit comments

Comments
 (0)