Skip to content

Commit c09b5b0

Browse files
committed
test(): analog vitest
1 parent 32ad0e0 commit c09b5b0

File tree

10 files changed

+280
-447
lines changed

10 files changed

+280
-447
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ package-lock.json
5151
npm-shrinkwrap.json
5252

5353
__screenshots__/
54+
55+
vite.config.*.timestamp*

apps/forms/62-crossfield-validation-signal-form/project.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@
6464
"lint": {
6565
"executor": "@nx/eslint:lint"
6666
},
67-
"test": {
67+
"ng-test": {
6868
"executor": "@angular/build:unit-test",
6969
"options": {
7070
"runnerConfig": "apps/forms/62-crossfield-validation-signal-form/vitest-base.config.ts"
7171
}
7272
},
73+
"test": {
74+
"executor": "@analogjs/vitest-angular:test"
75+
},
7376
"serve-static": {
7477
"continuous": true,
7578
"executor": "@nx/web:file-server",

apps/forms/62-crossfield-validation-signal-form/src/app/app.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('AppComponent', () => {
88
});
99

1010
describe('When component is rendered', () => {
11-
it('Then should display the form title', async () => {
11+
it.only('Then should display the form title', async () => {
1212
const heading = page.getByRole('heading', {
1313
name: /registration form/i,
1414
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import '@analogjs/vitest-angular/setup-snapshots';
2+
import { setupTestBed } from '@analogjs/vitest-angular/setup-testbed';
3+
import '@angular/compiler';
4+
5+
setupTestBed({
6+
browserMode: true, // Enables visual test preview
7+
});

apps/forms/62-crossfield-validation-signal-form/src/test-setup/no-teardown.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "../../../dist/out-tsc",
5-
"types": ["vitest/globals"]
4+
"outDir": "./out-tsc/spec",
5+
"target": "es2022",
6+
"types": ["vitest/globals", "node"]
67
},
7-
"include": ["src/**/*.ts", "src/**/*.d.ts"]
8+
"files": ["src/test-setup.ts"],
9+
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
810
}

apps/forms/62-crossfield-validation-signal-form/vitest-base.config.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defineConfig } from 'vite';
2+
3+
import angular from '@analogjs/vite-plugin-angular';
4+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
5+
import { playwright } from '@vitest/browser-playwright';
6+
7+
export default defineConfig(({ mode }) => ({
8+
plugins: [angular(), nxViteTsPaths()],
9+
test: {
10+
globals: true,
11+
setupFiles: ['src/test-setup.ts'],
12+
// environment: 'jsdom',
13+
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
14+
reporters: ['default'],
15+
// Vitest browser config
16+
browser: {
17+
enabled: true,
18+
headless: false, // set to true in CI
19+
provider: playwright(),
20+
instances: [{ browser: 'chromium' }],
21+
},
22+
},
23+
}));

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"ng": "nx",
77
"start": "nx serve",
88
"build": "nx build",
9-
"test": "nx test",
9+
"test": "nx test forms-crossfield-validation-signal-form --ui --watch",
1010
"prepare": "husky install",
1111
"doc:dev": "cd docs && pnpm exec pnpm run dev",
12-
"preinstall": "npx only-allow pnpm"
12+
"preinstall": "npx only-allow pnpm",
13+
"postinstall": "playwright install chromium"
1314
},
1415
"engines": {
1516
"node": ">=20.19.6"
@@ -44,6 +45,7 @@
4445
"zone.js": "0.16.0"
4546
},
4647
"devDependencies": {
48+
"@analogjs/vite-plugin-angular": "^2.2.3",
4749
"@analogjs/vitest-angular": "^2.2.3",
4850
"@angular-devkit/build-angular": "21.1.0",
4951
"@angular-devkit/core": "21.1.0",
@@ -67,6 +69,7 @@
6769
"@nx/jest": "22.3.1",
6870
"@nx/js": "22.3.1",
6971
"@nx/plugin": "22.3.1",
72+
"@nx/vite": "22.3.1",
7073
"@nx/web": "22.3.1",
7174
"@nx/workspace": "22.3.1",
7275
"@schematics/angular": "21.1.0",
@@ -84,8 +87,9 @@
8487
"@typescript-eslint/eslint-plugin": "7.16.1",
8588
"@typescript-eslint/parser": "7.16.1",
8689
"@typescript-eslint/utils": "^7.16.0",
87-
"@vitest/browser-playwright": "^4.0.16",
88-
"@vitest/browser-preview": "^4.0.16",
90+
"@vitest/browser-playwright": "4.0.18",
91+
"@vitest/browser-preview": "4.0.18",
92+
"@vitest/ui": "4.0.18",
8993
"all-contributors-cli": "^6.26.1",
9094
"autoprefixer": "^10.4.0",
9195
"cypress": "15.8.1",
@@ -98,11 +102,13 @@
98102
"jest-environment-jsdom": "30.0.5",
99103
"jest-preset-angular": "16.0.0",
100104
"jest-util": "~30.0.0",
105+
"jiti": "2.4.2",
101106
"jsdom": "^27.1.0",
102107
"jsonc-eslint-parser": "^2.1.0",
103108
"lint-staged": "^13.0.3",
104109
"ng-packagr": "21.0.1",
105110
"nx": "22.3.1",
111+
"playwright": "1.58.2",
106112
"postcss": "^8.4.5",
107113
"postcss-import": "~14.1.0",
108114
"postcss-preset-env": "~7.5.0",
@@ -114,7 +120,8 @@
114120
"ts-jest": "29.4.6",
115121
"ts-node": "10.9.1",
116122
"typescript": "5.9.3",
117-
"vitest": "^4.0.8"
123+
"vite": "7.3.1",
124+
"vitest": "4.0.18"
118125
},
119126
"overrides": {
120127
"chokidar": "4.0.1",

0 commit comments

Comments
 (0)