@analogjs/vitest-angular 3.0.0-alpha.1 → 3.0.0-alpha.10
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 +2 -2
- package/_virtual/_@oxc-project_runtime@0.120.0/helpers/decorate.js +9 -0
- package/package.json +8 -8
- package/setup-snapshots.d.ts +18 -18
- package/setup-snapshots.js +71 -95
- package/setup-snapshots.js.map +1 -0
- package/setup-testbed.d.ts +12 -5
- package/setup-testbed.js +23 -24
- package/setup-testbed.js.map +1 -0
- package/setup-zone.d.ts +6 -5
- package/setup-zone.js +90 -105
- package/setup-zone.js.map +1 -0
- package/src/index.d.ts +2 -2
- package/src/index.js +3 -4
- package/src/lib/builders/build/devkit.d.ts +2 -2
- package/src/lib/builders/build/devkit.js +23 -17
- package/src/lib/builders/build/devkit.js.map +1 -0
- package/src/lib/builders/build/plugins/angular-memory-plugin.d.ts +13 -20
- package/src/lib/builders/build/plugins/angular-memory-plugin.js +51 -77
- package/src/lib/builders/build/plugins/angular-memory-plugin.js.map +1 -0
- package/src/lib/builders/build/plugins/downlevel-plugin.d.ts +10 -0
- package/src/lib/builders/build/plugins/downlevel-plugin.js +24 -0
- package/src/lib/builders/build/plugins/downlevel-plugin.js.map +1 -0
- package/src/lib/builders/build/schema.js +53 -0
- package/src/lib/builders/build/schema.js.map +1 -0
- package/src/lib/builders/build/schema.json +44 -44
- package/src/lib/builders/build/utils.d.ts +3 -3
- package/src/lib/builders/build/vitest.impl.d.ts +5 -5
- package/src/lib/builders/build/vitest.impl.js +154 -190
- package/src/lib/builders/build/vitest.impl.js.map +1 -0
- package/src/lib/builders/test/schema.js +51 -0
- package/src/lib/builders/test/schema.js.map +1 -0
- package/src/lib/builders/test/schema.json +44 -44
- package/src/lib/builders/test/vitest.impl.d.ts +1 -1
- package/src/lib/builders/test/vitest.impl.js +48 -58
- package/src/lib/builders/test/vitest.impl.js.map +1 -0
- package/src/lib/tools/package.json +1 -5
- package/src/lib/tools/src/index.d.ts +1 -1
- package/src/lib/tools/src/index.js +3 -6
- package/src/lib/tools/src/schematics/setup/index.d.ts +2 -2
- package/src/lib/tools/src/schematics/setup/index.js +46 -71
- package/src/lib/tools/src/schematics/setup/index.js.map +1 -1
- package/src/lib/tools/src/schematics/utils/angular.d.ts +1 -1
- package/src/lib/tools/src/schematics/utils/angular.js +16 -22
- package/src/lib/tools/src/schematics/utils/angular.js.map +1 -1
- package/src/lib/tools/src/schematics/utils/dependencies.d.ts +2 -2
- package/src/lib/tools/src/schematics/utils/dependencies.js +34 -44
- package/src/lib/tools/src/schematics/utils/dependencies.js.map +1 -1
- package/src/lib/tools/src/schematics/utils/index.d.ts +4 -4
- package/src/lib/tools/src/schematics/utils/index.js +4 -8
- package/src/lib/tools/src/schematics/utils/versions.d.ts +1 -1
- package/src/lib/tools/src/schematics/utils/versions.js +17 -12
- package/src/lib/tools/src/schematics/utils/versions.js.map +1 -1
- package/src/lib/tools/src/schematics/utils/workspace.d.ts +8 -8
- package/src/lib/tools/src/schematics/utils/workspace.js +14 -17
- package/src/lib/tools/src/schematics/utils/workspace.js.map +1 -1
- package/src/lib/tools/src/test-global-setup.d.ts +1 -0
- package/src/lib/builders/build/plugins/esbuild-downlevel-plugin.d.ts +0 -7
- package/src/lib/builders/build/plugins/esbuild-downlevel-plugin.js +0 -23
- package/src/lib/builders/build/utils.js +0 -1
- package/src/lib/tools/src/index.js.map +0 -1
- package/src/lib/tools/src/schematics/utils/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -126,7 +126,7 @@ The `setupTestBed()` function accepts an optional configuration object with the
|
|
|
126
126
|
|
|
127
127
|
- `zoneless` (boolean): Whether to use zoneless change detection (default: `true`)
|
|
128
128
|
- `providers` (`Type<any>[]`): Additional providers to include in the test environment (default: `[]`)
|
|
129
|
-
- `
|
|
129
|
+
- `teardown.destroyAfterEach` (boolean): Whether to destroy the test environment after each test. Set to `false` to keep the component rendered, allowing you to inspect its final state. (default: `true`)
|
|
130
130
|
|
|
131
131
|
**Example with options:**
|
|
132
132
|
|
|
@@ -134,7 +134,7 @@ The `setupTestBed()` function accepts an optional configuration object with the
|
|
|
134
134
|
setupTestBed({
|
|
135
135
|
zoneless: true,
|
|
136
136
|
providers: [],
|
|
137
|
-
|
|
137
|
+
teardown: { destroyAfterEach: false },
|
|
138
138
|
});
|
|
139
139
|
```
|
|
140
140
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.120.0/helpers/decorate.js
|
|
2
|
+
function __decorate(decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { __decorate };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@analogjs/vitest-angular",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.10",
|
|
4
4
|
"description": "Vitest Builder for Angular",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Brandon Roberts <robertsbt@gmail.com>",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
9
|
-
"./package.json": "./package.json",
|
|
10
9
|
"./setup-zone": "./setup-zone.js",
|
|
11
10
|
"./setup-snapshots": "./setup-snapshots.js",
|
|
12
|
-
"./setup-testbed": "./setup-testbed.js"
|
|
11
|
+
"./setup-testbed": "./setup-testbed.js",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"angular",
|
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
"ng-add": {
|
|
36
36
|
"save": "devDependencies"
|
|
37
37
|
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"oxc-transform": "^0.119.0"
|
|
40
|
+
},
|
|
38
41
|
"peerDependencies": {
|
|
39
42
|
"@analogjs/vite-plugin-angular": "*",
|
|
40
43
|
"@angular-devkit/architect": ">=0.1500.0 < 0.2200.0",
|
|
@@ -61,8 +64,5 @@
|
|
|
61
64
|
"publishConfig": {
|
|
62
65
|
"access": "public",
|
|
63
66
|
"provenance": true
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
"module": "./src/index.js",
|
|
67
|
-
"main": "./src/index.js"
|
|
68
|
-
}
|
|
67
|
+
}
|
|
68
|
+
}
|
package/setup-snapshots.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
declare const env: any;
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
* Allows Vitest to handle Angular test fixtures
|
|
4
|
+
*
|
|
5
|
+
* Vitest Snapshot guide ==> https://vitest.dev/guide/snapshot.html
|
|
6
|
+
*
|
|
7
|
+
* @returns customSnapshotSerializer for Angular Fixture Component
|
|
8
|
+
*/
|
|
9
9
|
declare const customSnapshotSerializer: () => {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
serialize: (...args: any[]) => string;
|
|
11
|
+
test: (val: any) => boolean;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
* Check if is an Angular fixture
|
|
15
|
+
*
|
|
16
|
+
* @param val Angular fixture
|
|
17
|
+
* @returns boolean who check if is an angular fixture
|
|
18
|
+
*/
|
|
19
19
|
declare function isAngularFixture(val: any): boolean;
|
|
20
20
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
* Serialize Angular fixture for Vitest
|
|
22
|
+
*
|
|
23
|
+
* @param fixture Angular Fixture Component
|
|
24
|
+
* @returns HTML Child Node
|
|
25
|
+
*/
|
|
26
26
|
declare function fixtureVitestSerializer(fixture: any): ChildNode;
|
package/setup-snapshots.js
CHANGED
|
@@ -1,104 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region packages/vitest-angular/setup-snapshots.ts
|
|
2
|
+
var env = globalThis;
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
test,
|
|
22
|
-
};
|
|
4
|
+
* Allows Vitest to handle Angular test fixtures
|
|
5
|
+
*
|
|
6
|
+
* Vitest Snapshot guide ==> https://vitest.dev/guide/snapshot.html
|
|
7
|
+
*
|
|
8
|
+
* @returns customSnapshotSerializer for Angular Fixture Component
|
|
9
|
+
*/
|
|
10
|
+
var customSnapshotSerializer = () => {
|
|
11
|
+
function serialize(val, config, indentation, depth, refs, printer) {
|
|
12
|
+
return `${printer(fixtureVitestSerializer(val), config, indentation, depth, refs)}`;
|
|
13
|
+
}
|
|
14
|
+
function test(val) {
|
|
15
|
+
return val && isAngularFixture(val);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
serialize,
|
|
19
|
+
test
|
|
20
|
+
};
|
|
23
21
|
};
|
|
24
22
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
* Check if is an Angular fixture
|
|
24
|
+
*
|
|
25
|
+
* @param val Angular fixture
|
|
26
|
+
* @returns boolean who check if is an angular fixture
|
|
27
|
+
*/
|
|
30
28
|
function isAngularFixture(val) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
'location',
|
|
63
|
-
'_rootLView',
|
|
64
|
-
'_tNode',
|
|
65
|
-
'previousInputValues',
|
|
66
|
-
'instance',
|
|
67
|
-
'changeDetectorRef',
|
|
68
|
-
'hostView',
|
|
69
|
-
'componentType',
|
|
70
|
-
];
|
|
71
|
-
return (JSON.stringify(Object.keys(val)) === JSON.stringify(fixtureKeys) ||
|
|
72
|
-
JSON.stringify(Object.keys(val)) === JSON.stringify(fixtureComponentRefKeys));
|
|
29
|
+
if (typeof val !== "object") return false;
|
|
30
|
+
if (val["componentRef"] || val["componentInstance"]) return true;
|
|
31
|
+
if (val["componentType"]) return true;
|
|
32
|
+
return JSON.stringify(Object.keys(val)) === JSON.stringify([
|
|
33
|
+
"componentRef",
|
|
34
|
+
"ngZone",
|
|
35
|
+
"effectRunner",
|
|
36
|
+
"_autoDetect",
|
|
37
|
+
"_isStable",
|
|
38
|
+
"_isDestroyed",
|
|
39
|
+
"_resolve",
|
|
40
|
+
"_promise",
|
|
41
|
+
"_onUnstableSubscription",
|
|
42
|
+
"_onStableSubscription",
|
|
43
|
+
"_onMicrotaskEmptySubscription",
|
|
44
|
+
"_onErrorSubscription",
|
|
45
|
+
"changeDetectorRef",
|
|
46
|
+
"elementRef",
|
|
47
|
+
"debugElement",
|
|
48
|
+
"componentInstance",
|
|
49
|
+
"nativeElement"
|
|
50
|
+
]) || JSON.stringify(Object.keys(val)) === JSON.stringify([
|
|
51
|
+
"location",
|
|
52
|
+
"_rootLView",
|
|
53
|
+
"_tNode",
|
|
54
|
+
"previousInputValues",
|
|
55
|
+
"instance",
|
|
56
|
+
"changeDetectorRef",
|
|
57
|
+
"hostView",
|
|
58
|
+
"componentType"
|
|
59
|
+
]);
|
|
73
60
|
}
|
|
74
61
|
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
62
|
+
* Serialize Angular fixture for Vitest
|
|
63
|
+
*
|
|
64
|
+
* @param fixture Angular Fixture Component
|
|
65
|
+
* @returns HTML Child Node
|
|
66
|
+
*/
|
|
80
67
|
function fixtureVitestSerializer(fixture) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (componentType && componentType.propDecorators) {
|
|
88
|
-
inputsData = Object.entries(componentType.propDecorators)
|
|
89
|
-
.map(([key, value]) => `${key}="${value}"`)
|
|
90
|
-
.join('');
|
|
91
|
-
}
|
|
92
|
-
// * Get DOM Elements
|
|
93
|
-
const divElement = fixture && fixture.nativeElement
|
|
94
|
-
? fixture.nativeElement
|
|
95
|
-
: fixture.location.nativeElement;
|
|
96
|
-
// * Convert string data to HTML data
|
|
97
|
-
const doc = new DOMParser().parseFromString(`<${selector} ${inputsData}>${divElement.innerHTML}</${selector}>`, 'text/html');
|
|
98
|
-
return doc.body.childNodes[0];
|
|
68
|
+
const componentType = fixture && fixture.componentType ? fixture.componentType : fixture.componentRef.componentType;
|
|
69
|
+
let inputsData = "";
|
|
70
|
+
const selector = Reflect.getOwnPropertyDescriptor(componentType, "__annotations__")?.value[0].selector;
|
|
71
|
+
if (componentType && componentType.propDecorators) inputsData = Object.entries(componentType.propDecorators).map(([key, value]) => `${key}="${value}"`).join("");
|
|
72
|
+
const divElement = fixture && fixture.nativeElement ? fixture.nativeElement : fixture.location.nativeElement;
|
|
73
|
+
return new DOMParser().parseFromString(`<${selector} ${inputsData}>${divElement.innerHTML}</${selector}>`, "text/html").body.childNodes[0];
|
|
99
74
|
}
|
|
100
|
-
[
|
|
101
|
-
|
|
102
|
-
return originalvitestFn.addSnapshotSerializer(customSnapshotSerializer());
|
|
75
|
+
["expect"].forEach((methodName) => {
|
|
76
|
+
return env[methodName].addSnapshotSerializer(customSnapshotSerializer());
|
|
103
77
|
});
|
|
104
|
-
//#
|
|
78
|
+
//#endregion
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=setup-snapshots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-snapshots.js","names":[],"sources":["../../../packages/vitest-angular/setup-snapshots.ts"],"sourcesContent":["const env = globalThis as any;\n\n/**\n * Allows Vitest to handle Angular test fixtures\n *\n * Vitest Snapshot guide ==> https://vitest.dev/guide/snapshot.html\n *\n * @returns customSnapshotSerializer for Angular Fixture Component\n */\nconst customSnapshotSerializer = (): {\n serialize: (...args: any[]) => string;\n test: (val: any) => boolean;\n} => {\n function serialize(\n val: any,\n config: any,\n indentation: any,\n depth: any,\n refs: any,\n printer: any,\n ): string {\n // `printer` is a function that serializes a value using existing plugins.\n return `${printer(\n fixtureVitestSerializer(val),\n config,\n indentation,\n depth,\n refs,\n )}`;\n }\n function test(val: any): boolean {\n // * If it's a ComponentFixture we apply the transformation rules\n return val && isAngularFixture(val);\n }\n return {\n serialize: serialize,\n test: test,\n };\n};\n\n/**\n * Check if is an Angular fixture\n *\n * @param val Angular fixture\n * @returns boolean who check if is an angular fixture\n */\nfunction isAngularFixture(val: any): boolean {\n if (typeof val !== 'object') {\n return false;\n }\n\n if (val['componentRef'] || val['componentInstance']) {\n return true;\n }\n\n if (val['componentType']) {\n return true;\n }\n\n // * Angular fixture keys in Fixture component Object\n const fixtureKeys = [\n 'componentRef',\n 'ngZone',\n 'effectRunner',\n '_autoDetect',\n '_isStable',\n '_isDestroyed',\n '_resolve',\n '_promise',\n '_onUnstableSubscription',\n '_onStableSubscription',\n '_onMicrotaskEmptySubscription',\n '_onErrorSubscription',\n 'changeDetectorRef',\n 'elementRef',\n 'debugElement',\n 'componentInstance',\n 'nativeElement',\n ];\n\n // * Angular fixture keys in Fixture componentRef Object\n const fixtureComponentRefKeys = [\n 'location',\n '_rootLView',\n '_tNode',\n 'previousInputValues',\n 'instance',\n 'changeDetectorRef',\n 'hostView',\n 'componentType',\n ];\n\n return (\n JSON.stringify(Object.keys(val)) === JSON.stringify(fixtureKeys) ||\n JSON.stringify(Object.keys(val)) === JSON.stringify(fixtureComponentRefKeys)\n );\n}\n\n/**\n * Serialize Angular fixture for Vitest\n *\n * @param fixture Angular Fixture Component\n * @returns HTML Child Node\n */\nfunction fixtureVitestSerializer(fixture: any): ChildNode {\n // * Get Component meta data\n const componentType = (\n fixture && fixture.componentType\n ? fixture.componentType\n : fixture.componentRef.componentType\n ) as any;\n\n let inputsData = '';\n\n const selector = Reflect.getOwnPropertyDescriptor(\n componentType,\n '__annotations__',\n )?.value[0].selector;\n\n if (componentType && componentType.propDecorators) {\n inputsData = Object.entries(componentType.propDecorators)\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join('');\n }\n\n // * Get DOM Elements\n const divElement =\n fixture && fixture.nativeElement\n ? fixture.nativeElement\n : fixture.location.nativeElement;\n\n // * Convert string data to HTML data\n const doc = new DOMParser().parseFromString(\n `<${selector} ${inputsData}>${divElement.innerHTML}</${selector}>`,\n 'text/html',\n );\n\n return doc.body.childNodes[0];\n}\n\n['expect'].forEach((methodName) => {\n const originalvitestFn = env[methodName];\n return originalvitestFn.addSnapshotSerializer(customSnapshotSerializer());\n});\n"],"mappings":";AAAA,IAAM,MAAM;;;;;;;;AASZ,IAAM,iCAGD;CACH,SAAS,UACP,KACA,QACA,aACA,OACA,MACA,SACQ;AAER,SAAO,GAAG,QACR,wBAAwB,IAAI,EAC5B,QACA,aACA,OACA,KACD;;CAEH,SAAS,KAAK,KAAmB;AAE/B,SAAO,OAAO,iBAAiB,IAAI;;AAErC,QAAO;EACM;EACL;EACP;;;;;;;;AASH,SAAS,iBAAiB,KAAmB;AAC3C,KAAI,OAAO,QAAQ,SACjB,QAAO;AAGT,KAAI,IAAI,mBAAmB,IAAI,qBAC7B,QAAO;AAGT,KAAI,IAAI,iBACN,QAAO;AAoCT,QACE,KAAK,UAAU,OAAO,KAAK,IAAI,CAAC,KAAK,KAAK,UAjCxB;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAeiE,IAChE,KAAK,UAAU,OAAO,KAAK,IAAI,CAAC,KAAK,KAAK,UAbZ;EAC9B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAI6E;;;;;;;;AAUhF,SAAS,wBAAwB,SAAyB;CAExD,MAAM,gBACJ,WAAW,QAAQ,gBACf,QAAQ,gBACR,QAAQ,aAAa;CAG3B,IAAI,aAAa;CAEjB,MAAM,WAAW,QAAQ,yBACvB,eACA,kBACD,EAAE,MAAM,GAAG;AAEZ,KAAI,iBAAiB,cAAc,eACjC,cAAa,OAAO,QAAQ,cAAc,eAAe,CACtD,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,IAAI,MAAM,GAAG,CAC1C,KAAK,GAAG;CAIb,MAAM,aACJ,WAAW,QAAQ,gBACf,QAAQ,gBACR,QAAQ,SAAS;AAQvB,QALY,IAAI,WAAW,CAAC,gBAC1B,IAAI,SAAS,GAAG,WAAW,GAAG,WAAW,UAAU,IAAI,SAAS,IAChE,YACD,CAEU,KAAK,WAAW;;AAG7B,CAAC,SAAS,CAAC,SAAS,eAAe;AAEjC,QADyB,IAAI,YACL,sBAAsB,0BAA0B,CAAC;EACzE"}
|
package/setup-testbed.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { Provider } from
|
|
1
|
+
import { EnvironmentProviders, Provider } from "@angular/core";
|
|
2
2
|
type TestBedSetupOptions = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
zoneless?: boolean;
|
|
4
|
+
providers?: (Provider | EnvironmentProviders)[];
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use `teardown.destroyAfterEach` instead.
|
|
7
|
+
* @sunset 3.0.0
|
|
8
|
+
*/
|
|
9
|
+
browserMode?: boolean;
|
|
10
|
+
teardown?: {
|
|
11
|
+
destroyAfterEach: boolean;
|
|
12
|
+
};
|
|
6
13
|
};
|
|
7
|
-
export declare function setupTestBed({ zoneless, providers, browserMode, }?: TestBedSetupOptions): void;
|
|
14
|
+
export declare function setupTestBed({ zoneless, providers, browserMode, teardown }?: TestBedSetupOptions): void;
|
|
8
15
|
export {};
|
package/setup-testbed.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import { __decorate } from "
|
|
2
|
-
import { NgModule, provideZonelessChangeDetection
|
|
3
|
-
import {
|
|
4
|
-
import { BrowserTestingModule, platformBrowserTesting
|
|
5
|
-
import { afterEach, beforeEach } from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})
|
|
21
|
-
], TestModule);
|
|
22
|
-
getTestBed().initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting(), browserMode ? { teardown: { destroyAfterEach: false } } : undefined);
|
|
23
|
-
}
|
|
1
|
+
import { __decorate } from "./_virtual/_@oxc-project_runtime@0.120.0/helpers/decorate.js";
|
|
2
|
+
import { NgModule, provideZonelessChangeDetection } from "@angular/core";
|
|
3
|
+
import { getTestBed, ɵgetCleanupHook } from "@angular/core/testing";
|
|
4
|
+
import { BrowserTestingModule, platformBrowserTesting } from "@angular/platform-browser/testing";
|
|
5
|
+
import { afterEach, beforeEach } from "vitest";
|
|
6
|
+
//#region packages/vitest-angular/setup-testbed.ts
|
|
7
|
+
var ANGULAR_TESTBED_SETUP = Symbol.for("testbed-setup");
|
|
8
|
+
function setupTestBed({ zoneless = true, providers = [], browserMode = false, teardown } = {}) {
|
|
9
|
+
beforeEach(ɵgetCleanupHook(false));
|
|
10
|
+
afterEach(ɵgetCleanupHook(true));
|
|
11
|
+
if (!globalThis[ANGULAR_TESTBED_SETUP]) {
|
|
12
|
+
globalThis[ANGULAR_TESTBED_SETUP] = true;
|
|
13
|
+
let TestModule = class TestModule {};
|
|
14
|
+
TestModule = __decorate([NgModule({ providers: [...zoneless ? [provideZonelessChangeDetection()] : [], ...providers] })], TestModule);
|
|
15
|
+
getTestBed().initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting(), { teardown: {
|
|
16
|
+
destroyAfterEach: !browserMode,
|
|
17
|
+
...teardown
|
|
18
|
+
} });
|
|
19
|
+
}
|
|
24
20
|
}
|
|
25
|
-
//#
|
|
21
|
+
//#endregion
|
|
22
|
+
export { setupTestBed };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=setup-testbed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-testbed.js","names":[],"sources":["../../../packages/vitest-angular/setup-testbed.ts"],"sourcesContent":["import {\n EnvironmentProviders,\n NgModule,\n Provider,\n provideZonelessChangeDetection,\n} from '@angular/core';\nimport {\n ɵgetCleanupHook as getCleanupHook,\n getTestBed,\n} from '@angular/core/testing';\nimport {\n BrowserTestingModule,\n platformBrowserTesting,\n} from '@angular/platform-browser/testing';\nimport { afterEach, beforeEach } from 'vitest';\n\nconst ANGULAR_TESTBED_SETUP = Symbol.for('testbed-setup');\n\ntype TestBedSetupOptions = {\n zoneless?: boolean;\n providers?: (Provider | EnvironmentProviders)[];\n /**\n * @deprecated Use `teardown.destroyAfterEach` instead.\n * @sunset 3.0.0\n */\n browserMode?: boolean;\n teardown?: {\n destroyAfterEach: boolean;\n };\n};\n\nexport function setupTestBed({\n zoneless = true,\n providers = [],\n browserMode = false,\n teardown,\n}: TestBedSetupOptions = {}): void {\n beforeEach(getCleanupHook(false));\n afterEach(getCleanupHook(true));\n\n if (!(globalThis as any)[ANGULAR_TESTBED_SETUP]) {\n (globalThis as any)[ANGULAR_TESTBED_SETUP] = true;\n\n @NgModule({\n providers: [\n ...(zoneless ? [provideZonelessChangeDetection()] : []),\n ...providers,\n ],\n })\n class TestModule {}\n\n getTestBed().initTestEnvironment(\n [BrowserTestingModule, TestModule],\n platformBrowserTesting(),\n {\n teardown: {\n ...{ destroyAfterEach: !browserMode },\n ...teardown,\n },\n },\n );\n }\n}\n"],"mappings":";;;;;;AAgBA,IAAM,wBAAwB,OAAO,IAAI,gBAAgB;AAezD,SAAgB,aAAa,EAC3B,WAAW,MACX,YAAY,EAAE,EACd,cAAc,OACd,aACuB,EAAE,EAAQ;AACjC,YAAW,gBAAe,MAAM,CAAC;AACjC,WAAU,gBAAe,KAAK,CAAC;AAE/B,KAAI,CAAE,WAAmB,wBAAwB;AAC9C,aAAmB,yBAAyB;EAE7C,IAAA,aAAA,MAMM,WAAW;2BANhB,SAAS,EACR,WAAW,CACT,GAAI,WAAW,CAAC,gCAAgC,CAAC,GAAG,EAAE,EACtD,GAAG,UACJ,EACF,CAAC,CAAA,EAAA,WAAA;AAGF,cAAY,CAAC,oBACX,CAAC,sBAAsB,WAAW,EAClC,wBAAwB,EACxB,EACE,UAAU;GACH,kBAAkB,CAAC;GACxB,GAAG;GACJ,EACF,CACF"}
|
package/setup-zone.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import "zone.js";
|
|
2
|
+
import "zone.js/plugins/sync-test";
|
|
3
|
+
import "zone.js/plugins/proxy";
|
|
4
|
+
import "zone.js/testing";
|
|
5
|
+
import "./setup-snapshots.js";
|
|
6
|
+
export {};
|