vitest-browser-angular 0.0.0 → 0.0.2
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/LICENSE +21 -0
- package/README.md +101 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -2
- package/package.json +22 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 HiRez.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,3 +2,104 @@
|
|
|
2
2
|
|
|
3
3
|
Mount Angular components in VItest Browser Mode.
|
|
4
4
|
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D vitest-browser-angular
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup Test Environment with Zone.js
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// vitest.config.ts
|
|
15
|
+
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
test: {
|
|
18
|
+
globals: true,
|
|
19
|
+
|
|
20
|
+
// 👇 This is what you need to add
|
|
21
|
+
setupFiles: ['vitest-browser-angular/setup-zones'],
|
|
22
|
+
|
|
23
|
+
browser: {
|
|
24
|
+
enabled: true,
|
|
25
|
+
provider: 'playwright',
|
|
26
|
+
instances: [{ browser: 'chromium' }],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Setup Test Environment with Zoneless
|
|
33
|
+
|
|
34
|
+
TBD
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
|
|
40
|
+
import { test, expect } from 'vitest-browser-angular';
|
|
41
|
+
|
|
42
|
+
@Component({
|
|
43
|
+
template: '<h1>{{ title }}</h1>',
|
|
44
|
+
})
|
|
45
|
+
export class HelloWorldComponent {
|
|
46
|
+
title = 'Hello World';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
test('mount', async ({ mount }) => {
|
|
51
|
+
const { component } = await mount(HelloWorldComponent);
|
|
52
|
+
await expect.element(component).toHaveTextContent('Hello World');
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Extending Vitest Context
|
|
57
|
+
|
|
58
|
+
If you want to extend the library's test context (fixtures) like this:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { test as testBase } from 'vitest-browser-angular'
|
|
62
|
+
|
|
63
|
+
export const test = testBase.extend(...)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Make sure you add `vitest-browser-angular` to the `types` array in your `tsconfig.json`
|
|
67
|
+
|
|
68
|
+
If it doesn't work, you probably forgot to add `@vitest/browser` to the `types` array as well.
|
|
69
|
+
|
|
70
|
+
**Example:**
|
|
71
|
+
```json
|
|
72
|
+
|
|
73
|
+
"types": [
|
|
74
|
+
"@vitest/browser",
|
|
75
|
+
"vitest-browser-angular"
|
|
76
|
+
]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
|
|
81
|
+
Want to contribute? Yayy! 🎉
|
|
82
|
+
|
|
83
|
+
Please read and follow our [Contributing Guidelines](CONTRIBUTING.md) to learn what are the right steps to take before contributing your time, effort and code.
|
|
84
|
+
|
|
85
|
+
Thanks 🙏
|
|
86
|
+
|
|
87
|
+
<br/>
|
|
88
|
+
|
|
89
|
+
## Code Of Conduct
|
|
90
|
+
|
|
91
|
+
Be kind to each other and please read our [code of conduct](CODE_OF_CONDUCT.md).
|
|
92
|
+
|
|
93
|
+
<br/>
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## Credits
|
|
97
|
+
|
|
98
|
+
This project is inspired by the following projects:
|
|
99
|
+
|
|
100
|
+
[vitest-browser-vue](https://github.com/vitest-dev/vitest-browser-vue)
|
|
101
|
+
[angular-testing-library](https://github.com/testing-library/angular-testing-library)
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Router, Routes } from "@angular/router";
|
|
|
3
3
|
import { RouterTestingHarness } from "@angular/router/testing";
|
|
4
4
|
import { BrowserPage, Locator } from "@vitest/browser/context";
|
|
5
5
|
import * as vitest0 from "vitest";
|
|
6
|
-
import { Type } from "@angular/core";
|
|
6
|
+
import { EnvironmentProviders, Provider, Type } from "@angular/core";
|
|
7
7
|
export * from "vitest";
|
|
8
8
|
|
|
9
9
|
//#region src/index.d.ts
|
|
@@ -12,9 +12,9 @@ interface RoutingConfig {
|
|
|
12
12
|
initialRoute?: string;
|
|
13
13
|
}
|
|
14
14
|
interface MountConfig {
|
|
15
|
-
withRouting?: RoutingConfig;
|
|
16
|
-
providers?:
|
|
17
|
-
imports?:
|
|
15
|
+
withRouting?: RoutingConfig | boolean;
|
|
16
|
+
providers?: Array<Provider | EnvironmentProviders>;
|
|
17
|
+
imports?: unknown[];
|
|
18
18
|
}
|
|
19
19
|
interface MountResult<T> {
|
|
20
20
|
fixture: ComponentFixture<T>;
|
package/dist/index.js
CHANGED
|
@@ -17,13 +17,16 @@ const test = test$1.extend({
|
|
|
17
17
|
const imports = [componentClass, ...config?.imports || []];
|
|
18
18
|
const providers = [...config?.providers || []];
|
|
19
19
|
const mountResult = {};
|
|
20
|
-
if (config?.withRouting)
|
|
20
|
+
if (config?.withRouting) {
|
|
21
|
+
const routes = typeof config.withRouting === "boolean" ? [] : config.withRouting.routes;
|
|
22
|
+
providers.push(provideRouter(routes));
|
|
23
|
+
}
|
|
21
24
|
TestBed.configureTestingModule({
|
|
22
25
|
imports,
|
|
23
26
|
providers
|
|
24
27
|
});
|
|
25
28
|
if (config?.withRouting) {
|
|
26
|
-
const routerHarness = await RouterTestingHarness.create(config.withRouting.initialRoute);
|
|
29
|
+
const routerHarness = await RouterTestingHarness.create(typeof config.withRouting === "boolean" ? void 0 : config.withRouting.initialRoute);
|
|
27
30
|
mountResult.routerHarness = routerHarness;
|
|
28
31
|
mountResult.router = TestBed.inject(Router);
|
|
29
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-browser-angular",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Mount Angular components in VItest Browser Mode",
|
|
5
5
|
"author": "Shai Reznik (HiRez.io)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,13 +40,6 @@
|
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"
|
|
42
42
|
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"build": "tsdown",
|
|
45
|
-
"dev": "tsdown --watch --sourcemap",
|
|
46
|
-
"test": "vitest",
|
|
47
|
-
"lint": "eslint --cache .",
|
|
48
|
-
"lint:fix": "pnpm lint --fix"
|
|
49
|
-
},
|
|
50
43
|
"peerDependencies": {
|
|
51
44
|
"@analogjs/vitest-angular": "^1.20.0",
|
|
52
45
|
"@angular/compiler": "^20.0.0",
|
|
@@ -65,11 +58,14 @@
|
|
|
65
58
|
"@changesets/cli": "^2.29.6",
|
|
66
59
|
"@changesets/get-github-info": "^0.6.0",
|
|
67
60
|
"@changesets/types": "^6.1.0",
|
|
61
|
+
"@eslint/js": "^9.35.0",
|
|
68
62
|
"@vitest/browser": "^3.2.0",
|
|
69
63
|
"bumpp": "^9.4.2",
|
|
70
64
|
"changelogithub": "^0.13.9",
|
|
65
|
+
"dotenv": "^17.2.2",
|
|
71
66
|
"eslint": "^9.8.0",
|
|
72
67
|
"eslint-config-prettier": "^10.1.8",
|
|
68
|
+
"globals": "^16.3.0",
|
|
73
69
|
"playwright": "^1.46.0",
|
|
74
70
|
"prettier": "^3.6.2",
|
|
75
71
|
"pretty-quick": "^4.2.2",
|
|
@@ -78,8 +74,25 @@
|
|
|
78
74
|
"tsup": "^8.2.4",
|
|
79
75
|
"tsx": "^4.17.0",
|
|
80
76
|
"typescript": "^5.5.4",
|
|
77
|
+
"typescript-eslint": "^8.42.0",
|
|
81
78
|
"vitest": "^3.2.0",
|
|
82
79
|
"zone.js": "^0.15.1",
|
|
83
80
|
"zx": "^8.1.4"
|
|
81
|
+
},
|
|
82
|
+
"simple-git-hooks": {
|
|
83
|
+
"pre-commit": "pnpm fmt.staged && pnpm lint"
|
|
84
|
+
},
|
|
85
|
+
"scripts": {
|
|
86
|
+
"build": "tsdown",
|
|
87
|
+
"change": "changeset",
|
|
88
|
+
"dev": "tsdown --watch --sourcemap",
|
|
89
|
+
"fmt": "prettier --write .",
|
|
90
|
+
"fmt.check": "prettier --check .",
|
|
91
|
+
"fmt.staged": "pretty-quick --staged",
|
|
92
|
+
"lint": "eslint --cache .",
|
|
93
|
+
"lint:fix": "pnpm lint --fix",
|
|
94
|
+
"release": "changeset publish",
|
|
95
|
+
"release.pkg-pr-new": "pnpm dlx pkg-pr-new publish",
|
|
96
|
+
"test": "vitest"
|
|
84
97
|
}
|
|
85
|
-
}
|
|
98
|
+
}
|