@analogjs/vite-plugin-angular 3.0.0-alpha.19 → 3.0.0-alpha.20
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/migrations/migrate-setup-vitest/migrate-setup-vitest.d.ts +2 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
- package/migrations/migration.json +7 -1
- package/package.json +2 -3
- package/src/lib/angular-vitest-plugin.d.ts +1 -1
- package/src/lib/angular-vitest-plugin.js +13 -14
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/test-setup.d.ts +0 -1
- package/setup-vitest.d.ts +0 -5
- package/setup-vitest.js +0 -176
- package/setup-vitest.js.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { NodePackageInstallTask } from "@angular-devkit/schematics/tasks";
|
|
2
|
+
//#region packages/vite-plugin-angular/migrations/migrate-setup-vitest/migrate-setup-vitest.ts
|
|
3
|
+
var OLD_IMPORT = "@analogjs/vite-plugin-angular/setup-vitest";
|
|
4
|
+
var NEW_IMPORT = "@analogjs/vitest-angular/setup-zone";
|
|
5
|
+
function addVitestAngularDependency(tree, context) {
|
|
6
|
+
const pkgPath = "/package.json";
|
|
7
|
+
const content = tree.read(pkgPath);
|
|
8
|
+
if (!content) return;
|
|
9
|
+
const pkg = JSON.parse(content.toString("utf-8"));
|
|
10
|
+
const devDeps = pkg["devDependencies"] || {};
|
|
11
|
+
const deps = pkg["dependencies"] || {};
|
|
12
|
+
if (!devDeps["@analogjs/vitest-angular"] && !deps["@analogjs/vitest-angular"]) {
|
|
13
|
+
const analogVersion = devDeps["@analogjs/vite-plugin-angular"] || deps["@analogjs/vite-plugin-angular"] || "*";
|
|
14
|
+
pkg["devDependencies"] = {
|
|
15
|
+
...devDeps,
|
|
16
|
+
"@analogjs/vitest-angular": analogVersion
|
|
17
|
+
};
|
|
18
|
+
tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
19
|
+
context.addTask(new NodePackageInstallTask());
|
|
20
|
+
context.logger.info(`Added '@analogjs/vitest-angular': '${analogVersion}' to devDependencies.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function migrateSetupVitest() {
|
|
24
|
+
return (tree, context) => {
|
|
25
|
+
const filesToUpdate = [];
|
|
26
|
+
tree.visit((filePath) => {
|
|
27
|
+
if (!filePath.endsWith(".ts") && !filePath.endsWith(".mts") && !filePath.endsWith(".js") && !filePath.endsWith(".mjs")) return;
|
|
28
|
+
if (filePath.includes("/node_modules/")) return;
|
|
29
|
+
const content = tree.read(filePath);
|
|
30
|
+
if (!content) return;
|
|
31
|
+
const text = content.toString("utf-8");
|
|
32
|
+
if (text.includes(OLD_IMPORT)) {
|
|
33
|
+
const updated = text.replace(new RegExp(OLD_IMPORT.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"), NEW_IMPORT);
|
|
34
|
+
tree.overwrite(filePath, updated);
|
|
35
|
+
filesToUpdate.push(filePath);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
if (filesToUpdate.length > 0) {
|
|
39
|
+
context.logger.info(`Migrated ${filesToUpdate.length} file(s) from '${OLD_IMPORT}' to '${NEW_IMPORT}':`);
|
|
40
|
+
for (const file of filesToUpdate) context.logger.info(` - ${file}`);
|
|
41
|
+
}
|
|
42
|
+
if (filesToUpdate.length > 0) addVitestAngularDependency(tree, context);
|
|
43
|
+
return tree;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { migrateSetupVitest as default };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=migrate-setup-vitest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-setup-vitest.js","names":[],"sources":["../../../migrations/migrate-setup-vitest/migrate-setup-vitest.ts"],"sourcesContent":["import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';\n\nconst OLD_IMPORT = '@analogjs/vite-plugin-angular/setup-vitest';\nconst NEW_IMPORT = '@analogjs/vitest-angular/setup-zone';\n\nfunction addVitestAngularDependency(\n tree: Tree,\n context: SchematicContext,\n): void {\n const pkgPath = '/package.json';\n const content = tree.read(pkgPath);\n if (!content) {\n return;\n }\n\n const pkg = JSON.parse(content.toString('utf-8'));\n const devDeps = pkg['devDependencies'] || {};\n const deps = pkg['dependencies'] || {};\n\n if (\n !devDeps['@analogjs/vitest-angular'] &&\n !deps['@analogjs/vitest-angular']\n ) {\n const analogVersion =\n devDeps['@analogjs/vite-plugin-angular'] ||\n deps['@analogjs/vite-plugin-angular'] ||\n '*';\n\n pkg['devDependencies'] = {\n ...devDeps,\n '@analogjs/vitest-angular': analogVersion,\n };\n\n tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2) + '\\n');\n context.addTask(new NodePackageInstallTask());\n context.logger.info(\n `Added '@analogjs/vitest-angular': '${analogVersion}' to devDependencies.`,\n );\n }\n}\n\nexport default function migrateSetupVitest(): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const filesToUpdate: string[] = [];\n\n tree.visit((filePath) => {\n if (\n !filePath.endsWith('.ts') &&\n !filePath.endsWith('.mts') &&\n !filePath.endsWith('.js') &&\n !filePath.endsWith('.mjs')\n ) {\n return;\n }\n if (filePath.includes('/node_modules/')) {\n return;\n }\n\n const content = tree.read(filePath);\n if (!content) {\n return;\n }\n\n const text = content.toString('utf-8');\n if (text.includes(OLD_IMPORT)) {\n const updated = text.replace(\n new RegExp(OLD_IMPORT.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'g'),\n NEW_IMPORT,\n );\n tree.overwrite(filePath, updated);\n filesToUpdate.push(filePath);\n }\n });\n\n if (filesToUpdate.length > 0) {\n context.logger.info(\n `Migrated ${filesToUpdate.length} file(s) from '${OLD_IMPORT}' to '${NEW_IMPORT}':`,\n );\n for (const file of filesToUpdate) {\n context.logger.info(` - ${file}`);\n }\n }\n\n if (filesToUpdate.length > 0) {\n addVitestAngularDependency(tree, context);\n }\n\n return tree;\n };\n}\n"],"mappings":";;AAGA,IAAM,aAAa;AACnB,IAAM,aAAa;AAEnB,SAAS,2BACP,MACA,SACM;CACN,MAAM,UAAU;CAChB,MAAM,UAAU,KAAK,KAAK,QAAQ;AAClC,KAAI,CAAC,QACH;CAGF,MAAM,MAAM,KAAK,MAAM,QAAQ,SAAS,QAAQ,CAAC;CACjD,MAAM,UAAU,IAAI,sBAAsB,EAAE;CAC5C,MAAM,OAAO,IAAI,mBAAmB,EAAE;AAEtC,KACE,CAAC,QAAQ,+BACT,CAAC,KAAK,6BACN;EACA,MAAM,gBACJ,QAAQ,oCACR,KAAK,oCACL;AAEF,MAAI,qBAAqB;GACvB,GAAG;GACH,4BAA4B;GAC7B;AAED,OAAK,UAAU,SAAS,KAAK,UAAU,KAAK,MAAM,EAAE,GAAG,KAAK;AAC5D,UAAQ,QAAQ,IAAI,wBAAwB,CAAC;AAC7C,UAAQ,OAAO,KACb,sCAAsC,cAAc,uBACrD;;;AAIL,SAAwB,qBAA2B;AACjD,SAAQ,MAAY,YAA8B;EAChD,MAAM,gBAA0B,EAAE;AAElC,OAAK,OAAO,aAAa;AACvB,OACE,CAAC,SAAS,SAAS,MAAM,IACzB,CAAC,SAAS,SAAS,OAAO,IAC1B,CAAC,SAAS,SAAS,MAAM,IACzB,CAAC,SAAS,SAAS,OAAO,CAE1B;AAEF,OAAI,SAAS,SAAS,iBAAiB,CACrC;GAGF,MAAM,UAAU,KAAK,KAAK,SAAS;AACnC,OAAI,CAAC,QACH;GAGF,MAAM,OAAO,QAAQ,SAAS,QAAQ;AACtC,OAAI,KAAK,SAAS,WAAW,EAAE;IAC7B,MAAM,UAAU,KAAK,QACnB,IAAI,OAAO,WAAW,QAAQ,uBAAuB,OAAO,EAAE,IAAI,EAClE,WACD;AACD,SAAK,UAAU,UAAU,QAAQ;AACjC,kBAAc,KAAK,SAAS;;IAE9B;AAEF,MAAI,cAAc,SAAS,GAAG;AAC5B,WAAQ,OAAO,KACb,YAAY,cAAc,OAAO,iBAAiB,WAAW,QAAQ,WAAW,IACjF;AACD,QAAK,MAAM,QAAQ,cACjB,SAAQ,OAAO,KAAK,OAAO,OAAO;;AAItC,MAAI,cAAc,SAAS,EACzB,4BAA2B,MAAM,QAAQ;AAG3C,SAAO"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
3
|
-
"schematics": {
|
|
3
|
+
"schematics": {
|
|
4
|
+
"migrate-setup-vitest": {
|
|
5
|
+
"version": "3.0.0-alpha.16",
|
|
6
|
+
"description": "Migrate from @analogjs/vite-plugin-angular/setup-vitest to @analogjs/vitest-angular/setup-zone",
|
|
7
|
+
"factory": "./migrate-setup-vitest/migrate-setup-vitest"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
4
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@analogjs/vite-plugin-angular",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.20",
|
|
4
4
|
"description": "Vite Plugin for Angular",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -61,8 +61,7 @@
|
|
|
61
61
|
"import": "./src/index.js",
|
|
62
62
|
"require": "./src/index.js",
|
|
63
63
|
"default": "./src/index.js"
|
|
64
|
-
}
|
|
65
|
-
"./setup-vitest": "./setup-vitest.js"
|
|
64
|
+
}
|
|
66
65
|
},
|
|
67
66
|
"publishConfig": {
|
|
68
67
|
"access": "public",
|
|
@@ -4,7 +4,7 @@ import type { Plugin } from "vite";
|
|
|
4
4
|
* `@angular/cdk` from modern async/await to ES2016 so that Zone.js can
|
|
5
5
|
* intercept promises during `fakeAsync` tests.
|
|
6
6
|
*
|
|
7
|
-
* Under Vite 8+ (Rolldown)
|
|
7
|
+
* Under Vite 8+ (Rolldown) downleveling is not needed.
|
|
8
8
|
* Under Vite ≤7, esbuild handles the downlevel.
|
|
9
9
|
*/
|
|
10
10
|
export declare function angularVitestPlugin(): Plugin;
|
|
@@ -6,7 +6,7 @@ import * as vite from "vite";
|
|
|
6
6
|
* `@angular/cdk` from modern async/await to ES2016 so that Zone.js can
|
|
7
7
|
* intercept promises during `fakeAsync` tests.
|
|
8
8
|
*
|
|
9
|
-
* Under Vite 8+ (Rolldown)
|
|
9
|
+
* Under Vite 8+ (Rolldown) downleveling is not needed.
|
|
10
10
|
* Under Vite ≤7, esbuild handles the downlevel.
|
|
11
11
|
*/
|
|
12
12
|
function angularVitestPlugin() {
|
|
@@ -29,19 +29,18 @@ function angularVitestPlugin() {
|
|
|
29
29
|
filter: { id: /fesm2022|@angular\/cdk/ },
|
|
30
30
|
async handler(_code, id) {
|
|
31
31
|
if (/fesm2022/.test(id) && _code.includes("async ") || _code.includes("@angular/cdk")) {
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
32
|
+
if (isRolldown()) return;
|
|
33
|
+
const { code, map } = await vite.transformWithEsbuild(_code, id, {
|
|
34
|
+
loader: "js",
|
|
35
|
+
format: "esm",
|
|
36
|
+
target: "es2016",
|
|
37
|
+
sourcemap: true,
|
|
38
|
+
sourcefile: id
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
code,
|
|
42
|
+
map
|
|
43
|
+
};
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-vitest-plugin.js","names":[],"sources":["../../../src/lib/angular-vitest-plugin.ts"],"sourcesContent":["import type { Plugin, TransformResult, UserConfig } from 'vite';\n// Use the namespace import so these runtime helpers still resolve on Vite 6,\n// which does not expose them as named exports.\nimport * as vite from 'vite';\nimport { getJsTransformConfigKey, isRolldown } from './utils/rolldown.js';\n\n/**\n * Sets up test config for Vitest and downlevels Angular FESM bundles and\n * `@angular/cdk` from modern async/await to ES2016 so that Zone.js can\n * intercept promises during `fakeAsync` tests.\n *\n * Under Vite 8+ (Rolldown)
|
|
1
|
+
{"version":3,"file":"angular-vitest-plugin.js","names":[],"sources":["../../../src/lib/angular-vitest-plugin.ts"],"sourcesContent":["import type { Plugin, TransformResult, UserConfig } from 'vite';\n// Use the namespace import so these runtime helpers still resolve on Vite 6,\n// which does not expose them as named exports.\nimport * as vite from 'vite';\nimport { getJsTransformConfigKey, isRolldown } from './utils/rolldown.js';\n\n/**\n * Sets up test config for Vitest and downlevels Angular FESM bundles and\n * `@angular/cdk` from modern async/await to ES2016 so that Zone.js can\n * intercept promises during `fakeAsync` tests.\n *\n * Under Vite 8+ (Rolldown) downleveling is not needed.\n * Under Vite ≤7, esbuild handles the downlevel.\n */\nexport function angularVitestPlugin(): Plugin {\n return {\n name: '@analogjs/vitest-angular-esm-plugin',\n apply: 'serve',\n enforce: 'post',\n config(userConfig) {\n return {\n optimizeDeps: {\n include: ['tslib'],\n },\n ssr: {\n noExternal: [\n '@analogjs/vitest-angular/setup-testbed',\n /fesm2022(.*?)testing/,\n /fesm2015/,\n ],\n },\n test: {\n pool: (userConfig as any).test?.pool ?? 'vmThreads',\n },\n };\n },\n // Filter by module ID so only Angular FESM2022 bundles and CDK enter\n // the handler. The inner guards add a secondary code-content check\n // (`async` keyword) for fesm2022 to avoid needless transforms.\n transform: {\n filter: {\n id: /fesm2022|@angular\\/cdk/,\n },\n async handler(_code, id) {\n if (\n (/fesm2022/.test(id) && _code.includes('async ')) ||\n _code.includes('@angular/cdk')\n ) {\n if (isRolldown()) {\n return undefined;\n }\n\n const { code, map } = await vite.transformWithEsbuild(_code, id, {\n loader: 'js',\n format: 'esm',\n target: 'es2016',\n sourcemap: true,\n sourcefile: id,\n });\n\n return {\n code,\n map,\n };\n }\n\n return undefined;\n },\n },\n };\n}\n\n/**\n * Eagerly disables the built-in JS transformer (esbuild on Vite ≤7, OXC on\n * Vite 8+) so Vitest's internal plugin doesn't race with the Angular\n * compiler. Must run at `enforce: 'pre'` to take effect before Vitest\n * reads the resolved config.\n */\nexport function angularVitestEsbuildPlugin(): Plugin {\n return {\n name: '@analogjs/vitest-angular-esbuild-oxc-plugin',\n enforce: 'pre',\n config(userConfig: UserConfig) {\n const jsTransformConfigKey = getJsTransformConfigKey();\n\n return {\n [jsTransformConfigKey]:\n jsTransformConfigKey === 'oxc'\n ? (userConfig.oxc ?? false)\n : (userConfig.esbuild ?? false),\n };\n },\n };\n}\n\n/**\n * Post-processes `.ts` files with the JS transformer (esbuild / OXC) to\n * re-align sourcemaps so breakpoints and coverage reports work correctly.\n *\n * Inline style/template virtual modules (`?inline`) are excluded because\n * they are already handled by the Angular compiler.\n */\nexport function angularVitestSourcemapPlugin(): Plugin {\n return {\n name: '@analogjs/vitest-angular-sourcemap-plugin',\n transform: {\n filter: {\n // Match `.ts` at the end of the path OR before a `?` query string.\n // Vite/Vitest appends query params for virtual modules (e.g.\n // `component.ts?inline`), so a plain `$` anchor would reject them\n // and leave sourcemaps misaligned — causing Angular TestBed teardown\n // crashes (`_doc` undefined in `removeAllRootElements`).\n // The negative lookahead `(?!x)` prevents matching `.tsx` or `.d.ts`.\n id: /\\.ts(?:\\?|$)/,\n },\n async handler(code: string, id: string) {\n const [, query] = id.split('?');\n\n if (query && query.includes('inline')) {\n return;\n }\n\n if (isRolldown()) {\n // lang must be 'ts' (not 'js') so OXC parses TypeScript syntax;\n // using 'js' would cause parse errors on type annotations.\n const result = await vite.transformWithOxc(code, id, {\n lang: 'ts',\n });\n\n return result as unknown as TransformResult;\n } else {\n const result = await vite.transformWithEsbuild(code, id, {\n loader: 'ts',\n });\n\n return result;\n }\n },\n },\n };\n}\n\nexport function angularVitestPlugins(): Plugin[] {\n return [\n angularVitestPlugin(),\n angularVitestEsbuildPlugin(),\n angularVitestSourcemapPlugin(),\n ];\n}\n"],"mappings":";;;;;;;;;;;AAcA,SAAgB,sBAA8B;AAC5C,QAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;EACT,OAAO,YAAY;AACjB,UAAO;IACL,cAAc,EACZ,SAAS,CAAC,QAAQ,EACnB;IACD,KAAK,EACH,YAAY;KACV;KACA;KACA;KACD,EACF;IACD,MAAM,EACJ,MAAO,WAAmB,MAAM,QAAQ,aACzC;IACF;;EAKH,WAAW;GACT,QAAQ,EACN,IAAI,0BACL;GACD,MAAM,QAAQ,OAAO,IAAI;AACvB,QACG,WAAW,KAAK,GAAG,IAAI,MAAM,SAAS,SAAS,IAChD,MAAM,SAAS,eAAe,EAC9B;AACA,SAAI,YAAY,CACd;KAGF,MAAM,EAAE,MAAM,QAAQ,MAAM,KAAK,qBAAqB,OAAO,IAAI;MAC/D,QAAQ;MACR,QAAQ;MACR,QAAQ;MACR,WAAW;MACX,YAAY;MACb,CAAC;AAEF,YAAO;MACL;MACA;MACD;;;GAKN;EACF;;;;;;;;AASH,SAAgB,6BAAqC;AACnD,QAAO;EACL,MAAM;EACN,SAAS;EACT,OAAO,YAAwB;GAC7B,MAAM,uBAAuB,yBAAyB;AAEtD,UAAO,GACJ,uBACC,yBAAyB,QACpB,WAAW,OAAO,QAClB,WAAW,WAAW,OAC9B;;EAEJ;;;;;;;;;AAUH,SAAgB,+BAAuC;AACrD,QAAO;EACL,MAAM;EACN,WAAW;GACT,QAAQ,EAON,IAAI,gBACL;GACD,MAAM,QAAQ,MAAc,IAAY;IACtC,MAAM,GAAG,SAAS,GAAG,MAAM,IAAI;AAE/B,QAAI,SAAS,MAAM,SAAS,SAAS,CACnC;AAGF,QAAI,YAAY,CAOd,QAJe,MAAM,KAAK,iBAAiB,MAAM,IAAI,EACnD,MAAM,MACP,CAAC;QAQF,QAJe,MAAM,KAAK,qBAAqB,MAAM,IAAI,EACvD,QAAQ,MACT,CAAC;;GAKP;EACF;;AAGH,SAAgB,uBAAiC;AAC/C,QAAO;EACL,qBAAqB;EACrB,4BAA4B;EAC5B,8BAA8B;EAC/B"}
|
package/src/test-setup.d.ts
CHANGED
package/setup-vitest.d.ts
DELETED
package/setup-vitest.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import "zone.js";
|
|
2
|
-
import "zone.js/plugins/sync-test";
|
|
3
|
-
import "zone.js/plugins/proxy";
|
|
4
|
-
import "zone.js/testing";
|
|
5
|
-
//#region packages/vite-plugin-angular/setup-vitest.ts
|
|
6
|
-
/**
|
|
7
|
-
* Patch Vitest's describe/test/beforeEach/afterEach functions so test code
|
|
8
|
-
* always runs in a testZone (ProxyZone).
|
|
9
|
-
*/
|
|
10
|
-
var { Zone } = globalThis;
|
|
11
|
-
if (Zone === void 0) throw new Error("Missing: Zone (zone.js)");
|
|
12
|
-
if (globalThis["__vitest_zone_patch__"] === true) throw new Error("'vitest' has already been patched with 'Zone'.");
|
|
13
|
-
globalThis["__vitest_zone_patch__"] = true;
|
|
14
|
-
var { SyncTestZoneSpec } = Zone;
|
|
15
|
-
var { ProxyZoneSpec } = Zone;
|
|
16
|
-
if (SyncTestZoneSpec === void 0) throw new Error("Missing: SyncTestZoneSpec (zone.js/plugins/sync-test)");
|
|
17
|
-
if (ProxyZoneSpec === void 0) throw new Error("Missing: ProxyZoneSpec (zone.js/plugins/proxy.js)");
|
|
18
|
-
var env = globalThis;
|
|
19
|
-
var ambientZone = Zone.current;
|
|
20
|
-
var syncZone = ambientZone.fork(new SyncTestZoneSpec("vitest.describe"));
|
|
21
|
-
function wrapDescribeInZone(describeBody) {
|
|
22
|
-
return function(...args) {
|
|
23
|
-
return syncZone.run(describeBody, null, args);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
var testProxyZone = ambientZone.fork(new ProxyZoneSpec());
|
|
27
|
-
function wrapTestInZone(testBody) {
|
|
28
|
-
if (testBody === void 0) return;
|
|
29
|
-
const wrappedFunc = function wrappedFunc(...args) {
|
|
30
|
-
return testProxyZone.run(testBody, null, args);
|
|
31
|
-
};
|
|
32
|
-
try {
|
|
33
|
-
Object.defineProperty(wrappedFunc, "length", {
|
|
34
|
-
configurable: true,
|
|
35
|
-
enumerable: false,
|
|
36
|
-
writable: true
|
|
37
|
-
});
|
|
38
|
-
wrappedFunc.length = testBody.length;
|
|
39
|
-
} catch (e) {
|
|
40
|
-
return testBody.length === 0 ? () => testProxyZone.run(testBody, null) : (done) => testProxyZone.run(testBody, null, [done]);
|
|
41
|
-
}
|
|
42
|
-
return wrappedFunc;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Allows Vitest to handle Angular test fixtures
|
|
46
|
-
*
|
|
47
|
-
* Vitest Snapshot guide ==> https://vitest.dev/guide/snapshot.html
|
|
48
|
-
*
|
|
49
|
-
* @returns customSnapshotSerializer for Angular Fixture Component
|
|
50
|
-
*/
|
|
51
|
-
var customSnapshotSerializer = () => {
|
|
52
|
-
function serialize(val, config, indentation, depth, refs, printer) {
|
|
53
|
-
return `${printer(fixtureVitestSerializer(val), config, indentation, depth, refs)}`;
|
|
54
|
-
}
|
|
55
|
-
function test(val) {
|
|
56
|
-
return val && isAngularFixture(val);
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
serialize,
|
|
60
|
-
test
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Check if is an Angular fixture
|
|
65
|
-
*
|
|
66
|
-
* @param val Angular fixture
|
|
67
|
-
* @returns boolean who check if is an angular fixture
|
|
68
|
-
*/
|
|
69
|
-
function isAngularFixture(val) {
|
|
70
|
-
if (typeof val !== "object") return false;
|
|
71
|
-
if (val["componentRef"] || val["componentInstance"]) return true;
|
|
72
|
-
if (val["componentType"]) return true;
|
|
73
|
-
return JSON.stringify(Object.keys(val)) === JSON.stringify([
|
|
74
|
-
"componentRef",
|
|
75
|
-
"ngZone",
|
|
76
|
-
"effectRunner",
|
|
77
|
-
"_autoDetect",
|
|
78
|
-
"_isStable",
|
|
79
|
-
"_isDestroyed",
|
|
80
|
-
"_resolve",
|
|
81
|
-
"_promise",
|
|
82
|
-
"_onUnstableSubscription",
|
|
83
|
-
"_onStableSubscription",
|
|
84
|
-
"_onMicrotaskEmptySubscription",
|
|
85
|
-
"_onErrorSubscription",
|
|
86
|
-
"changeDetectorRef",
|
|
87
|
-
"elementRef",
|
|
88
|
-
"debugElement",
|
|
89
|
-
"componentInstance",
|
|
90
|
-
"nativeElement"
|
|
91
|
-
]) || JSON.stringify(Object.keys(val)) === JSON.stringify([
|
|
92
|
-
"location",
|
|
93
|
-
"_rootLView",
|
|
94
|
-
"_tNode",
|
|
95
|
-
"previousInputValues",
|
|
96
|
-
"instance",
|
|
97
|
-
"changeDetectorRef",
|
|
98
|
-
"hostView",
|
|
99
|
-
"componentType"
|
|
100
|
-
]);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Serialize Angular fixture for Vitest
|
|
104
|
-
*
|
|
105
|
-
* @param fixture Angular Fixture Component
|
|
106
|
-
* @returns HTML Child Node
|
|
107
|
-
*/
|
|
108
|
-
function fixtureVitestSerializer(fixture) {
|
|
109
|
-
const componentType = fixture && fixture.componentType ? fixture.componentType : fixture.componentRef.componentType;
|
|
110
|
-
let inputsData = "";
|
|
111
|
-
const selector = Reflect.getOwnPropertyDescriptor(componentType, "__annotations__")?.value[0].selector;
|
|
112
|
-
if (componentType && componentType.propDecorators) inputsData = Object.entries(componentType.propDecorators).map(([key, value]) => `${key}="${value}"`).join("");
|
|
113
|
-
const divElement = fixture && fixture.nativeElement ? fixture.nativeElement : fixture.location.nativeElement;
|
|
114
|
-
return new DOMParser().parseFromString(`<${selector} ${inputsData}>${divElement.innerHTML}</${selector}>`, "text/html").body.childNodes[0];
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Bind describe method to wrap describe.each function
|
|
118
|
-
*/
|
|
119
|
-
var bindDescribe = (self, originalVitestFn) => function bindDescribe(...eachArgs) {
|
|
120
|
-
return function bindDescribe(...args) {
|
|
121
|
-
args[1] = wrapDescribeInZone(args[1]);
|
|
122
|
-
return originalVitestFn.apply(self, eachArgs).apply(self, args);
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Bind test method to wrap test.each function
|
|
127
|
-
*/
|
|
128
|
-
var bindTest = (self, originalVitestFn) => function bindTest(...eachArgs) {
|
|
129
|
-
return function bindTest(...args) {
|
|
130
|
-
args[1] = wrapTestInZone(args[1]);
|
|
131
|
-
return originalVitestFn.apply(self, eachArgs).apply(self, args);
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
["describe"].forEach((methodName) => {
|
|
135
|
-
const originalvitestFn = env[methodName];
|
|
136
|
-
env[methodName] = function(...args) {
|
|
137
|
-
args[1] = wrapDescribeInZone(args[1]);
|
|
138
|
-
return originalvitestFn.apply(this, args);
|
|
139
|
-
};
|
|
140
|
-
env[methodName].each = bindDescribe(originalvitestFn, originalvitestFn.each);
|
|
141
|
-
if (methodName === "describe") {
|
|
142
|
-
env[methodName].only = bindDescribe(originalvitestFn, originalvitestFn.only);
|
|
143
|
-
env[methodName].skip = bindDescribe(originalvitestFn, originalvitestFn.skip);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
["test", "it"].forEach((methodName) => {
|
|
147
|
-
const originalvitestFn = env[methodName];
|
|
148
|
-
env[methodName] = function(...args) {
|
|
149
|
-
args[1] = wrapTestInZone(args[1]);
|
|
150
|
-
return originalvitestFn.apply(this, args);
|
|
151
|
-
};
|
|
152
|
-
env[methodName].each = bindTest(originalvitestFn, originalvitestFn.each);
|
|
153
|
-
env[methodName].only = bindTest(originalvitestFn, originalvitestFn.only);
|
|
154
|
-
env[methodName].skip = bindTest(originalvitestFn, originalvitestFn.skip);
|
|
155
|
-
if (methodName === "test" || methodName === "it") env[methodName].todo = function todo(...args) {
|
|
156
|
-
return originalvitestFn.todo.apply(this, args);
|
|
157
|
-
};
|
|
158
|
-
});
|
|
159
|
-
[
|
|
160
|
-
"beforeEach",
|
|
161
|
-
"afterEach",
|
|
162
|
-
"beforeAll",
|
|
163
|
-
"afterAll"
|
|
164
|
-
].forEach((methodName) => {
|
|
165
|
-
const originalvitestFn = env[methodName];
|
|
166
|
-
env[methodName] = function(...args) {
|
|
167
|
-
args[0] = wrapTestInZone(args[0]);
|
|
168
|
-
return originalvitestFn.apply(this, args);
|
|
169
|
-
};
|
|
170
|
-
});
|
|
171
|
-
["expect"].forEach((methodName) => {
|
|
172
|
-
return env[methodName].addSnapshotSerializer(customSnapshotSerializer());
|
|
173
|
-
});
|
|
174
|
-
//#endregion
|
|
175
|
-
|
|
176
|
-
//# sourceMappingURL=setup-vitest.js.map
|
package/setup-vitest.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup-vitest.js","names":[],"sources":["../setup-vitest.ts"],"sourcesContent":["import 'zone.js';\nimport 'zone.js/plugins/sync-test';\nimport 'zone.js/plugins/proxy';\nimport 'zone.js/testing';\n\n/**\n * Patch Vitest's describe/test/beforeEach/afterEach functions so test code\n * always runs in a testZone (ProxyZone).\n */\n/* global Zone */\nconst { Zone } = globalThis as any;\n\nif (Zone === undefined) {\n throw new Error('Missing: Zone (zone.js)');\n}\n\nif ((globalThis as any)['__vitest_zone_patch__'] === true) {\n throw new Error(\"'vitest' has already been patched with 'Zone'.\");\n}\n\n(globalThis as any)['__vitest_zone_patch__'] = true;\nconst { SyncTestZoneSpec } = Zone;\nconst { ProxyZoneSpec } = Zone;\n\nif (SyncTestZoneSpec === undefined) {\n throw new Error('Missing: SyncTestZoneSpec (zone.js/plugins/sync-test)');\n}\nif (ProxyZoneSpec === undefined) {\n throw new Error('Missing: ProxyZoneSpec (zone.js/plugins/proxy.js)');\n}\n\nconst env = globalThis as any;\nconst ambientZone = Zone.current;\n\n// Create a synchronous-only zone in which to run `describe` blocks in order to\n// Raise an error if any asynchronous operations are attempted\n// Inside of a `describe` but outside of a `beforeEach` or `it`.\nconst syncZone = ambientZone.fork(new SyncTestZoneSpec('vitest.describe'));\nfunction wrapDescribeInZone(describeBody: any) {\n return function (...args: any) {\n return syncZone.run(describeBody, null, args);\n };\n}\n\n// Create a proxy zone in which to run `test` blocks so that the tests function\n// Can retroactively install different zones.\nconst testProxyZone = ambientZone.fork(new ProxyZoneSpec());\nfunction wrapTestInZone(testBody: string | any[] | undefined) {\n if (testBody === undefined) {\n return;\n }\n\n const wrappedFunc = function wrappedFunc(...args: any[]) {\n return testProxyZone.run(testBody, null, args);\n };\n try {\n Object.defineProperty(wrappedFunc, 'length', {\n configurable: true,\n enumerable: false,\n writable: true,\n });\n wrappedFunc.length = testBody.length;\n } catch (e) {\n return testBody.length === 0\n ? () => testProxyZone.run(testBody, null)\n : (done: any) => testProxyZone.run(testBody, null, [done]);\n }\n\n return wrappedFunc;\n}\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 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,\n 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) {\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/**\n * Bind describe method to wrap describe.each function\n */\nconst bindDescribe = (\n self: any,\n originalVitestFn: {\n apply: (\n arg0: any,\n arg1: any[],\n ) => {\n (): any;\n new (): any;\n apply: { (arg0: any, arg1: any[]): any; new (): any };\n };\n },\n) =>\n function bindDescribe(...eachArgs: any) {\n return function bindDescribe(...args: any[]) {\n args[1] = wrapDescribeInZone(args[1]);\n\n return originalVitestFn.apply(self, eachArgs).apply(self, args);\n };\n };\n\n/**\n * Bind test method to wrap test.each function\n */\nconst bindTest = (\n self: any,\n originalVitestFn: {\n apply: (\n arg0: any,\n arg1: any[],\n ) => {\n (): any;\n new (): any;\n apply: { (arg0: any, arg1: any[]): any; new (): any };\n };\n },\n) =>\n function bindTest(...eachArgs: any) {\n return function bindTest(...args: any[]) {\n args[1] = wrapTestInZone(args[1]);\n\n return originalVitestFn.apply(self, eachArgs).apply(self, args);\n };\n };\n\n['describe'].forEach((methodName) => {\n const originalvitestFn = env[methodName];\n env[methodName] = function (...args: any[]) {\n args[1] = wrapDescribeInZone(args[1]);\n\n return originalvitestFn.apply(this, args);\n };\n env[methodName].each = bindDescribe(originalvitestFn, originalvitestFn.each);\n if (methodName === 'describe') {\n env[methodName].only = bindDescribe(\n originalvitestFn,\n originalvitestFn.only,\n );\n env[methodName].skip = bindDescribe(\n originalvitestFn,\n originalvitestFn.skip,\n );\n }\n});\n\n['test', 'it'].forEach((methodName) => {\n const originalvitestFn = env[methodName];\n env[methodName] = function (...args: any[]) {\n args[1] = wrapTestInZone(args[1]);\n\n return originalvitestFn.apply(this, args);\n };\n env[methodName].each = bindTest(originalvitestFn, originalvitestFn.each);\n env[methodName].only = bindTest(originalvitestFn, originalvitestFn.only);\n env[methodName].skip = bindTest(originalvitestFn, originalvitestFn.skip);\n\n if (methodName === 'test' || methodName === 'it') {\n env[methodName].todo = function todo(...args: any) {\n return originalvitestFn.todo.apply(this, args);\n };\n }\n});\n\n['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach((methodName) => {\n const originalvitestFn = env[methodName];\n\n env[methodName] = function (...args: any[]) {\n args[0] = wrapTestInZone(args[0]);\n\n return originalvitestFn.apply(this, args);\n };\n});\n\n['expect'].forEach((methodName) => {\n const originalvitestFn = env[methodName];\n return originalvitestFn.addSnapshotSerializer(customSnapshotSerializer());\n});\n"],"mappings":";;;;;;;;;AAUA,IAAM,EAAE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