vitest-browser-angular 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -8
- package/dist/index-B6AjE_kw.d.ts +10 -0
- package/dist/index.js +10 -40
- package/dist/pure-BCQUoZ4o.js +39 -0
- package/dist/pure-CDpj4kF8.d.ts +2 -0
- package/dist/pure-CheJC9ys.d.ts +34 -0
- package/dist/pure.js +3 -0
- package/dist/{setup-RnZmQ_2I.js → setup-DUx6xbqk.js} +1 -1
- package/dist/setup-zones.js +1 -1
- package/dist/setup.js +1 -1
- package/package.json +5 -5
- package/dist/index.d.ts +0 -32
- /package/dist/{setup.d.ts → setup-C5tF0VaY.d.ts} +0 -0
- /package/dist/{setup-zones.d.ts → setup-zones-CB3nb_2d.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# vitest-browser-angular
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Render Angular components in VItest Browser Mode.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -13,6 +13,8 @@ pnpm add -D vitest-browser-angular
|
|
|
13
13
|
```ts
|
|
14
14
|
// vitest.config.ts
|
|
15
15
|
|
|
16
|
+
import { playwright } from '@vitest/browser-playwright';
|
|
17
|
+
|
|
16
18
|
export default defineConfig({
|
|
17
19
|
test: {
|
|
18
20
|
globals: true,
|
|
@@ -22,7 +24,7 @@ export default defineConfig({
|
|
|
22
24
|
|
|
23
25
|
browser: {
|
|
24
26
|
enabled: true,
|
|
25
|
-
provider:
|
|
27
|
+
provider: playwright(),
|
|
26
28
|
instances: [{ browser: 'chromium' }],
|
|
27
29
|
},
|
|
28
30
|
},
|
|
@@ -36,8 +38,8 @@ TBD
|
|
|
36
38
|
## Usage
|
|
37
39
|
|
|
38
40
|
```ts
|
|
39
|
-
|
|
40
41
|
import { test, expect } from 'vitest-browser-angular';
|
|
42
|
+
import { render } from 'vitest-browser-angular';
|
|
41
43
|
|
|
42
44
|
@Component({
|
|
43
45
|
template: '<h1>{{ title }}</h1>',
|
|
@@ -46,13 +48,104 @@ export class HelloWorldComponent {
|
|
|
46
48
|
title = 'Hello World';
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const { component } = await mount(HelloWorldComponent);
|
|
51
|
+
test('render', async () => {
|
|
52
|
+
const { component } = await render(HelloWorldComponent);
|
|
52
53
|
await expect.element(component).toHaveTextContent('Hello World');
|
|
53
54
|
});
|
|
54
55
|
```
|
|
55
56
|
|
|
57
|
+
## Routing
|
|
58
|
+
|
|
59
|
+
### Simple Routing
|
|
60
|
+
|
|
61
|
+
Enable routing with `withRouting: true` for components that use routing features but don't require specific route configuration:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { test, expect } from 'vitest';
|
|
65
|
+
import { render } from 'vitest-browser-angular';
|
|
66
|
+
import { Component } from '@angular/core';
|
|
67
|
+
import { RouterLink, RouterOutlet } from '@angular/router';
|
|
68
|
+
|
|
69
|
+
@Component({
|
|
70
|
+
template: `
|
|
71
|
+
<nav>
|
|
72
|
+
<a routerLink="/home">Home</a>
|
|
73
|
+
<a routerLink="/about">About</a>
|
|
74
|
+
</nav>
|
|
75
|
+
<router-outlet></router-outlet>
|
|
76
|
+
`,
|
|
77
|
+
imports: [RouterLink, RouterOutlet],
|
|
78
|
+
})
|
|
79
|
+
export class RoutedComponent {}
|
|
80
|
+
|
|
81
|
+
test('render with simple routing', async () => {
|
|
82
|
+
const { component } = await render(RoutedComponent, {
|
|
83
|
+
withRouting: true,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
await expect.element(component).toHaveTextContent('Home');
|
|
87
|
+
await expect.element(component).toHaveTextContent('About');
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Routing with Configuration
|
|
92
|
+
|
|
93
|
+
Configure specific routes and optionally set an initial route:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { test, expect } from 'vitest';
|
|
97
|
+
import { render } from 'vitest-browser-angular';
|
|
98
|
+
import { Component, inject } from '@angular/core';
|
|
99
|
+
import { Router, RouterLink, RouterOutlet, Routes } from '@angular/router';
|
|
100
|
+
|
|
101
|
+
@Component({
|
|
102
|
+
template: '<h1>Home Page</h1>',
|
|
103
|
+
})
|
|
104
|
+
export class HomeComponent {}
|
|
105
|
+
|
|
106
|
+
@Component({
|
|
107
|
+
template: '<h1>About Page</h1>',
|
|
108
|
+
standalone: true,
|
|
109
|
+
})
|
|
110
|
+
export class AboutComponent {}
|
|
111
|
+
|
|
112
|
+
@Component({
|
|
113
|
+
template: `
|
|
114
|
+
<nav>
|
|
115
|
+
<a routerLink="/home">Home</a>
|
|
116
|
+
<a routerLink="/about">About</a>
|
|
117
|
+
</nav>
|
|
118
|
+
<router-outlet></router-outlet>
|
|
119
|
+
`,
|
|
120
|
+
imports: [RouterLink, RouterOutlet],
|
|
121
|
+
standalone: true,
|
|
122
|
+
})
|
|
123
|
+
export class AppComponent {
|
|
124
|
+
router = inject(Router);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const routes: Routes = [
|
|
128
|
+
{ path: 'home', component: HomeComponent },
|
|
129
|
+
{ path: 'about', component: AboutComponent },
|
|
130
|
+
{ path: '', redirectTo: '/home', pathMatch: 'full' },
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
test('render with route configuration', async () => {
|
|
134
|
+
const { component, router } = await render(AppComponent, {
|
|
135
|
+
withRouting: {
|
|
136
|
+
routes,
|
|
137
|
+
initialRoute: '/home',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
await expect.element(component).toHaveTextContent('Home Page');
|
|
142
|
+
|
|
143
|
+
// Navigate programmatically
|
|
144
|
+
await router.navigate(['/about']);
|
|
145
|
+
await expect.element(component).toHaveTextContent('About Page');
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
56
149
|
## Contributing
|
|
57
150
|
|
|
58
151
|
Want to contribute? Yayy! 🎉
|
|
@@ -69,7 +162,6 @@ Be kind to each other and please read our [code of conduct](CODE_OF_CONDUCT.md).
|
|
|
69
162
|
|
|
70
163
|
<br/>
|
|
71
164
|
|
|
72
|
-
|
|
73
165
|
## Credits
|
|
74
166
|
|
|
75
167
|
This project is inspired by the following projects:
|
|
@@ -79,4 +171,4 @@ This project is inspired by the following projects:
|
|
|
79
171
|
|
|
80
172
|
## License
|
|
81
173
|
|
|
82
|
-
MIT
|
|
174
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { i as render, n as RenderResult, r as cleanup, t as RenderFn } from "./pure-CheJC9ys.js";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare module "vitest/browser" {
|
|
5
|
+
interface BrowserPage {
|
|
6
|
+
render: typeof render;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { type RenderFn, type RenderResult, cleanup, render };
|
package/dist/index.js
CHANGED
|
@@ -1,45 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { page } from "@vitest/browser/context";
|
|
5
|
-
import { test as test$1 } from "vitest";
|
|
6
|
-
|
|
7
|
-
export * from "vitest"
|
|
1
|
+
import { n as render, t as cleanup } from "./pure-BCQUoZ4o.js";
|
|
2
|
+
import { beforeEach } from "vitest";
|
|
3
|
+
import { page } from "vitest/browser";
|
|
8
4
|
|
|
9
5
|
//#region src/index.ts
|
|
10
|
-
page.extend({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
await use(async (componentClass, config) => {
|
|
17
|
-
const imports = [componentClass, ...config?.imports || []];
|
|
18
|
-
const providers = [...config?.providers || []];
|
|
19
|
-
const mountResult = {};
|
|
20
|
-
if (config?.withRouting) providers.push(provideRouter(config.withRouting.routes));
|
|
21
|
-
TestBed.configureTestingModule({
|
|
22
|
-
imports,
|
|
23
|
-
providers
|
|
24
|
-
});
|
|
25
|
-
if (config?.withRouting) {
|
|
26
|
-
const routerHarness = await RouterTestingHarness.create(config.withRouting.initialRoute);
|
|
27
|
-
mountResult.routerHarness = routerHarness;
|
|
28
|
-
mountResult.router = TestBed.inject(Router);
|
|
29
|
-
}
|
|
30
|
-
const fixture = TestBed.createComponent(componentClass);
|
|
31
|
-
fixture.autoDetectChanges();
|
|
32
|
-
await fixture.whenStable();
|
|
33
|
-
const component = page$1.elementLocator(fixture.nativeElement);
|
|
34
|
-
return {
|
|
35
|
-
...mountResult,
|
|
36
|
-
fixture,
|
|
37
|
-
componentClassInstance: fixture.componentInstance,
|
|
38
|
-
component
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
}
|
|
6
|
+
page.extend({
|
|
7
|
+
render,
|
|
8
|
+
[Symbol.for("vitest:component-cleanup")]: cleanup
|
|
9
|
+
});
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
await cleanup(true);
|
|
42
12
|
});
|
|
43
13
|
|
|
44
14
|
//#endregion
|
|
45
|
-
export {
|
|
15
|
+
export { cleanup, render };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { page } from "vitest/browser";
|
|
2
|
+
import { TestBed, ɵgetCleanupHook } from "@angular/core/testing";
|
|
3
|
+
import { Router, provideRouter } from "@angular/router";
|
|
4
|
+
import { RouterTestingHarness } from "@angular/router/testing";
|
|
5
|
+
|
|
6
|
+
//#region src/pure.ts
|
|
7
|
+
async function render(componentClass, config) {
|
|
8
|
+
const imports = [componentClass, ...config?.imports || []];
|
|
9
|
+
const providers = [...config?.providers || []];
|
|
10
|
+
const renderResult = {};
|
|
11
|
+
if (config?.withRouting) {
|
|
12
|
+
const routes = typeof config.withRouting === "boolean" ? [] : config.withRouting.routes;
|
|
13
|
+
providers.push(provideRouter(routes));
|
|
14
|
+
}
|
|
15
|
+
TestBed.configureTestingModule({
|
|
16
|
+
imports,
|
|
17
|
+
providers
|
|
18
|
+
});
|
|
19
|
+
if (config?.withRouting) {
|
|
20
|
+
renderResult.routerHarness = await RouterTestingHarness.create(typeof config.withRouting === "boolean" ? void 0 : config.withRouting.initialRoute);
|
|
21
|
+
renderResult.router = TestBed.inject(Router);
|
|
22
|
+
}
|
|
23
|
+
const fixture = TestBed.createComponent(componentClass);
|
|
24
|
+
fixture.autoDetectChanges();
|
|
25
|
+
await fixture.whenStable();
|
|
26
|
+
const component = page.elementLocator(fixture.nativeElement);
|
|
27
|
+
return {
|
|
28
|
+
...renderResult,
|
|
29
|
+
fixture,
|
|
30
|
+
componentClassInstance: fixture.componentInstance,
|
|
31
|
+
component
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function cleanup(shouldTearndown = false) {
|
|
35
|
+
return ɵgetCleanupHook(shouldTearndown)();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { render as n, cleanup as t };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Locator } from "vitest/browser";
|
|
2
|
+
import { ComponentFixture } from "@angular/core/testing";
|
|
3
|
+
import { Router, Routes } from "@angular/router";
|
|
4
|
+
import { RouterTestingHarness } from "@angular/router/testing";
|
|
5
|
+
import { EnvironmentProviders, Provider, Type } from "@angular/core";
|
|
6
|
+
|
|
7
|
+
//#region src/pure.d.ts
|
|
8
|
+
interface RoutingConfig {
|
|
9
|
+
routes: Routes;
|
|
10
|
+
initialRoute?: string;
|
|
11
|
+
}
|
|
12
|
+
interface RenderConfig {
|
|
13
|
+
withRouting?: RoutingConfig | boolean;
|
|
14
|
+
providers?: Array<Provider | EnvironmentProviders>;
|
|
15
|
+
imports?: unknown[];
|
|
16
|
+
}
|
|
17
|
+
interface RenderResult<T> {
|
|
18
|
+
fixture: ComponentFixture<T>;
|
|
19
|
+
component: Locator;
|
|
20
|
+
componentClassInstance: T;
|
|
21
|
+
routerHarness?: RouterTestingHarness;
|
|
22
|
+
router?: Router;
|
|
23
|
+
}
|
|
24
|
+
type RenderFn = <T>(component: Type<T>, config?: RenderConfig) => Promise<RenderResult<T>>;
|
|
25
|
+
declare function render<T>(componentClass: Type<T>, config?: RenderConfig): Promise<{
|
|
26
|
+
fixture: ComponentFixture<T>;
|
|
27
|
+
componentClassInstance: T;
|
|
28
|
+
component: Locator;
|
|
29
|
+
routerHarness?: RouterTestingHarness | undefined;
|
|
30
|
+
router?: Router | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
declare function cleanup(shouldTearndown?: boolean): void;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { render as i, RenderResult as n, cleanup as r, RenderFn as t };
|
package/dist/pure.js
ADDED
package/dist/setup-zones.js
CHANGED
package/dist/setup.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-browser-angular",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Render Angular components in VItest Browser Mode",
|
|
5
5
|
"author": "Shai Reznik (HiRez.io)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/hirezio/vitest-browser-angular#readme",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@angular/platform-browser": "^20.0.0",
|
|
48
48
|
"@angular/router": "^20.0.0",
|
|
49
49
|
"@vitest/browser": "^2.1.0 || ^3.0.0 || ^4.0.0-0",
|
|
50
|
-
"vitest": "^2.1.0 || ^3.0.0 || ^4.0.0
|
|
50
|
+
"vitest": "^2.1.0 || ^3.0.0 || ^4.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@analogjs/vitest-angular": "^1.20.2",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"@changesets/types": "^6.1.0",
|
|
61
61
|
"@eslint/js": "^9.35.0",
|
|
62
62
|
"@vitest/browser": "^3.2.0",
|
|
63
|
+
"@vitest/browser-playwright": "^4.0.0",
|
|
63
64
|
"bumpp": "^9.4.2",
|
|
64
65
|
"changelogithub": "^0.13.9",
|
|
65
66
|
"dotenv": "^17.2.2",
|
|
@@ -71,11 +72,10 @@
|
|
|
71
72
|
"pretty-quick": "^4.2.2",
|
|
72
73
|
"simple-git-hooks": "^2.13.1",
|
|
73
74
|
"tsdown": "^0.14.2",
|
|
74
|
-
"tsup": "^8.2.4",
|
|
75
75
|
"tsx": "^4.17.0",
|
|
76
76
|
"typescript": "^5.5.4",
|
|
77
77
|
"typescript-eslint": "^8.42.0",
|
|
78
|
-
"vitest": "^
|
|
78
|
+
"vitest": "^4.0.0",
|
|
79
79
|
"zone.js": "^0.15.1",
|
|
80
80
|
"zx": "^8.1.4"
|
|
81
81
|
},
|
package/dist/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ComponentFixture } from "@angular/core/testing";
|
|
2
|
-
import { Router, Routes } from "@angular/router";
|
|
3
|
-
import { RouterTestingHarness } from "@angular/router/testing";
|
|
4
|
-
import { BrowserPage, Locator } from "@vitest/browser/context";
|
|
5
|
-
import * as vitest0 from "vitest";
|
|
6
|
-
import { EnvironmentProviders, Provider, Type } from "@angular/core";
|
|
7
|
-
export * from "vitest";
|
|
8
|
-
|
|
9
|
-
//#region src/index.d.ts
|
|
10
|
-
interface RoutingConfig {
|
|
11
|
-
routes: Routes;
|
|
12
|
-
initialRoute?: string;
|
|
13
|
-
}
|
|
14
|
-
interface MountConfig {
|
|
15
|
-
withRouting?: RoutingConfig;
|
|
16
|
-
providers?: Array<Provider | EnvironmentProviders>;
|
|
17
|
-
imports?: unknown[];
|
|
18
|
-
}
|
|
19
|
-
interface MountResult<T> {
|
|
20
|
-
fixture: ComponentFixture<T>;
|
|
21
|
-
component: Locator;
|
|
22
|
-
componentClassInstance: T;
|
|
23
|
-
routerHarness?: RouterTestingHarness;
|
|
24
|
-
router?: Router;
|
|
25
|
-
}
|
|
26
|
-
type MountFn = <T>(component: Type<T>, config?: MountConfig) => Promise<MountResult<T>>;
|
|
27
|
-
declare const test: vitest0.TestAPI<{
|
|
28
|
-
page: BrowserPage;
|
|
29
|
-
mount: MountFn;
|
|
30
|
-
}>;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { MountFn, MountResult, test };
|
|
File without changes
|
|
File without changes
|