Skip to content

Commit c430039

Browse files
committed
use vitest for soba
1 parent d3c141f commit c430039

File tree

7 files changed

+78
-19
lines changed

7 files changed

+78
-19
lines changed
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1+
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
12
import { NgtTestBed } from 'angular-three/testing';
3+
import { ExtrudeGeometry, Mesh } from 'three';
24
import { NgtsPrismGeometry } from './prism-geometry';
35

46
describe(NgtsPrismGeometry.name, () => {
7+
@Component({
8+
standalone: true,
9+
template: `
10+
<ngt-mesh>
11+
<ngts-prism-geometry
12+
[vertices]="[
13+
[0, 0, 0],
14+
[1, 0, 0],
15+
[0, 1, 0],
16+
[0, 0, 1],
17+
]"
18+
/>
19+
</ngt-mesh>
20+
`,
21+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
22+
imports: [NgtsPrismGeometry],
23+
})
24+
class SceneGraph {}
25+
526
it('should render properly', async () => {
6-
const { scene } = NgtTestBed.create(NgtsPrismGeometry);
27+
const { scene, fixture } = NgtTestBed.create(SceneGraph);
28+
fixture.detectChanges();
29+
30+
expect(scene.children.length).toEqual(1);
31+
const mesh = scene.children[0] as Mesh<ExtrudeGeometry>;
732

8-
expect(true).toBe(true);
33+
expect(mesh.geometry.type).toEqual('ExtrudeGeometry');
934
});
1035
});

libs/soba/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/soba/src",
55
"prefix": "platform",
6-
"tags": [],
76
"projectType": "library",
7+
"tags": [],
88
"targets": {
99
"build": {
1010
"executor": "@nx/angular:package",
@@ -35,11 +35,7 @@
3535
}
3636
},
3737
"test": {
38-
"executor": "@nx/jest:jest",
39-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
40-
"options": {
41-
"jestConfig": "libs/soba/jest.config.ts"
42-
}
38+
"executor": "@analogjs/vitest-angular:test"
4339
},
4440
"lint": {
4541
"executor": "@nx/eslint:lint",

libs/soba/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/soba/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/soba/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+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"devDependencies": {
1919
"@analogjs/platform": "^1.6.4-beta.1",
2020
"@analogjs/vite-plugin-angular": "^1.6.4-beta.1",
21+
"@analogjs/vitest-angular": "^1.5.0",
2122
"@angular-devkit/build-angular": "18.1.2",
2223
"@angular-devkit/core": "18.1.2",
2324
"@angular-devkit/schematics": "18.1.2",

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)