@analogjs/vitest-angular 3.0.0-alpha.7 → 3.0.0-alpha.70
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 +11 -0
- package/_virtual/_@oxc-project_runtime@0.124.0/helpers/decorate.js +9 -0
- package/package.json +26 -13
- package/setup-serializers.d.ts +1 -0
- package/setup-serializers.js +13 -0
- package/setup-serializers.js.map +1 -0
- package/setup-snapshots.d.ts +1 -26
- package/setup-snapshots.js +10 -103
- package/setup-snapshots.js.map +1 -0
- package/setup-testbed.d.ts +14 -12
- package/setup-testbed.js +27 -29
- package/setup-testbed.js.map +1 -0
- package/setup-zone.d.ts +6 -5
- package/setup-zone.js +101 -113
- 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 +6 -6
- package/src/lib/builders/build/plugins/downlevel-plugin.js +23 -22
- 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/snapshot-serializers/angular-fixture.d.ts +2 -0
- package/src/lib/snapshot-serializers/angular-fixture.js +71 -0
- package/src/lib/snapshot-serializers/angular-fixture.js.map +1 -0
- package/src/lib/snapshot-serializers/html-comment.d.ts +2 -0
- package/src/lib/snapshot-serializers/html-comment.js +11 -0
- package/src/lib/snapshot-serializers/html-comment.js.map +1 -0
- package/src/lib/snapshot-serializers/index.d.ts +3 -0
- package/src/lib/snapshot-serializers/no-ng-attributes.d.ts +4 -0
- package/src/lib/snapshot-serializers/no-ng-attributes.js +63 -0
- package/src/lib/snapshot-serializers/no-ng-attributes.js.map +1 -0
- package/src/lib/tools/collection.json +2 -2
- package/src/lib/tools/index.d.ts +1 -0
- package/src/lib/tools/index.js +3 -0
- package/src/lib/tools/package.json +1 -5
- package/src/lib/tools/{src/schematics → schematics}/setup/files/src/test-setup.ts.template +1 -0
- package/src/lib/tools/{src/schematics → schematics}/setup/files/vite.config.mts.template +2 -7
- package/src/lib/tools/schematics/setup/index.d.ts +3 -0
- package/src/lib/tools/schematics/setup/index.js +55 -0
- package/src/lib/tools/schematics/setup/index.js.map +1 -0
- package/src/lib/tools/schematics/utils/angular.d.ts +3 -0
- package/src/lib/tools/schematics/utils/angular.js +21 -0
- package/src/lib/tools/schematics/utils/angular.js.map +1 -0
- package/src/lib/tools/schematics/utils/dependencies.d.ts +6 -0
- package/src/lib/tools/schematics/utils/dependencies.js +39 -0
- package/src/lib/tools/schematics/utils/dependencies.js.map +1 -0
- package/src/lib/tools/schematics/utils/index.d.ts +4 -0
- package/src/lib/tools/schematics/utils/index.js +4 -0
- package/src/lib/tools/schematics/utils/versions.d.ts +7 -0
- package/src/lib/tools/schematics/utils/versions.js +18 -0
- package/src/lib/tools/schematics/utils/versions.js.map +1 -0
- package/src/lib/tools/schematics/utils/workspace.d.ts +15 -0
- package/src/lib/tools/schematics/utils/workspace.js +21 -0
- package/src/lib/tools/schematics/utils/workspace.js.map +1 -0
- package/src/lib/tools/src/index.d.ts +1 -1
- package/src/lib/tools/src/schematics/setup/index.d.ts +2 -2
- package/src/lib/tools/src/schematics/utils/angular.d.ts +1 -1
- package/src/lib/tools/src/schematics/utils/dependencies.d.ts +2 -2
- package/src/lib/tools/src/schematics/utils/index.d.ts +4 -4
- package/src/lib/tools/src/schematics/utils/versions.d.ts +1 -1
- package/src/lib/tools/src/schematics/utils/workspace.d.ts +8 -8
- package/src/lib/tools/src/test-global-setup.d.ts +1 -0
- package/src/test-setup.d.ts +3 -0
- package/src/lib/builders/build/utils.js +0 -1
- package/src/lib/tools/src/index.js +0 -6
- package/src/lib/tools/src/index.js.map +0 -1
- package/src/lib/tools/src/schematics/setup/index.js +0 -80
- package/src/lib/tools/src/schematics/setup/index.js.map +0 -1
- package/src/lib/tools/src/schematics/utils/angular.js +0 -27
- package/src/lib/tools/src/schematics/utils/angular.js.map +0 -1
- package/src/lib/tools/src/schematics/utils/dependencies.js +0 -49
- package/src/lib/tools/src/schematics/utils/dependencies.js.map +0 -1
- package/src/lib/tools/src/schematics/utils/index.js +0 -8
- package/src/lib/tools/src/schematics/utils/index.js.map +0 -1
- package/src/lib/tools/src/schematics/utils/versions.js +0 -13
- package/src/lib/tools/src/schematics/utils/versions.js.map +0 -1
- package/src/lib/tools/src/schematics/utils/workspace.js +0 -24
- package/src/lib/tools/src/schematics/utils/workspace.js.map +0 -1
- /package/src/lib/tools/{src/schematics → schematics}/jsonc-parser.d.ts +0 -0
- /package/src/lib/tools/{src/schematics → schematics}/semver.d.ts +0 -0
- /package/src/lib/tools/{src/schematics → schematics}/setup/schema.d.ts +0 -0
- /package/src/lib/tools/{src/schematics → schematics}/setup/schema.json +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var schema_default = {
|
|
2
|
+
version: 2,
|
|
3
|
+
cli: "nx",
|
|
4
|
+
title: "Vitest Builder for Angular",
|
|
5
|
+
description: "Run unit tests using Vitest.",
|
|
6
|
+
type: "object",
|
|
7
|
+
properties: {
|
|
8
|
+
"configFile": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The path to the local vitest config",
|
|
11
|
+
"x-completion-type": "file",
|
|
12
|
+
"x-completion-glob": "@(vitest|vite).config@(.js|.ts)",
|
|
13
|
+
"aliases": ["config"]
|
|
14
|
+
},
|
|
15
|
+
"reportsDirectory": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "Directory to write coverage report to."
|
|
18
|
+
},
|
|
19
|
+
"mode": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Mode for Vite."
|
|
22
|
+
},
|
|
23
|
+
"testFiles": {
|
|
24
|
+
"aliases": ["testFile"],
|
|
25
|
+
"type": "array",
|
|
26
|
+
"items": { "type": "string" }
|
|
27
|
+
},
|
|
28
|
+
"watch": {
|
|
29
|
+
"description": "Watch files for changes and rerun tests related to changed files.",
|
|
30
|
+
"type": "boolean"
|
|
31
|
+
},
|
|
32
|
+
"ui": {
|
|
33
|
+
"description": "Run tests using Vitest UI Mode.",
|
|
34
|
+
"type": "boolean"
|
|
35
|
+
},
|
|
36
|
+
"coverage": {
|
|
37
|
+
"description": "Enable code coverage analysis.",
|
|
38
|
+
"type": "boolean"
|
|
39
|
+
},
|
|
40
|
+
"update": {
|
|
41
|
+
"description": "Update snapshot.",
|
|
42
|
+
"type": "boolean",
|
|
43
|
+
"aliases": ["u"]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
required: []
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { schema_default as default };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../../../../src/lib/builders/test/schema.json"],"sourcesContent":["{\n \"version\": 2,\n \"cli\": \"nx\",\n \"title\": \"Vitest Builder for Angular\",\n \"description\": \"Run unit tests using Vitest.\",\n \"type\": \"object\",\n \"properties\": {\n \"configFile\": {\n \"type\": \"string\",\n \"description\": \"The path to the local vitest config\",\n \"x-completion-type\": \"file\",\n \"x-completion-glob\": \"@(vitest|vite).config@(.js|.ts)\",\n \"aliases\": [\"config\"]\n },\n \"reportsDirectory\": {\n \"type\": \"string\",\n \"description\": \"Directory to write coverage report to.\"\n },\n \"mode\": {\n \"type\": \"string\",\n \"description\": \"Mode for Vite.\"\n },\n \"testFiles\": {\n \"aliases\": [\"testFile\"],\n \"type\": \"array\",\n \"items\": { \"type\": \"string\" }\n },\n \"watch\": {\n \"description\": \"Watch files for changes and rerun tests related to changed files.\",\n \"type\": \"boolean\"\n },\n \"ui\": {\n \"description\": \"Run tests using Vitest UI Mode.\",\n \"type\": \"boolean\"\n },\n \"coverage\": {\n \"description\": \"Enable code coverage analysis.\",\n \"type\": \"boolean\"\n },\n \"update\": {\n \"description\": \"Update snapshot.\",\n \"type\": \"boolean\",\n \"aliases\": [\"u\"]\n }\n },\n \"required\": []\n}\n"],"mappings":""}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
"reportsDirectory": {
|
|
16
|
-
"type": "string",
|
|
17
|
-
"description": "Directory to write coverage report to."
|
|
18
|
-
},
|
|
19
|
-
"mode": {
|
|
20
|
-
"type": "string",
|
|
21
|
-
"description": "Mode for Vite."
|
|
22
|
-
},
|
|
23
|
-
"testFiles": {
|
|
24
|
-
"aliases": ["testFile"],
|
|
25
|
-
"type": "array",
|
|
26
|
-
"items": { "type": "string" }
|
|
27
|
-
},
|
|
28
|
-
"watch": {
|
|
29
|
-
"description": "Watch files for changes and rerun tests related to changed files.",
|
|
30
|
-
"type": "boolean"
|
|
31
|
-
},
|
|
32
|
-
"ui": {
|
|
33
|
-
"description": "Run tests using Vitest UI Mode.",
|
|
34
|
-
"type": "boolean"
|
|
35
|
-
},
|
|
36
|
-
"coverage": {
|
|
37
|
-
"description": "Enable code coverage analysis.",
|
|
38
|
-
"type": "boolean"
|
|
39
|
-
},
|
|
40
|
-
"update": {
|
|
41
|
-
"description": "Update snapshot.",
|
|
42
|
-
"type": "boolean",
|
|
43
|
-
"aliases": ["u"]
|
|
44
|
-
}
|
|
2
|
+
"version": 2,
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"title": "Vitest Builder for Angular",
|
|
5
|
+
"description": "Run unit tests using Vitest.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"configFile": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The path to the local vitest config",
|
|
11
|
+
"x-completion-type": "file",
|
|
12
|
+
"x-completion-glob": "@(vitest|vite).config@(.js|.ts)",
|
|
13
|
+
"aliases": ["config"]
|
|
45
14
|
},
|
|
46
|
-
"
|
|
15
|
+
"reportsDirectory": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "Directory to write coverage report to."
|
|
18
|
+
},
|
|
19
|
+
"mode": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Mode for Vite."
|
|
22
|
+
},
|
|
23
|
+
"testFiles": {
|
|
24
|
+
"aliases": ["testFile"],
|
|
25
|
+
"type": "array",
|
|
26
|
+
"items": { "type": "string" }
|
|
27
|
+
},
|
|
28
|
+
"watch": {
|
|
29
|
+
"description": "Watch files for changes and rerun tests related to changed files.",
|
|
30
|
+
"type": "boolean"
|
|
31
|
+
},
|
|
32
|
+
"ui": {
|
|
33
|
+
"description": "Run tests using Vitest UI Mode.",
|
|
34
|
+
"type": "boolean"
|
|
35
|
+
},
|
|
36
|
+
"coverage": {
|
|
37
|
+
"description": "Enable code coverage analysis.",
|
|
38
|
+
"type": "boolean"
|
|
39
|
+
},
|
|
40
|
+
"update": {
|
|
41
|
+
"description": "Update snapshot.",
|
|
42
|
+
"type": "boolean",
|
|
43
|
+
"aliases": ["u"]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"required": []
|
|
47
47
|
}
|
|
@@ -1,61 +1,51 @@
|
|
|
1
|
-
import { createBuilder
|
|
1
|
+
import { createBuilder } from "@angular-devkit/architect";
|
|
2
|
+
//#region packages/vitest-angular/src/lib/builders/test/vitest.impl.ts
|
|
2
3
|
async function vitestBuilder(options, context) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
process.on('SIGINT', processExit);
|
|
40
|
-
process.on('SIGTERM', processExit);
|
|
41
|
-
process.on('exit', processExit);
|
|
42
|
-
}
|
|
43
|
-
// vitest sets the exitCode = 1 when code coverage isn't met
|
|
44
|
-
hasErrors = (process.exitCode && process.exitCode !== 0);
|
|
45
|
-
return {
|
|
46
|
-
success: !hasErrors,
|
|
47
|
-
};
|
|
4
|
+
process.env["TEST"] = "true";
|
|
5
|
+
process.env["VITEST"] = "true";
|
|
6
|
+
const { startVitest } = await Function("return import(\"vitest/node\")")();
|
|
7
|
+
const projectConfig = await context.getProjectMetadata(context.target);
|
|
8
|
+
const { coverageArgs, ...extraArgs } = await getExtraArgs(options);
|
|
9
|
+
const watch = options.watch === true;
|
|
10
|
+
const ui = options.ui === true;
|
|
11
|
+
const coverageEnabled = options.coverage === true;
|
|
12
|
+
const update = options.update === true;
|
|
13
|
+
const config = {
|
|
14
|
+
root: `${projectConfig["root"] || "."}`,
|
|
15
|
+
watch,
|
|
16
|
+
ui,
|
|
17
|
+
config: options.configFile,
|
|
18
|
+
coverage: {
|
|
19
|
+
enabled: coverageEnabled,
|
|
20
|
+
...coverageArgs
|
|
21
|
+
},
|
|
22
|
+
update,
|
|
23
|
+
...extraArgs
|
|
24
|
+
};
|
|
25
|
+
const viteOverrides = { test: { watch } };
|
|
26
|
+
const server = await startVitest("test", options.testFiles ?? [], config, viteOverrides);
|
|
27
|
+
let hasErrors = false;
|
|
28
|
+
const processExit = () => {
|
|
29
|
+
server?.exit();
|
|
30
|
+
if (hasErrors) process.exit(1);
|
|
31
|
+
else process.exit(0);
|
|
32
|
+
};
|
|
33
|
+
if (options.watch) {
|
|
34
|
+
process.once("SIGINT", processExit);
|
|
35
|
+
process.once("SIGTERM", processExit);
|
|
36
|
+
process.once("exit", processExit);
|
|
37
|
+
}
|
|
38
|
+
hasErrors = process.exitCode && process.exitCode !== 0;
|
|
39
|
+
return { success: !hasErrors };
|
|
48
40
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!schema.default.properties[key]) {
|
|
55
|
-
extraArgs[key] = options[key];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return extraArgs;
|
|
41
|
+
async function getExtraArgs(options) {
|
|
42
|
+
const schema = await import("./schema.json", { with: { type: "json" } });
|
|
43
|
+
const extraArgs = {};
|
|
44
|
+
for (const key of Object.keys(options)) if (!schema.default.properties[key]) extraArgs[key] = options[key];
|
|
45
|
+
return extraArgs;
|
|
59
46
|
}
|
|
60
|
-
|
|
61
|
-
//#
|
|
47
|
+
var vitest_impl_default = createBuilder(vitestBuilder);
|
|
48
|
+
//#endregion
|
|
49
|
+
export { vitest_impl_default as default };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=vitest.impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest.impl.js","names":[],"sources":["../../../../../src/lib/builders/test/vitest.impl.ts"],"sourcesContent":["import {\n BuilderContext,\n BuilderOutput,\n createBuilder,\n} from '@angular-devkit/architect';\n\nimport { VitestSchema } from './schema';\n\nasync function vitestBuilder(\n options: VitestSchema,\n context: BuilderContext,\n): Promise<BuilderOutput> {\n process.env['TEST'] = 'true';\n process.env['VITEST'] = 'true';\n\n const { startVitest } = await (Function(\n 'return import(\"vitest/node\")',\n )() as Promise<typeof import('vitest/node')>);\n\n const projectConfig = await context.getProjectMetadata(\n context.target as unknown as string,\n );\n const { coverageArgs, ...extraArgs } = await getExtraArgs(options);\n const watch = options.watch === true;\n const ui = options.ui === true;\n const coverageEnabled = options.coverage === true;\n const update = options.update === true;\n const config = {\n root: `${projectConfig['root'] || '.'}`,\n watch,\n ui,\n config: options.configFile,\n coverage: {\n enabled: coverageEnabled,\n ...coverageArgs,\n },\n update,\n ...extraArgs,\n };\n const viteOverrides: any = {\n test: { watch },\n };\n\n const server = await startVitest(\n 'test',\n options.testFiles ?? [],\n config,\n viteOverrides,\n );\n\n let hasErrors = false;\n\n const processExit = () => {\n server?.exit();\n if (hasErrors) {\n process.exit(1);\n } else {\n process.exit(0);\n }\n };\n\n // .once() prevents listener stacking across repeated Nx executor runs\n // that share the same host process (avoids MaxListenersExceededWarning).\n if (options.watch) {\n process.once('SIGINT', processExit);\n process.once('SIGTERM', processExit);\n process.once('exit', processExit);\n }\n\n // vitest sets the exitCode = 1 when code coverage isn't met\n hasErrors = (process.exitCode && process.exitCode !== 0) as boolean;\n\n return {\n success: !hasErrors,\n };\n}\n\nexport async function getExtraArgs(\n options: VitestSchema,\n): Promise<Record<string, any>> {\n // support passing extra args to Vitest CLI\n const schema = await import('./schema.json', { with: { type: 'json' } });\n const extraArgs: Record<string, any> = {};\n for (const key of Object.keys(options)) {\n if (!(schema as any).default.properties[key]) {\n extraArgs[key] = (options as any)[key];\n }\n }\n\n return extra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,QAAO;;AAGT,IAAA,sBAAe,cAAc,cAAc"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//#region packages/vitest-angular/src/lib/snapshot-serializers/angular-fixture.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if is an Angular fixture
|
|
4
|
+
*
|
|
5
|
+
* @param val Angular fixture
|
|
6
|
+
* @returns boolean who check if is an angular fixture
|
|
7
|
+
*/
|
|
8
|
+
function isAngularFixture(val) {
|
|
9
|
+
if (typeof val !== "object") return false;
|
|
10
|
+
if (val["componentRef"] || val["componentInstance"]) return true;
|
|
11
|
+
if (val["componentType"]) return true;
|
|
12
|
+
return JSON.stringify(Object.keys(val)) === JSON.stringify([
|
|
13
|
+
"componentRef",
|
|
14
|
+
"ngZone",
|
|
15
|
+
"effectRunner",
|
|
16
|
+
"_autoDetect",
|
|
17
|
+
"_isStable",
|
|
18
|
+
"_isDestroyed",
|
|
19
|
+
"_resolve",
|
|
20
|
+
"_promise",
|
|
21
|
+
"_onUnstableSubscription",
|
|
22
|
+
"_onStableSubscription",
|
|
23
|
+
"_onMicrotaskEmptySubscription",
|
|
24
|
+
"_onErrorSubscription",
|
|
25
|
+
"changeDetectorRef",
|
|
26
|
+
"elementRef",
|
|
27
|
+
"debugElement",
|
|
28
|
+
"componentInstance",
|
|
29
|
+
"nativeElement"
|
|
30
|
+
]) || JSON.stringify(Object.keys(val)) === JSON.stringify([
|
|
31
|
+
"location",
|
|
32
|
+
"_rootLView",
|
|
33
|
+
"_tNode",
|
|
34
|
+
"previousInputValues",
|
|
35
|
+
"instance",
|
|
36
|
+
"changeDetectorRef",
|
|
37
|
+
"hostView",
|
|
38
|
+
"componentType"
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Serialize Angular fixture for Vitest
|
|
43
|
+
*
|
|
44
|
+
* @param fixture Angular Fixture Component
|
|
45
|
+
* @returns HTML Child Node
|
|
46
|
+
*/
|
|
47
|
+
function fixtureVitestSerializer(fixture) {
|
|
48
|
+
const componentType = fixture && fixture.componentType ? fixture.componentType : fixture.componentRef.componentType;
|
|
49
|
+
let inputsData = "";
|
|
50
|
+
const selector = Reflect.getOwnPropertyDescriptor(componentType, "__annotations__")?.value[0]?.selector ?? componentType.ɵcmp?.selectors[0]?.[0];
|
|
51
|
+
if (componentType && componentType.propDecorators) inputsData = Object.entries(componentType.propDecorators).map(([key, value]) => `${key}="${value}"`).join("");
|
|
52
|
+
const divElement = fixture && fixture.nativeElement ? fixture.nativeElement : fixture.location.nativeElement;
|
|
53
|
+
return new DOMParser().parseFromString(`<${selector} ${inputsData}>${divElement.innerHTML}</${selector}>`, "text/html").body.childNodes[0];
|
|
54
|
+
}
|
|
55
|
+
function normalizeSnapshotOutput(value) {
|
|
56
|
+
return value.replace(/[ \t]+$/gm, "").replace(/\n{3,}/g, "\n\n");
|
|
57
|
+
}
|
|
58
|
+
function createAngularFixtureSnapshotSerializer() {
|
|
59
|
+
return {
|
|
60
|
+
serialize(val, config, indentation, depth, refs, printer) {
|
|
61
|
+
return normalizeSnapshotOutput(printer(fixtureVitestSerializer(val), config, indentation, depth, refs));
|
|
62
|
+
},
|
|
63
|
+
test(val) {
|
|
64
|
+
return val && isAngularFixture(val);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { createAngularFixtureSnapshotSerializer };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=angular-fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angular-fixture.js","names":[],"sources":["../../../../src/lib/snapshot-serializers/angular-fixture.ts"],"sourcesContent":["import type { ComponentFixture } from '@angular/core/testing';\nimport type { SnapshotSerializer } from 'vitest';\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 =\n Reflect.getOwnPropertyDescriptor(componentType, '__annotations__')?.value[0]\n ?.selector ?? componentType.ɵcmp?.selectors[0]?.[0];\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\nfunction normalizeSnapshotOutput(value: string): string {\n return (\n value\n // Inline snapshots should not fail after formatters strip trailing spaces.\n .replace(/[ \\t]+$/gm, '')\n // Comment removal can leave repeated empty lines in pretty-printed output.\n .replace(/\\n{3,}/g, '\\n\\n')\n );\n}\n\nexport function createAngularFixtureSnapshotSerializer(): SnapshotSerializer {\n return {\n serialize(val, config, indentation, depth, refs, printer) {\n return normalizeSnapshotOutput(\n printer(fixtureVitestSerializer(val), config, indentation, depth, refs),\n );\n },\n test(val) {\n return val && isAngularFixture(val);\n },\n };\n}\n"],"mappings":";;;;;;;AASA,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,SAAc;CAE7C,MAAM,gBACJ,WAAW,QAAQ,gBACf,QAAQ,gBACR,QAAQ,aAAa;CAG3B,IAAI,aAAa;CAEjB,MAAM,WACJ,QAAQ,yBAAyB,eAAe,kBAAkB,EAAE,MAAM,IACtE,YAAY,cAAc,MAAM,UAAU,KAAK;AAErD,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,SAAS,wBAAwB,OAAuB;AACtD,QACE,MAEG,QAAQ,aAAa,GAAG,CAExB,QAAQ,WAAW,OAAO;;AAIjC,SAAgB,yCAA6D;AAC3E,QAAO;EACL,UAAU,KAAK,QAAQ,aAAa,OAAO,MAAM,SAAS;AACxD,UAAO,wBACL,QAAQ,wBAAwB,IAAI,EAAE,QAAQ,aAAa,OAAO,KAAK,CACxE;;EAEH,KAAK,KAAK;AACR,UAAO,OAAO,iBAAiB,IAAI;;EAEtC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region packages/vitest-angular/src/lib/snapshot-serializers/html-comment.ts
|
|
2
|
+
function createHtmlCommentSnapshotSerializer() {
|
|
3
|
+
return {
|
|
4
|
+
serialize: () => "",
|
|
5
|
+
test: (val) => typeof Comment !== "undefined" && val instanceof Comment
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { createHtmlCommentSnapshotSerializer };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=html-comment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-comment.js","names":[],"sources":["../../../../src/lib/snapshot-serializers/html-comment.ts"],"sourcesContent":["import { type SnapshotSerializer } from 'vitest';\n\nexport function createHtmlCommentSnapshotSerializer(): SnapshotSerializer {\n return {\n serialize: () => '',\n test: (val: any): boolean =>\n typeof Comment !== 'undefined' && val instanceof Comment,\n };\n}\n"],"mappings":";AAEA,SAAgB,sCAA0D;AACxE,QAAO;EACL,iBAAiB;EACjB,OAAO,QACL,OAAO,YAAY,eAAe,eAAe;EACpD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region packages/vitest-angular/src/lib/snapshot-serializers/no-ng-attributes.ts
|
|
2
|
+
var CLEANED_ELEMENT_MARKER = "__analogSnapshotCleaned__";
|
|
3
|
+
var attributesToRemovePatterns = [
|
|
4
|
+
"ng-reflect",
|
|
5
|
+
"_nghost",
|
|
6
|
+
"_ngcontent",
|
|
7
|
+
"ng-version"
|
|
8
|
+
];
|
|
9
|
+
var attributesToClean = {
|
|
10
|
+
class: [/^(?:mat|cdk|ng).*-\w*\d+-\d+$/, /^ng-star-inserted$/],
|
|
11
|
+
id: [/^(?:mat|cdk|ng).*-\w*\d+$/],
|
|
12
|
+
for: [/^(?:mat|cdk|ng).*-\d+$/],
|
|
13
|
+
"aria-owns": [/^(?:mat|cdk|ng).*-\d+$/],
|
|
14
|
+
"aria-labelledby": [/^(?:mat|cdk|ng).*-\d+$/],
|
|
15
|
+
"aria-controls": [/^(?:mat|cdk|ng).*-\d+$/],
|
|
16
|
+
"aria-describedby": [/^(?:mat|cdk|ng).*-\d+$/]
|
|
17
|
+
};
|
|
18
|
+
var hasAttributesToRemove = (attribute) => attributesToRemovePatterns.some((removePattern) => attribute.name.startsWith(removePattern));
|
|
19
|
+
var hasAttributesToClean = (attribute) => Object.prototype.hasOwnProperty.call(attributesToClean, attribute.name);
|
|
20
|
+
var attributeNeedsCleaning = (attribute) => hasAttributesToClean(attribute) && attribute.value.split(" ").some((attrValue) => attributesToClean[attribute.name].some((attributeCleanRegex) => attributeCleanRegex.test(attrValue)));
|
|
21
|
+
var shouldSerializeElement = (node) => {
|
|
22
|
+
if (node.parentElement?.tagName === "BODY" && node.hasAttribute("id")) return true;
|
|
23
|
+
return Array.from(node.attributes).some((attribute) => hasAttributesToRemove(attribute) || attributeNeedsCleaning(attribute));
|
|
24
|
+
};
|
|
25
|
+
function cleanAngularElementAttributes(node) {
|
|
26
|
+
const nodeCopy = node.cloneNode(true);
|
|
27
|
+
Object.defineProperty(nodeCopy, CLEANED_ELEMENT_MARKER, {
|
|
28
|
+
configurable: true,
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
if (node.parentElement?.tagName === "BODY") nodeCopy.removeAttribute("id");
|
|
32
|
+
Array.from(nodeCopy.attributes).forEach((attribute) => {
|
|
33
|
+
if (hasAttributesToRemove(attribute)) {
|
|
34
|
+
nodeCopy.removeAttribute(attribute.name);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (hasAttributesToClean(attribute)) {
|
|
38
|
+
const cleanedValue = attribute.value.split(" ").filter((attrValue) => !attributesToClean[attribute.name].some((attributeCleanRegex) => attributeCleanRegex.test(attrValue))).join(" ");
|
|
39
|
+
if (cleanedValue === "") {
|
|
40
|
+
nodeCopy.removeAttribute(attribute.name);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
nodeCopy.setAttribute(attribute.name, cleanedValue);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return nodeCopy;
|
|
47
|
+
}
|
|
48
|
+
function createNoNgAttributesSnapshotSerializer() {
|
|
49
|
+
return {
|
|
50
|
+
serialize(val, config, indentation, depth, refs, printer) {
|
|
51
|
+
const cleanedNode = cleanAngularElementAttributes(val);
|
|
52
|
+
if (shouldSerializeElement(cleanedNode)) throw new Error(`NoNgAttributes serializer did not stabilize for <${cleanedNode.tagName.toLowerCase()}>`);
|
|
53
|
+
return printer(cleanedNode, config, indentation, depth, refs);
|
|
54
|
+
},
|
|
55
|
+
test(val) {
|
|
56
|
+
return typeof Element !== "undefined" && val instanceof Element && !val[CLEANED_ELEMENT_MARKER] && shouldSerializeElement(val);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { createNoNgAttributesSnapshotSerializer };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=no-ng-attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-ng-attributes.js","names":[],"sources":["../../../../src/lib/snapshot-serializers/no-ng-attributes.ts"],"sourcesContent":["import { type SnapshotSerializer } from 'vitest';\n\nconst CLEANED_ELEMENT_MARKER = '__analogSnapshotCleaned__';\n\nexport const attributesToRemovePatterns = [\n 'ng-reflect',\n '_nghost',\n '_ngcontent',\n 'ng-version',\n];\n\nexport const attributesToClean: Record<string, RegExp[]> = {\n class: [/^(?:mat|cdk|ng).*-\\w*\\d+-\\d+$/, /^ng-star-inserted$/],\n id: [/^(?:mat|cdk|ng).*-\\w*\\d+$/],\n for: [/^(?:mat|cdk|ng).*-\\d+$/],\n 'aria-owns': [/^(?:mat|cdk|ng).*-\\d+$/],\n 'aria-labelledby': [/^(?:mat|cdk|ng).*-\\d+$/],\n 'aria-controls': [/^(?:mat|cdk|ng).*-\\d+$/],\n 'aria-describedby': [/^(?:mat|cdk|ng).*-\\d+$/],\n};\n\nconst hasAttributesToRemove = (attribute: Attr): boolean =>\n attributesToRemovePatterns.some((removePattern) =>\n attribute.name.startsWith(removePattern),\n );\n\nconst hasAttributesToClean = (attribute: Attr): boolean =>\n Object.prototype.hasOwnProperty.call(attributesToClean, attribute.name);\n\nconst attributeNeedsCleaning = (attribute: Attr): boolean =>\n hasAttributesToClean(attribute) &&\n attribute.value\n .split(' ')\n .some((attrValue) =>\n attributesToClean[attribute.name].some((attributeCleanRegex) =>\n attributeCleanRegex.test(attrValue),\n ),\n );\n\nconst shouldSerializeElement = (node: Element): boolean => {\n if (node.parentElement?.tagName === 'BODY' && node.hasAttribute('id')) {\n return true;\n }\n\n return Array.from(node.attributes).some(\n (attribute) =>\n hasAttributesToRemove(attribute) || attributeNeedsCleaning(attribute),\n );\n};\n\nfunction cleanAngularElementAttributes(node: Element): Element {\n const nodeCopy = node.cloneNode(true) as Element;\n\n Object.defineProperty(nodeCopy, CLEANED_ELEMENT_MARKER, {\n configurable: true,\n value: true,\n });\n\n if (node.parentElement?.tagName === 'BODY') {\n nodeCopy.removeAttribute('id');\n }\n\n Array.from(nodeCopy.attributes).forEach((attribute) => {\n if (hasAttributesToRemove(attribute)) {\n nodeCopy.removeAttribute(attribute.name);\n return;\n }\n\n if (hasAttributesToClean(attribute)) {\n const cleanedValue = attribute.value\n .split(' ')\n .filter(\n (attrValue) =>\n !attributesToClean[attribute.name].some((attributeCleanRegex) =>\n attributeCleanRegex.test(attrValue),\n ),\n )\n .join(' ');\n\n if (cleanedValue === '') {\n nodeCopy.removeAttribute(attribute.name);\n return;\n }\n\n nodeCopy.setAttribute(attribute.name, cleanedValue);\n }\n });\n\n return nodeCopy;\n}\n\nexport function createNoNgAttributesSnapshotSerializer(): SnapshotSerializer {\n return {\n serialize(val, config, indentation, depth, refs, printer): string {\n const cleanedNode = cleanAngularElementAttributes(val);\n\n if (shouldSerializeElement(cleanedNode)) {\n throw new Error(\n `NoNgAttributes serializer did not stabilize for <${cleanedNode.tagName.toLowerCase()}>`,\n );\n }\n\n return printer(cleanedNode, config, indentation, depth, refs);\n },\n test(val): boolean {\n const matches =\n typeof Element !== 'undefined' &&\n val instanceof Element &&\n !(val as Element & Record<string, unknown>)[CLEANED_ELEMENT_MARKER] &&\n shouldSerializeElement(val);\n\n return matches;\n },\n };\n}\n"],"mappings":";AAEA,IAAM,yBAAyB;AAE/B,IAAa,6BAA6B;CACxC;CACA;CACA;CACA;CACD;AAED,IAAa,oBAA8C;CACzD,OAAO,CAAC,iCAAiC,qBAAqB;CAC9D,IAAI,CAAC,4BAA4B;CACjC,KAAK,CAAC,yBAAyB;CAC/B,aAAa,CAAC,yBAAyB;CACvC,mBAAmB,CAAC,yBAAyB;CAC7C,iBAAiB,CAAC,yBAAyB;CAC3C,oBAAoB,CAAC,yBAAyB;CAC/C;AAED,IAAM,yBAAyB,cAC7B,2BAA2B,MAAM,kBAC/B,UAAU,KAAK,WAAW,cAAc,CACzC;AAEH,IAAM,wBAAwB,cAC5B,OAAO,UAAU,eAAe,KAAK,mBAAmB,UAAU,KAAK;AAEzE,IAAM,0BAA0B,cAC9B,qBAAqB,UAAU,IAC/B,UAAU,MACP,MAAM,IAAI,CACV,MAAM,cACL,kBAAkB,UAAU,MAAM,MAAM,wBACtC,oBAAoB,KAAK,UAAU,CACpC,CACF;AAEL,IAAM,0BAA0B,SAA2B;AACzD,KAAI,KAAK,eAAe,YAAY,UAAU,KAAK,aAAa,KAAK,CACnE,QAAO;AAG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ematics/setup/index#setupSchematic",
|
|
7
|
+
"schema": "./schematics/setup/schema.json"
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { setupSchematic } from "./schematics/setup/index";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<% if (majorAngularVersion > 20) { %>
|
|
2
2
|
import '@angular/compiler';
|
|
3
3
|
import '@analogjs/vitest-angular/setup-snapshots';
|
|
4
|
+
import '@analogjs/vitest-angular/setup-serializers';
|
|
4
5
|
import { setupTestBed } from '@analogjs/vitest-angular/setup-testbed';
|
|
5
6
|
|
|
6
7
|
<% if (browserMode) { %>
|
|
@@ -2,17 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { defineConfig } from 'vite';
|
|
4
4
|
import angular from '@analogjs/vite-plugin-angular';
|
|
5
|
-
<% if (isNx) { %>import
|
|
6
|
-
<% } else { %>import viteTsConfigPaths from 'vite-tsconfig-paths';<% } %>
|
|
5
|
+
<% if (!isNx) { %>import viteTsConfigPaths from 'vite-tsconfig-paths';<% } %>
|
|
7
6
|
<% if (browserMode) { %>import { playwright } from '@vitest/browser-playwright';<% } %>
|
|
8
7
|
|
|
9
8
|
// https://vitejs.dev/config/
|
|
10
9
|
export default defineConfig(({ mode }) => ({
|
|
11
|
-
<% if (isNx) { %>
|
|
12
|
-
plugins: [angular(), nxViteTsPaths()],
|
|
13
|
-
<% } else { %>
|
|
14
|
-
plugins: [angular(), viteTsConfigPaths()],
|
|
15
|
-
<% } %>
|
|
10
|
+
plugins: [angular()<% if (!isNx) { %>, viteTsConfigPaths()<% } %>],
|
|
16
11
|
test: {
|
|
17
12
|
globals: true,
|
|
18
13
|
<% if (browserMode) { %>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const require_angular = require("../utils/angular.js");
|
|
2
|
+
const require_workspace = require("../utils/workspace.js");
|
|
3
|
+
const require_dependencies = require("../utils/dependencies.js");
|
|
4
|
+
require("../utils/index.js");
|
|
5
|
+
let _angular_devkit_schematics = require("@angular-devkit/schematics");
|
|
6
|
+
let _angular_devkit_schematics_tasks = require("@angular-devkit/schematics/tasks");
|
|
7
|
+
let jsonc_parser = require("jsonc-parser");
|
|
8
|
+
//#region packages/vitest-angular-tools/src/schematics/setup/index.ts
|
|
9
|
+
function updateTsConfigSpec(tree, projectRoot) {
|
|
10
|
+
const tsConfigPath = projectRoot ? `${projectRoot}/tsconfig.spec.json` : "tsconfig.spec.json";
|
|
11
|
+
if (!tree.exists(tsConfigPath)) return;
|
|
12
|
+
const tsConfigContent = tree.read(tsConfigPath);
|
|
13
|
+
if (!tsConfigContent) return;
|
|
14
|
+
const tsConfig = (0, jsonc_parser.parse)(tsConfigContent.toString("utf-8"));
|
|
15
|
+
tsConfig.compilerOptions = tsConfig.compilerOptions || {};
|
|
16
|
+
delete tsConfig.compilerOptions.module;
|
|
17
|
+
tsConfig.compilerOptions.target = "es2022";
|
|
18
|
+
const filteredTypes = (tsConfig.compilerOptions.types || ["node"]).filter((t) => t !== "jest" && t !== "jasmine");
|
|
19
|
+
if (!filteredTypes.includes("vitest/globals")) filteredTypes.push("vitest/globals");
|
|
20
|
+
tsConfig.compilerOptions.types = filteredTypes;
|
|
21
|
+
tsConfig.files = ["src/test-setup.ts"];
|
|
22
|
+
tree.overwrite(tsConfigPath, JSON.stringify(tsConfig, null, 2) + "\n");
|
|
23
|
+
}
|
|
24
|
+
function updateAngularJson(tree, projectName) {
|
|
25
|
+
const workspace = require_workspace.getWorkspace(tree);
|
|
26
|
+
const project = workspace.projects[projectName];
|
|
27
|
+
if (!project.architect) project.architect = {};
|
|
28
|
+
project.architect["test"] = { builder: "@analogjs/vitest-angular:test" };
|
|
29
|
+
tree.overwrite("angular.json", JSON.stringify(workspace, null, 2) + "\n");
|
|
30
|
+
}
|
|
31
|
+
function generateFiles(projectRoot, majorAngularVersion, isNx, browserMode) {
|
|
32
|
+
return (0, _angular_devkit_schematics.mergeWith)((0, _angular_devkit_schematics.apply)((0, _angular_devkit_schematics.url)("./files"), [(0, _angular_devkit_schematics.applyTemplates)({
|
|
33
|
+
majorAngularVersion,
|
|
34
|
+
isNx,
|
|
35
|
+
browserMode
|
|
36
|
+
}), (0, _angular_devkit_schematics.move)(projectRoot)]));
|
|
37
|
+
}
|
|
38
|
+
function setupSchematic(options) {
|
|
39
|
+
return (tree, context) => {
|
|
40
|
+
const angularVersion = require_angular.getAngularVersion(tree);
|
|
41
|
+
const majorAngularVersion = require_angular.getMajorAngularVersion(angularVersion);
|
|
42
|
+
const projectRoot = require_workspace.getProject(require_workspace.getWorkspace(tree), options.project).root || "";
|
|
43
|
+
const isNx = require_workspace.isNxWorkspace(tree);
|
|
44
|
+
const browserMode = options.browserMode ?? false;
|
|
45
|
+
require_dependencies.addDevDependencies(tree, angularVersion, { browserMode });
|
|
46
|
+
updateTsConfigSpec(tree, projectRoot);
|
|
47
|
+
updateAngularJson(tree, options.project);
|
|
48
|
+
context.addTask(new _angular_devkit_schematics_tasks.NodePackageInstallTask());
|
|
49
|
+
return (0, _angular_devkit_schematics.chain)([generateFiles(projectRoot, majorAngularVersion, isNx, browserMode)]);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.setupSchematic = setupSchematic;
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../../vitest-angular-tools/src/schematics/setup/index.ts"],"sourcesContent":["import {\n Rule,\n Tree,\n apply,\n url,\n applyTemplates,\n move,\n chain,\n mergeWith,\n SchematicContext,\n} from '@angular-devkit/schematics';\nimport { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';\nimport { parse } from 'jsonc-parser';\nimport {\n getAngularVersion,\n getMajorAngularVersion,\n getWorkspace,\n getProject,\n addDevDependencies,\n isNxWorkspace,\n} from '../utils';\nimport { Schema } from './schema';\n\nfunction updateTsConfigSpec(tree: Tree, projectRoot: string): void {\n const tsConfigPath = projectRoot\n ? `${projectRoot}/tsconfig.spec.json`\n : 'tsconfig.spec.json';\n\n if (!tree.exists(tsConfigPath)) {\n return;\n }\n\n const tsConfigContent = tree.read(tsConfigPath);\n if (!tsConfigContent) {\n return;\n }\n\n const tsConfig = parse(tsConfigContent.toString('utf-8')) as Record<\n string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n >;\n\n tsConfig.compilerOptions = tsConfig.compilerOptions || {};\n\n // Remove module (let Vite handle it)\n delete tsConfig.compilerOptions.module;\n\n // Set target to es2022\n tsConfig.compilerOptions.target = 'es2022';\n\n // Update types: remove jest, add vitest/globals\n const types: string[] = tsConfig.compilerOptions.types || ['node'];\n const filteredTypes = types.filter(\n (t: string) => t !== 'jest' && t !== 'jasmine',\n );\n if (!filteredTypes.includes('vitest/globals')) {\n filteredTypes.push('vitest/globals');\n }\n tsConfig.compilerOptions.types = filteredTypes;\n\n // Set files to include test-setup.ts\n tsConfig.files = ['src/test-setup.ts'];\n\n tree.overwrite(tsConfigPath, JSON.stringify(tsConfig, null, 2) + '\\n');\n}\n\nfunction updateAngularJson(tree: Tree, projectName: string): void {\n const workspace = getWorkspace(tree);\n const project = workspace.projects[projectName];\n\n if (!project.architect) {\n project.architect = {};\n }\n\n project.architect['test'] = {\n builder: '@analogjs/vitest-angular:test',\n };\n\n tree.overwrite('angular.json', JSON.stringify(workspace, null, 2) + '\\n');\n}\n\nfunction generateFiles(\n projectRoot: string,\n majorAngularVersion: number,\n isNx: boolean,\n browserMode: boolean,\n): Rule {\n return mergeWith(\n apply(url('./files'), [\n applyTemplates({\n majorAngularVersion,\n isNx,\n browserMode,\n }),\n move(projectRoot),\n ]),\n );\n}\n\nexport function setupSchematic(options: Schema): Rule {\n return (tree: Tree, context: SchematicContext) => {\n const angularVersion = getAngularVersion(tree);\n const majorAngularVersion = getMajorAngularVersion(angularVersion);\n\n const workspace = getWorkspace(tree);\n const project = getProject(workspace, options.project);\n const projectRoot = project.root || '';\n const isNx = isNxWorkspace(tree);\n\n const browserMode = options.browserMode ?? false;\n\n // Add devDependencies\n addDevDependencies(tree, angularVersion, { browserMode });\n\n // Update tsconfig.spec.json (if exists)\n updateTsConfigSpec(tree, projectRoot);\n\n // Update angular.json test target\n updateAngularJson(tree, options.project);\n\n // Schedule package install\n context.addTask(new NodePackageInstallTask());\n\n // Generate files\n return chain([\n generateFiles(projectRoot, majorAngularVersion, isNx, browserMode),\n ]);\n };\n}\n"],"mappings":";;;;;;;;AAuBA,SAAS,mBAAmB,MAAY,aAA2B;CACjE,MAAM,eAAe,cACjB,GAAG,YAAY,uBACf;AAEJ,KAAI,CAAC,KAAK,OAAO,aAAa,CAC5B;CAGF,MAAM,kBAAkB,KAAK,KAAK,aAAa;AAC/C,KAAI,CAAC,gBACH;CAGF,MAAM,YAAA,GAAA,aAAA,OAAiB,gBAAgB,SAAS,QAAQ,CAAC;AAMzD,UAAS,kBAAkB,SAAS,mBAAmB,EAAE;AAGzD,QAAO,SAAS,gBAAgB;AAGhC,UAAS,gBAAgB,SAAS;CAIlC,MAAM,iBADkB,SAAS,gBAAgB,SAAS,CAAC,OAAO,EACtC,QACzB,MAAc,MAAM,UAAU,MAAM,UACtC;AACD,KAAI,CAAC,cAAc,SAAS,iBAAiB,CAC3C,eAAc,KAAK,iBAAiB;AAEtC,UAAS,gBAAgB,QAAQ;AAGjC,UAAS,QAAQ,CAAC,oBAAoB;AAEtC,MAAK,UAAU,cAAc,KAAK,UAAU,UAAU,MAAM,EAAE,GAAG,KAAK;;AAGxE,SAAS,kBAAkB,MAAY,aAA2B;CAChE,MAAM,YAAY,kBAAA,aAAa,KAAK;CACpC,MAAM,UAAU,UAAU,SAAS;AAEnC,KAAI,CAAC,QAAQ,UACX,SAAQ,YAAY,EAAE;AAGxB,SAAQ,UAAU,UAAU,EAC1B,SAAS,iCACV;AAED,MAAK,UAAU,gBAAgB,KAAK,UAAU,WAAW,MAAM,EAAE,GAAG,KAAK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