@immense/vue-pom-generator 1.0.91 → 1.0.92
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 +60 -2
- package/RELEASE_NOTES.md +105 -22
- package/class-generation/base-page.ts +141 -59
- package/class-generation/diagnostics.ts +559 -0
- package/class-generation/index.ts +123 -21
- package/class-generation/playwright-types.ts +7 -11
- package/class-generation/pointer.ts +65 -18
- package/dist/class-generation/base-page.d.ts +19 -4
- package/dist/class-generation/base-page.d.ts.map +1 -1
- package/dist/class-generation/diagnostics.d.ts +110 -0
- package/dist/class-generation/diagnostics.d.ts.map +1 -0
- package/dist/class-generation/index.d.ts +3 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/class-generation/playwright-types.d.ts +3 -39
- package/dist/class-generation/playwright-types.d.ts.map +1 -1
- package/dist/class-generation/pointer.d.ts +10 -1
- package/dist/class-generation/pointer.d.ts.map +1 -1
- package/dist/eslint/index.cjs +52 -9
- package/dist/eslint/index.cjs.map +1 -1
- package/dist/eslint/index.d.ts +16 -7
- package/dist/eslint/index.d.ts.map +1 -1
- package/dist/eslint/index.mjs +52 -9
- package/dist/eslint/index.mjs.map +1 -1
- package/dist/index.cjs +419 -298
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +419 -298
- package/dist/index.mjs.map +1 -1
- package/dist/manifest-generator.d.ts +10 -5
- package/dist/manifest-generator.d.ts.map +1 -1
- package/dist/method-generation.d.ts.map +1 -1
- package/dist/playwright/reporter.cjs +174 -0
- package/dist/playwright/reporter.cjs.map +1 -0
- package/dist/playwright/reporter.d.ts +13 -0
- package/dist/playwright/reporter.d.ts.map +1 -0
- package/dist/playwright/reporter.mjs +174 -0
- package/dist/playwright/reporter.mjs.map +1 -0
- package/dist/plugin/internal/build-plugin.d.ts +2 -0
- package/dist/plugin/internal/build-plugin.d.ts.map +1 -1
- package/dist/plugin/internal/dev-plugin.d.ts +2 -0
- package/dist/plugin/internal/dev-plugin.d.ts.map +1 -1
- package/dist/plugin/internal-plugins.d.ts.map +1 -1
- package/dist/route-navigation-codegen.d.ts +3 -1
- package/dist/route-navigation-codegen.d.ts.map +1 -1
- package/dist/router-bridge.d.ts +14 -0
- package/dist/router-bridge.d.ts.map +1 -1
- package/dist/router.cjs +41 -1
- package/dist/router.cjs.map +1 -1
- package/dist/router.mjs +41 -1
- package/dist/router.mjs.map +1 -1
- package/dist/tests/broad/helpers/fake-runtime.d.ts +27 -3
- package/dist/tests/broad/helpers/fake-runtime.d.ts.map +1 -1
- package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts +16 -3
- package/dist/tests/fixtures/generated-tsc/base-page.full.d.ts.map +1 -1
- package/dist/tests/method-generation.test.d.ts +2 -0
- package/dist/tests/method-generation.test.d.ts.map +1 -0
- package/dist/tests/playwright-diagnostics.test.d.ts +2 -0
- package/dist/tests/playwright-diagnostics.test.d.ts.map +1 -0
- package/dist/tests/playwright-reporter.test.d.ts +2 -0
- package/dist/tests/playwright-reporter.test.d.ts.map +1 -0
- package/dist/transform.d.ts.map +1 -1
- package/dist/vite.config.d.ts.map +1 -1
- package/package.json +8 -1
package/dist/index.cjs
CHANGED
|
@@ -665,6 +665,10 @@ function upperFirst$1(value) {
|
|
|
665
665
|
}
|
|
666
666
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
667
667
|
}
|
|
668
|
+
function generatedActionMetadata(componentName, methodName, options = {}) {
|
|
669
|
+
const preferAssociatedLabel = options.preferAssociatedLabel ? ", preferAssociatedLabel: true" : "";
|
|
670
|
+
return `{ componentName: ${JSON.stringify(componentName)}, methodName: ${JSON.stringify(methodName)}${preferAssociatedLabel} }`;
|
|
671
|
+
}
|
|
668
672
|
function createParameters(params) {
|
|
669
673
|
return toTypeScriptPomParameterStructures(params);
|
|
670
674
|
}
|
|
@@ -690,7 +694,7 @@ function createAsyncMethod(name, parameters, statements) {
|
|
|
690
694
|
statements
|
|
691
695
|
});
|
|
692
696
|
}
|
|
693
|
-
function generateClickMethod(componentName, methodName, selector, alternateSelectors, parameters) {
|
|
697
|
+
function generateClickMethod(componentName, methodName, nativeRole, selector, alternateSelectors, parameters) {
|
|
694
698
|
const name = `click${methodName}`;
|
|
695
699
|
const noWaitName = `${name}NoWait`;
|
|
696
700
|
const locatorDescription = JSON.stringify(buildPomLocatorDescription({
|
|
@@ -704,6 +708,9 @@ function generateClickMethod(componentName, methodName, selector, alternateSelec
|
|
|
704
708
|
const argsForForward = getPomParameterNames(selectorParams).join(", ");
|
|
705
709
|
const alternates = uniquePomStringPatterns(selector, alternateSelectors).slice(1);
|
|
706
710
|
const primaryTestIdExpr = toTypeScriptPomPatternExpression(selector);
|
|
711
|
+
const actionMetadata = generatedActionMetadata(componentName, name, {
|
|
712
|
+
preferAssociatedLabel: nativeRole === "checkbox"
|
|
713
|
+
});
|
|
707
714
|
if (alternates.length > 0) {
|
|
708
715
|
const candidatesExpr = [primaryTestIdExpr, ...alternates.map((id) => toTypeScriptPomPatternExpression(id))].join(", ");
|
|
709
716
|
const clickMethod = createAsyncMethod(
|
|
@@ -718,20 +725,8 @@ function generateClickMethod(componentName, methodName, selector, alternateSelec
|
|
|
718
725
|
],
|
|
719
726
|
(writer) => {
|
|
720
727
|
writer.writeLine(`const candidates = [${candidatesExpr}] as const;`);
|
|
721
|
-
writer.writeLine(
|
|
722
|
-
writer.
|
|
723
|
-
writer.writeLine(`const locator = this.locatorByTestId(testId, ${locatorDescription});`);
|
|
724
|
-
writer.write("try ").block(() => {
|
|
725
|
-
writer.write("if (await locator.count()) ").block(() => {
|
|
726
|
-
writer.writeLine("await this.clickLocator(locator, annotationText, wait);");
|
|
727
|
-
writer.writeLine("return;");
|
|
728
|
-
});
|
|
729
|
-
});
|
|
730
|
-
writer.write("catch (e) ").block(() => {
|
|
731
|
-
writer.writeLine("lastError = e;");
|
|
732
|
-
});
|
|
733
|
-
});
|
|
734
|
-
writer.writeLine(`throw (lastError instanceof Error) ? lastError : new Error("[pom] Failed to click any candidate locator for ${name}.");`);
|
|
728
|
+
writer.writeLine(`const locator = await this.resolveVisibleTestIdLocator(candidates, ${locatorDescription}, ${JSON.stringify(name)}, ${JSON.stringify(componentName)});`);
|
|
729
|
+
writer.writeLine("await this.clickLocator(locator, annotationText, wait);");
|
|
735
730
|
}
|
|
736
731
|
);
|
|
737
732
|
const noWaitArgs = argsForForward ? `${argsForForward}, false, annotationText` : "false, annotationText";
|
|
@@ -754,7 +749,7 @@ function generateClickMethod(componentName, methodName, selector, alternateSelec
|
|
|
754
749
|
createInlineParameter("annotationText", { type: "string", initializer: '""' })
|
|
755
750
|
],
|
|
756
751
|
(writer) => {
|
|
757
|
-
writer.writeLine(`await this.clickByTestId(${primaryTestIdExpr}, annotationText, wait, ${locatorDescription});`);
|
|
752
|
+
writer.writeLine(`await this.clickByTestId(${primaryTestIdExpr}, annotationText, wait, ${locatorDescription}, ${actionMetadata});`);
|
|
758
753
|
}
|
|
759
754
|
),
|
|
760
755
|
createAsyncMethod(
|
|
@@ -774,7 +769,7 @@ function generateClickMethod(componentName, methodName, selector, alternateSelec
|
|
|
774
769
|
createInlineParameter("annotationText", { type: "string", initializer: '""' })
|
|
775
770
|
],
|
|
776
771
|
(writer) => {
|
|
777
|
-
writer.writeLine(`await this.clickByTestId(${primaryTestIdExpr}, annotationText, wait, ${locatorDescription});`);
|
|
772
|
+
writer.writeLine(`await this.clickByTestId(${primaryTestIdExpr}, annotationText, wait, ${locatorDescription}, ${actionMetadata});`);
|
|
778
773
|
}
|
|
779
774
|
),
|
|
780
775
|
createAsyncMethod(
|
|
@@ -798,7 +793,7 @@ function generateRadioMethod(componentName, methodName, selector, parameters) {
|
|
|
798
793
|
const testIdExpr = toTypeScriptPomPatternExpression(selector);
|
|
799
794
|
return [
|
|
800
795
|
createAsyncMethod(name, methodParameters, (writer) => {
|
|
801
|
-
writer.writeLine(`await this.clickByTestId(${testIdExpr}, annotationText, true, ${locatorDescription});`);
|
|
796
|
+
writer.writeLine(`await this.clickByTestId(${testIdExpr}, annotationText, true, ${locatorDescription}, ${generatedActionMetadata(componentName, name, { preferAssociatedLabel: true })});`);
|
|
802
797
|
})
|
|
803
798
|
];
|
|
804
799
|
}
|
|
@@ -817,7 +812,8 @@ function generateSelectMethod(componentName, methodName, selector, parameters) {
|
|
|
817
812
|
createParameters(selectorParams),
|
|
818
813
|
(writer) => {
|
|
819
814
|
writer.writeLine(`const testId = ${testIdExpr};`);
|
|
820
|
-
writer.writeLine(`
|
|
815
|
+
writer.writeLine(`this.recordPomAction(${JSON.stringify(componentName)}, ${JSON.stringify(name)}, [testId]);`);
|
|
816
|
+
writer.writeLine(`const locator = this.locatorByTestId(testId, ${locatorDescription}).filter({ visible: true }).first();`);
|
|
821
817
|
writer.writeLine("await this.animateCursorToElement(locator, false, 500, annotationText);");
|
|
822
818
|
writer.writeLine("await locator.selectOption(value);");
|
|
823
819
|
}
|
|
@@ -831,13 +827,13 @@ function generateVSelectMethod(componentName, methodName, selector, parameters)
|
|
|
831
827
|
methodName,
|
|
832
828
|
nativeRole: "vselect"
|
|
833
829
|
}));
|
|
834
|
-
const selectorParams = orderPomPatternParameters(parameters, [selector]);
|
|
830
|
+
const selectorParams = orderPomPatternParameters(parameters, [selector]).filter((parameter) => parameter.name !== "timeOut" && parameter.name !== "timeout");
|
|
835
831
|
return [
|
|
836
832
|
createAsyncMethod(
|
|
837
833
|
name,
|
|
838
834
|
createParameters(selectorParams),
|
|
839
835
|
(writer) => {
|
|
840
|
-
writer.writeLine(`await this.selectVSelectByTestId(${toTypeScriptPomPatternExpression(selector)}, value,
|
|
836
|
+
writer.writeLine(`await this.selectVSelectByTestId(${toTypeScriptPomPatternExpression(selector)}, value, annotationText, ${locatorDescription}, ${generatedActionMetadata(componentName, name)});`);
|
|
841
837
|
}
|
|
842
838
|
)
|
|
843
839
|
];
|
|
@@ -855,7 +851,7 @@ function generateTypeMethod(componentName, methodName, selector, parameters) {
|
|
|
855
851
|
name,
|
|
856
852
|
createParameters(selectorParams),
|
|
857
853
|
(writer) => {
|
|
858
|
-
writer.writeLine(`await this.fillInputByTestId(${toTypeScriptPomPatternExpression(selector)}, text, annotationText, ${locatorDescription});`);
|
|
854
|
+
writer.writeLine(`await this.fillInputByTestId(${toTypeScriptPomPatternExpression(selector)}, text, annotationText, ${locatorDescription}, ${generatedActionMetadata(componentName, name)});`);
|
|
859
855
|
}
|
|
860
856
|
)
|
|
861
857
|
];
|
|
@@ -935,20 +931,9 @@ function generateNavigationMethod(args) {
|
|
|
935
931
|
statements: (writer) => {
|
|
936
932
|
writer.write("return this.fluent(async () => ").block(() => {
|
|
937
933
|
writer.writeLine(`const candidates = [${candidatesExpr}] as const;`);
|
|
938
|
-
writer.writeLine(
|
|
939
|
-
writer.
|
|
940
|
-
|
|
941
|
-
writer.write("try ").block(() => {
|
|
942
|
-
writer.write("if (await locator.count()) ").block(() => {
|
|
943
|
-
writer.writeLine("await this.clickLocator(locator);");
|
|
944
|
-
writer.writeLine(`return new ${target}(this.page);`);
|
|
945
|
-
});
|
|
946
|
-
});
|
|
947
|
-
writer.write("catch (e) ").block(() => {
|
|
948
|
-
writer.writeLine("lastError = e;");
|
|
949
|
-
});
|
|
950
|
-
});
|
|
951
|
-
writer.writeLine(`throw (lastError instanceof Error) ? lastError : new Error("[pom] Failed to navigate using any candidate locator for ${methodName}.");`);
|
|
934
|
+
writer.writeLine(`const locator = await this.resolveVisibleTestIdLocator(candidates, ${locatorDescription}, ${JSON.stringify(methodName)}, ${JSON.stringify(componentName)});`);
|
|
935
|
+
writer.writeLine("await this.clickLocator(locator);");
|
|
936
|
+
writer.writeLine(`return new ${target}(this.page);`);
|
|
952
937
|
});
|
|
953
938
|
writer.writeLine(");");
|
|
954
939
|
}
|
|
@@ -963,6 +948,7 @@ function generateNavigationMethod(args) {
|
|
|
963
948
|
statements: (writer) => {
|
|
964
949
|
writer.write("return this.fluent(async () => ").block(() => {
|
|
965
950
|
writer.writeLine(`const locator = this.locatorByTestId(${toTypeScriptPomPatternExpression(selector)}, ${locatorDescription});`);
|
|
951
|
+
writer.writeLine(`this.recordPomAction(${JSON.stringify(componentName)}, ${JSON.stringify(methodName)}, [${toTypeScriptPomPatternExpression(selector)}]);`);
|
|
966
952
|
writer.writeLine("await this.clickLocator(locator);");
|
|
967
953
|
writer.writeLine(`return new ${target}(this.page);`);
|
|
968
954
|
});
|
|
@@ -1007,7 +993,60 @@ function generateViewObjectModelMembers(componentName, targetPageObjectModelClas
|
|
|
1007
993
|
if (nativeRole === "radio") {
|
|
1008
994
|
return [...members, ...generateRadioMethod(componentName, baseMethodName || "Radio", selector, parameters)];
|
|
1009
995
|
}
|
|
1010
|
-
return [...members, ...generateClickMethod(componentName, baseMethodName, selector, alternateSelectors, parameters)];
|
|
996
|
+
return [...members, ...generateClickMethod(componentName, baseMethodName, nativeRole, selector, alternateSelectors, parameters)];
|
|
997
|
+
}
|
|
998
|
+
function supportsInlineTextAccessibleName(role) {
|
|
999
|
+
return role === "button" || role === "radio";
|
|
1000
|
+
}
|
|
1001
|
+
function buildAccessibilityAudit(metadata, inferredRole) {
|
|
1002
|
+
if (!metadata || !inferredRole) {
|
|
1003
|
+
return void 0;
|
|
1004
|
+
}
|
|
1005
|
+
const role = normalizePomRoleLabel(inferredRole).toLowerCase();
|
|
1006
|
+
const dynamicProps = new Set(metadata.dynamicProps ?? []);
|
|
1007
|
+
const hasDynamicAccessibleNameSignal = dynamicProps.has("aria-label") || dynamicProps.has("title") || !!metadata.hasDynamicText;
|
|
1008
|
+
let accessibleNameSource;
|
|
1009
|
+
const reasons = [];
|
|
1010
|
+
if (metadata.staticAriaLabel) {
|
|
1011
|
+
accessibleNameSource = "aria-label";
|
|
1012
|
+
} else if (supportsInlineTextAccessibleName(role) && metadata.staticTextContent) {
|
|
1013
|
+
accessibleNameSource = "text";
|
|
1014
|
+
} else if (metadata.staticTitle) {
|
|
1015
|
+
accessibleNameSource = "title";
|
|
1016
|
+
} else if (hasDynamicAccessibleNameSignal) {
|
|
1017
|
+
accessibleNameSource = "dynamic";
|
|
1018
|
+
} else if (role === "input" || role === "select") {
|
|
1019
|
+
accessibleNameSource = "unknown";
|
|
1020
|
+
reasons.push("No inline accessible-name signal was found; the element may rely on external markup such as a separate <label>.");
|
|
1021
|
+
} else {
|
|
1022
|
+
accessibleNameSource = "missing";
|
|
1023
|
+
reasons.push("No compile-time accessible-name signal was found.");
|
|
1024
|
+
}
|
|
1025
|
+
return {
|
|
1026
|
+
needsReview: accessibleNameSource === "unknown" || accessibleNameSource === "missing",
|
|
1027
|
+
accessibleNameSource,
|
|
1028
|
+
reasons,
|
|
1029
|
+
...metadata.staticAriaLabel ? { staticAriaLabel: metadata.staticAriaLabel } : {},
|
|
1030
|
+
...metadata.staticRole ? { staticRole: metadata.staticRole } : {},
|
|
1031
|
+
...metadata.staticTitle ? { staticTitle: metadata.staticTitle } : {},
|
|
1032
|
+
...metadata.staticTextContent ? { staticTextContent: metadata.staticTextContent } : {}
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
function collectAccessibilityReviewWarnings(manifest) {
|
|
1036
|
+
const warnings = [];
|
|
1037
|
+
for (const [componentName, component] of Object.entries(manifest)) {
|
|
1038
|
+
for (const entry of component.entries) {
|
|
1039
|
+
if (!entry.accessibility?.needsReview) {
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
const entryLabel = entry.generatedPropertyName ?? entry.testId;
|
|
1043
|
+
const reasonText = entry.accessibility.reasons.join(" ");
|
|
1044
|
+
warnings.push(
|
|
1045
|
+
`[vue-pom-generator] Accessibility review suggested for ${componentName}.${entryLabel} (role=${entry.inferredRole ?? "unknown"}, testId=${JSON.stringify(entry.testId)}): ${reasonText}`
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return warnings;
|
|
1011
1050
|
}
|
|
1012
1051
|
function isSimpleExpressionNode(value) {
|
|
1013
1052
|
return value !== null && "type" in value && value.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION;
|
|
@@ -1353,7 +1392,7 @@ function findTemplateSlotScopeExpression(node) {
|
|
|
1353
1392
|
return slotProp?.exp && (slotProp.exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION || slotProp.exp.type === compilerCore.NodeTypes.COMPOUND_EXPRESSION) ? slotProp.exp : null;
|
|
1354
1393
|
}
|
|
1355
1394
|
function buildSlotScopeFallbackKeyExpression(identifier) {
|
|
1356
|
-
return `${identifier}.key ?? ${identifier}.data?.id ?? ${identifier}.id ?? ${identifier}.value ?? ${identifier}`;
|
|
1395
|
+
return `${identifier}.key ?? ${identifier}.data?.id ?? ${identifier}.id ?? ${identifier}.value ?? ${identifier}.url ?? ${identifier}`;
|
|
1357
1396
|
}
|
|
1358
1397
|
function tryGetBindingIdentifierName(node) {
|
|
1359
1398
|
if (!node) {
|
|
@@ -3645,6 +3684,157 @@ function buildPomGeneratedPropertyName(pom) {
|
|
|
3645
3684
|
function buildPomGeneratedActionName(pom) {
|
|
3646
3685
|
return requireStructuredPomName(pom.generatedActionName, "generatedActionName", pom);
|
|
3647
3686
|
}
|
|
3687
|
+
function matchesPrimarySelector(extraMethod, pom) {
|
|
3688
|
+
if (extraMethod.selector.kind !== "testId") {
|
|
3689
|
+
return false;
|
|
3690
|
+
}
|
|
3691
|
+
return extraMethod.selector.testId.formatted === pom.selector.formatted && extraMethod.selector.testId.patternKind === pom.selector.patternKind;
|
|
3692
|
+
}
|
|
3693
|
+
function getManifestEntry(componentName, entry, componentMetadata, extraMethods) {
|
|
3694
|
+
const testId = entry.selectorValue.formatted;
|
|
3695
|
+
const metadata = componentMetadata?.get(testId);
|
|
3696
|
+
const pom = entry.pom;
|
|
3697
|
+
const generatedActionName = pom ? buildPomGeneratedActionName(pom) : null;
|
|
3698
|
+
const extraActionNames = pom ? extraMethods.filter((extraMethod) => matchesPrimarySelector(extraMethod, pom)).map((extraMethod) => extraMethod.name).sort((a, b) => a.localeCompare(b)) : [];
|
|
3699
|
+
const generatedActionNames = Array.from(/* @__PURE__ */ new Set([
|
|
3700
|
+
...generatedActionName ? [generatedActionName] : [],
|
|
3701
|
+
...extraActionNames.filter((name) => name !== generatedActionName)
|
|
3702
|
+
]));
|
|
3703
|
+
const generatedMethods = [
|
|
3704
|
+
...pom && generatedActionName ? [{ name: generatedActionName, kind: "action", parameters: pom.parameters }] : [],
|
|
3705
|
+
...pom ? extraMethods.filter((extraMethod) => matchesPrimarySelector(extraMethod, pom)).map((extraMethod) => ({ name: extraMethod.name, kind: "action", parameters: extraMethod.parameters })) : [],
|
|
3706
|
+
...pom ? [{ name: buildPomGeneratedPropertyName(pom), kind: "locator", parameters: pom.parameters }] : []
|
|
3707
|
+
].filter((method, index, methods) => methods.findIndex((candidate) => candidate.name === method.name && candidate.kind === method.kind) === index);
|
|
3708
|
+
const accessibility = buildAccessibilityAudit(metadata, pom?.nativeRole ?? null);
|
|
3709
|
+
return {
|
|
3710
|
+
testId,
|
|
3711
|
+
selectorPatternKind: entry.selectorValue.patternKind,
|
|
3712
|
+
semanticName: metadata?.semanticName ?? (pom ? humanizePomMethodName(pom.methodName) : testId),
|
|
3713
|
+
locatorDescription: pom ? buildPomLocatorDescription({
|
|
3714
|
+
componentName,
|
|
3715
|
+
methodName: pom.methodName,
|
|
3716
|
+
nativeRole: pom.nativeRole
|
|
3717
|
+
}) : componentName,
|
|
3718
|
+
inferredRole: pom?.nativeRole ?? null,
|
|
3719
|
+
...accessibility ? { accessibility } : {},
|
|
3720
|
+
generatedPropertyName: pom ? buildPomGeneratedPropertyName(pom) : null,
|
|
3721
|
+
generatedActionName,
|
|
3722
|
+
generatedActionNames,
|
|
3723
|
+
generatedMethods,
|
|
3724
|
+
emitPrimary: pom?.emitPrimary !== false,
|
|
3725
|
+
...entry.targetPageObjectModelClass ? { targetPageObjectModelClass: entry.targetPageObjectModelClass } : {},
|
|
3726
|
+
...metadata?.tag ? { sourceTag: metadata.tag } : {},
|
|
3727
|
+
...metadata ? { sourceTagType: metadata.tagType } : {},
|
|
3728
|
+
...metadata?.sourceLine !== void 0 ? { sourceLine: metadata.sourceLine } : {},
|
|
3729
|
+
...metadata?.sourceColumn !== void 0 ? { sourceColumn: metadata.sourceColumn } : {},
|
|
3730
|
+
...metadata?.patchFlag !== void 0 ? { patchFlag: metadata.patchFlag } : {},
|
|
3731
|
+
...metadata?.dynamicProps?.length ? { dynamicProps: metadata.dynamicProps } : {},
|
|
3732
|
+
...metadata?.hasClickHandler !== void 0 ? { hasClickHandler: metadata.hasClickHandler } : {},
|
|
3733
|
+
...metadata?.hasDynamicClass !== void 0 ? { hasDynamicClass: metadata.hasDynamicClass } : {},
|
|
3734
|
+
...metadata?.hasDynamicStyle !== void 0 ? { hasDynamicStyle: metadata.hasDynamicStyle } : {},
|
|
3735
|
+
...metadata?.hasDynamicText !== void 0 ? { hasDynamicText: metadata.hasDynamicText } : {}
|
|
3736
|
+
};
|
|
3737
|
+
}
|
|
3738
|
+
function buildPomManifest(componentHierarchyMap, elementMetadata) {
|
|
3739
|
+
const manifestEntries = Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
3740
|
+
const entries = Array.from(dependencies.dataTestIdSet).sort((a, b) => a.selectorValue.formatted.localeCompare(b.selectorValue.formatted)).map((entry) => getManifestEntry(componentName, entry, elementMetadata.get(componentName), dependencies.pomExtraMethods ?? []));
|
|
3741
|
+
if (!entries.length) {
|
|
3742
|
+
return null;
|
|
3743
|
+
}
|
|
3744
|
+
return [componentName, {
|
|
3745
|
+
componentName,
|
|
3746
|
+
className: componentName,
|
|
3747
|
+
sourceFile: dependencies.filePath,
|
|
3748
|
+
kind: dependencies.isView ? "view" : "component",
|
|
3749
|
+
testIds: Array.from(new Set(entries.map((entry) => entry.testId))),
|
|
3750
|
+
entries
|
|
3751
|
+
}];
|
|
3752
|
+
}).filter((entry) => entry !== null);
|
|
3753
|
+
return Object.fromEntries(manifestEntries);
|
|
3754
|
+
}
|
|
3755
|
+
function buildTestIdManifest(componentHierarchyMap) {
|
|
3756
|
+
return Object.fromEntries(
|
|
3757
|
+
Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
3758
|
+
const testIds = Array.from(dependencies.dataTestIdSet).map((entry) => entry.selectorValue.formatted).filter(Boolean);
|
|
3759
|
+
if (!testIds.length) {
|
|
3760
|
+
return null;
|
|
3761
|
+
}
|
|
3762
|
+
return [componentName, Array.from(new Set(testIds)).sort((a, b) => a.localeCompare(b))];
|
|
3763
|
+
}).filter((entry) => entry !== null)
|
|
3764
|
+
);
|
|
3765
|
+
}
|
|
3766
|
+
function writeConstJson(value) {
|
|
3767
|
+
return (writer) => {
|
|
3768
|
+
writer.write(`${JSON.stringify(value, null, 2)} as const`);
|
|
3769
|
+
};
|
|
3770
|
+
}
|
|
3771
|
+
function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
3772
|
+
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
3773
|
+
const testIdManifest = buildTestIdManifest(componentHierarchyMap);
|
|
3774
|
+
return renderSourceFile("virtual-testids.ts", (sourceFile) => {
|
|
3775
|
+
sourceFile.addStatements("// Virtual module: test id manifest");
|
|
3776
|
+
sourceFile.addVariableStatement({
|
|
3777
|
+
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
3778
|
+
isExported: true,
|
|
3779
|
+
declarations: [{
|
|
3780
|
+
name: "testIdManifest",
|
|
3781
|
+
initializer: writeConstJson(testIdManifest)
|
|
3782
|
+
}]
|
|
3783
|
+
});
|
|
3784
|
+
sourceFile.addVariableStatement({
|
|
3785
|
+
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
3786
|
+
isExported: true,
|
|
3787
|
+
declarations: [{
|
|
3788
|
+
name: "pomManifest",
|
|
3789
|
+
initializer: writeConstJson(pomManifest)
|
|
3790
|
+
}]
|
|
3791
|
+
});
|
|
3792
|
+
sourceFile.addTypeAlias({
|
|
3793
|
+
isExported: true,
|
|
3794
|
+
name: "TestIdManifest",
|
|
3795
|
+
type: "typeof testIdManifest"
|
|
3796
|
+
});
|
|
3797
|
+
sourceFile.addTypeAlias({
|
|
3798
|
+
isExported: true,
|
|
3799
|
+
name: "ComponentName",
|
|
3800
|
+
type: "keyof TestIdManifest"
|
|
3801
|
+
});
|
|
3802
|
+
sourceFile.addTypeAlias({
|
|
3803
|
+
isExported: true,
|
|
3804
|
+
name: "PomManifest",
|
|
3805
|
+
type: "typeof pomManifest"
|
|
3806
|
+
});
|
|
3807
|
+
sourceFile.addTypeAlias({
|
|
3808
|
+
isExported: true,
|
|
3809
|
+
name: "PomManifestComponentName",
|
|
3810
|
+
type: "keyof PomManifest"
|
|
3811
|
+
});
|
|
3812
|
+
});
|
|
3813
|
+
}
|
|
3814
|
+
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts") {
|
|
3815
|
+
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
3816
|
+
return renderSourceFile(fileName, (sourceFile) => {
|
|
3817
|
+
sourceFile.addStatements("// Rich POM discoverability manifest.");
|
|
3818
|
+
sourceFile.addVariableStatement({
|
|
3819
|
+
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
3820
|
+
isExported: true,
|
|
3821
|
+
declarations: [{
|
|
3822
|
+
name: "pomManifest",
|
|
3823
|
+
initializer: writeConstJson(pomManifest)
|
|
3824
|
+
}]
|
|
3825
|
+
});
|
|
3826
|
+
sourceFile.addTypeAlias({
|
|
3827
|
+
isExported: true,
|
|
3828
|
+
name: "PomManifest",
|
|
3829
|
+
type: "typeof pomManifest"
|
|
3830
|
+
});
|
|
3831
|
+
sourceFile.addTypeAlias({
|
|
3832
|
+
isExported: true,
|
|
3833
|
+
name: "PomManifestComponentName",
|
|
3834
|
+
type: "keyof PomManifest"
|
|
3835
|
+
});
|
|
3836
|
+
});
|
|
3837
|
+
}
|
|
3648
3838
|
function safeRealpath(value) {
|
|
3649
3839
|
try {
|
|
3650
3840
|
if (fs.existsSync(value)) {
|
|
@@ -4715,11 +4905,9 @@ function writeRouterTargetType(writer, includeQuery) {
|
|
|
4715
4905
|
writer.write(" }");
|
|
4716
4906
|
}
|
|
4717
4907
|
function writeRouterType(writer, includeQuery) {
|
|
4718
|
-
writer.write(`{ ${router.POM_ROUTER_GLOBAL_NAME}?: {
|
|
4908
|
+
writer.write(`{ ${router.POM_ROUTER_GLOBAL_NAME}?: { beginNavigation: (to: `);
|
|
4719
4909
|
writeRouterTargetType(writer, includeQuery);
|
|
4720
|
-
writer.write(
|
|
4721
|
-
writeRouterTargetType(writer, includeQuery);
|
|
4722
|
-
writer.write(") => { href: string } } }");
|
|
4910
|
+
writer.write(') => number; navigation?: { id: number; status: "pending" | "succeeded" | "failed"; stage: "waiting-for-router-ready" | "pushing-route" | "complete"; targetName: string; error?: string } } }');
|
|
4723
4911
|
}
|
|
4724
4912
|
function writeRouterBinding(writer, includeQuery) {
|
|
4725
4913
|
writer.write("{ name, params");
|
|
@@ -4737,6 +4925,66 @@ function writeRouterTarget(writer, writeName, includeQuery, paramsExpression, qu
|
|
|
4737
4925
|
}
|
|
4738
4926
|
writer.write(" }");
|
|
4739
4927
|
}
|
|
4928
|
+
function writeRouterNavigation(writer, writeName, includeQuery) {
|
|
4929
|
+
writer.write("const navigationId = await this.page.evaluate((");
|
|
4930
|
+
writeRouterBinding(writer, includeQuery);
|
|
4931
|
+
writer.write(") => {").newLine();
|
|
4932
|
+
writer.indent(() => {
|
|
4933
|
+
writer.write("const router = (globalThis as ");
|
|
4934
|
+
writeRouterType(writer, includeQuery);
|
|
4935
|
+
writer.write(`).${router.POM_ROUTER_GLOBAL_NAME};`).newLine();
|
|
4936
|
+
writer.writeLine("if (!router) {");
|
|
4937
|
+
writer.indent(() => {
|
|
4938
|
+
writer.writeLine('throw new Error("[vue-pom-generator] Vue Router bridge is unavailable.");');
|
|
4939
|
+
});
|
|
4940
|
+
writer.writeLine("}");
|
|
4941
|
+
writer.write("return router.beginNavigation(");
|
|
4942
|
+
writeRouterBinding(writer, includeQuery);
|
|
4943
|
+
writer.write(");").newLine();
|
|
4944
|
+
});
|
|
4945
|
+
writer.write("}, ");
|
|
4946
|
+
writeRouterTarget(writer, writeName, includeQuery, "routeParams", "routeQuery");
|
|
4947
|
+
writer.write(");").newLine();
|
|
4948
|
+
writer.writeLine("try {");
|
|
4949
|
+
writer.indent(() => {
|
|
4950
|
+
writer.write("await this.page.waitForFunction((id) => {").newLine();
|
|
4951
|
+
writer.indent(() => {
|
|
4952
|
+
writer.write("const navigation = (globalThis as ");
|
|
4953
|
+
writeRouterType(writer, includeQuery);
|
|
4954
|
+
writer.write(`).${router.POM_ROUTER_GLOBAL_NAME}?.navigation;`).newLine();
|
|
4955
|
+
writer.writeLine('return navigation?.id === id && navigation.status !== "pending";');
|
|
4956
|
+
});
|
|
4957
|
+
writer.writeLine("}, navigationId, { timeout: 5000 });");
|
|
4958
|
+
});
|
|
4959
|
+
writer.writeLine("}");
|
|
4960
|
+
writer.writeLine("catch (error) {");
|
|
4961
|
+
writer.indent(() => {
|
|
4962
|
+
writer.write("const navigation = await this.page.evaluate((id) => {").newLine();
|
|
4963
|
+
writer.indent(() => {
|
|
4964
|
+
writer.write("const current = (globalThis as ");
|
|
4965
|
+
writeRouterType(writer, includeQuery);
|
|
4966
|
+
writer.write(`).${router.POM_ROUTER_GLOBAL_NAME}?.navigation;`).newLine();
|
|
4967
|
+
writer.writeLine("return current?.id === id ? current : undefined;");
|
|
4968
|
+
});
|
|
4969
|
+
writer.writeLine("}, navigationId).catch(() => undefined);");
|
|
4970
|
+
writer.writeLine("const detail = error instanceof Error ? error.message : String(error);");
|
|
4971
|
+
writer.writeLine('throw new Error(`[vue-pom-generator] Vue Router navigation timed out after 5000ms (stage: ${navigation?.stage ?? "unknown"}, target: ${navigation?.targetName ?? "unknown"}, current URL: ${this.page.url()}). ${detail}`);');
|
|
4972
|
+
});
|
|
4973
|
+
writer.writeLine("}");
|
|
4974
|
+
writer.write("const navigationError = await this.page.evaluate((id) => {").newLine();
|
|
4975
|
+
writer.indent(() => {
|
|
4976
|
+
writer.write("const navigation = (globalThis as ");
|
|
4977
|
+
writeRouterType(writer, includeQuery);
|
|
4978
|
+
writer.write(`).${router.POM_ROUTER_GLOBAL_NAME}?.navigation;`).newLine();
|
|
4979
|
+
writer.writeLine('return navigation?.id === id && navigation.status === "failed" ? navigation.error ?? "Unknown navigation error" : undefined;');
|
|
4980
|
+
});
|
|
4981
|
+
writer.writeLine("}, navigationId);");
|
|
4982
|
+
writer.writeLine("if (navigationError) {");
|
|
4983
|
+
writer.indent(() => {
|
|
4984
|
+
writer.writeLine("throw new Error(`[vue-pom-generator] Vue Router navigation failed: ${navigationError}`);");
|
|
4985
|
+
});
|
|
4986
|
+
writer.writeLine("}");
|
|
4987
|
+
}
|
|
4740
4988
|
function requireNavigationInput(input, context) {
|
|
4741
4989
|
if (!input) {
|
|
4742
4990
|
throw new Error(`${context} requires a navigation input.`);
|
|
@@ -4776,6 +5024,7 @@ function writeSelectedTarget(writer, selection, input) {
|
|
|
4776
5024
|
}
|
|
4777
5025
|
function createRouterNavigationWriter(options) {
|
|
4778
5026
|
return (writer) => {
|
|
5027
|
+
writer.writeLine(`this.recordPomAction(${JSON.stringify(options.componentName)}, "goTo", []);`);
|
|
4779
5028
|
writeSelectionPrelude(writer, options.routeName, options.input, options.pathParamNames);
|
|
4780
5029
|
const writeRouteName = (nameWriter) => writeSelectedTarget(nameWriter, options.routeName, options.input);
|
|
4781
5030
|
const includeQuery = options.queryNames.length > 0;
|
|
@@ -4792,40 +5041,11 @@ function createRouterNavigationWriter(options) {
|
|
|
4792
5041
|
writer.indent(() => {
|
|
4793
5042
|
writer.writeLine('await this.page.goto("/", { waitUntil: "commit" });');
|
|
4794
5043
|
writer.writeLine(
|
|
4795
|
-
`await this.page.waitForFunction(() => typeof (globalThis as { ${router.POM_ROUTER_GLOBAL_NAME}?: unknown }).${router.POM_ROUTER_GLOBAL_NAME} !== "undefined", { timeout:
|
|
5044
|
+
`await this.page.waitForFunction(() => typeof (globalThis as { ${router.POM_ROUTER_GLOBAL_NAME}?: unknown }).${router.POM_ROUTER_GLOBAL_NAME} !== "undefined", undefined, { timeout: 5000 });`
|
|
4796
5045
|
);
|
|
4797
|
-
writer.write("const href = await this.page.evaluate((");
|
|
4798
|
-
writeRouterBinding(writer, includeQuery);
|
|
4799
|
-
writer.write(") => (globalThis as ");
|
|
4800
|
-
writeRouterType(writer, includeQuery);
|
|
4801
|
-
writer.write(`).${router.POM_ROUTER_GLOBAL_NAME}?.resolve(`);
|
|
4802
|
-
writeRouterBinding(writer, includeQuery);
|
|
4803
|
-
writer.write(")?.href, ");
|
|
4804
|
-
writeRouterTarget(writer, writeRouteName, includeQuery, "routeParams", "routeQuery");
|
|
4805
|
-
writer.write(");").newLine();
|
|
4806
|
-
writer.writeLine("if (href) {");
|
|
4807
|
-
writer.indent(() => {
|
|
4808
|
-
writer.writeLine('await this.page.goto(href, { waitUntil: "domcontentloaded" });');
|
|
4809
|
-
});
|
|
4810
|
-
writer.writeLine("}");
|
|
4811
|
-
});
|
|
4812
|
-
writer.writeLine("} else {");
|
|
4813
|
-
writer.indent(() => {
|
|
4814
|
-
writer.write("await this.page.evaluate(async (");
|
|
4815
|
-
writeRouterBinding(writer, includeQuery);
|
|
4816
|
-
writer.write(") => {").newLine();
|
|
4817
|
-
writer.indent(() => {
|
|
4818
|
-
writer.write("await (globalThis as ");
|
|
4819
|
-
writeRouterType(writer, includeQuery);
|
|
4820
|
-
writer.write(`).${router.POM_ROUTER_GLOBAL_NAME}?.push(`);
|
|
4821
|
-
writeRouterBinding(writer, includeQuery);
|
|
4822
|
-
writer.write(");").newLine();
|
|
4823
|
-
});
|
|
4824
|
-
writer.write("}, ");
|
|
4825
|
-
writeRouterTarget(writer, writeRouteName, includeQuery, "routeParams", "routeQuery");
|
|
4826
|
-
writer.write(");").newLine();
|
|
4827
5046
|
});
|
|
4828
5047
|
writer.writeLine("}");
|
|
5048
|
+
writeRouterNavigation(writer, writeRouteName, includeQuery);
|
|
4829
5049
|
};
|
|
4830
5050
|
}
|
|
4831
5051
|
function writePathParamAssignments(writer, input, pathParams) {
|
|
@@ -4879,6 +5099,7 @@ function writeRuntimeUrlNavigation(writer) {
|
|
|
4879
5099
|
}
|
|
4880
5100
|
function createUrlNavigationWriter(options) {
|
|
4881
5101
|
return (writer) => {
|
|
5102
|
+
writer.writeLine(`this.recordPomAction(${JSON.stringify(options.componentName)}, "goTo", []);`);
|
|
4882
5103
|
writeSelectionPrelude(writer, options.routeTemplate, options.input, options.pathParams.map((param) => param.name));
|
|
4883
5104
|
if (options.routeTemplate.kind === "single") {
|
|
4884
5105
|
writer.write(`let targetUrl = ${JSON.stringify(options.routeTemplate.target)};`).newLine();
|
|
@@ -5171,11 +5392,13 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
5171
5392
|
isAsync: true,
|
|
5172
5393
|
parameters: hasQuery2 ? [{ name: "params", type: paramType2, hasQuestionToken: true }] : [],
|
|
5173
5394
|
statements: route.name !== null ? createRouterNavigationWriter({
|
|
5395
|
+
componentName,
|
|
5174
5396
|
routeName: { kind: "single", target: route.name },
|
|
5175
5397
|
input: hasQuery2 ? { identifier: "params", optional: true } : void 0,
|
|
5176
5398
|
pathParamNames: [],
|
|
5177
5399
|
queryNames: route.query
|
|
5178
5400
|
}) : createUrlNavigationWriter({
|
|
5401
|
+
componentName,
|
|
5179
5402
|
routeTemplate: { kind: "single", target: route.template },
|
|
5180
5403
|
input: hasQuery2 ? { identifier: "params", optional: true } : void 0,
|
|
5181
5404
|
pathParams: [],
|
|
@@ -5194,11 +5417,13 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
5194
5417
|
isAsync: true,
|
|
5195
5418
|
parameters: [{ name: "params", type: paramType, hasQuestionToken: allOptional }],
|
|
5196
5419
|
statements: route.name !== null ? createRouterNavigationWriter({
|
|
5420
|
+
componentName,
|
|
5197
5421
|
routeName: { kind: "single", target: route.name },
|
|
5198
5422
|
input: { identifier: "params", optional: allOptional },
|
|
5199
5423
|
pathParamNames: route.params.map((param) => param.name),
|
|
5200
5424
|
queryNames: route.query
|
|
5201
5425
|
}) : createUrlNavigationWriter({
|
|
5426
|
+
componentName,
|
|
5202
5427
|
routeTemplate: { kind: "single", target: route.template },
|
|
5203
5428
|
input: { identifier: "params", optional: allOptional },
|
|
5204
5429
|
pathParams: route.params,
|
|
@@ -5228,6 +5453,7 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
5228
5453
|
],
|
|
5229
5454
|
parameters: [{ name: "params", type: implementationType, hasQuestionToken: true }],
|
|
5230
5455
|
statements: usePush ? createRouterNavigationWriter({
|
|
5456
|
+
componentName,
|
|
5231
5457
|
routeName: {
|
|
5232
5458
|
kind: "dual",
|
|
5233
5459
|
parametrizedTarget: requireRouteName(parametrizedRoute),
|
|
@@ -5238,6 +5464,7 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
5238
5464
|
pathParamNames: parametrizedRoute.params.map((param) => param.name),
|
|
5239
5465
|
queryNames: hasQuery ? queryNames : []
|
|
5240
5466
|
}) : createUrlNavigationWriter({
|
|
5467
|
+
componentName,
|
|
5241
5468
|
routeTemplate: {
|
|
5242
5469
|
kind: "dual",
|
|
5243
5470
|
parametrizedTarget: parametrizedRoute.template,
|
|
@@ -5288,7 +5515,7 @@ function generateExtraClickMethodMembers(spec, componentName) {
|
|
|
5288
5515
|
for (const statement of testIdBinding.setupStatements) {
|
|
5289
5516
|
writer.writeLine(statement);
|
|
5290
5517
|
}
|
|
5291
|
-
writer.writeLine(`await this.clickByTestId(${testIdBinding.expression}, ${annotationArg}, ${waitArg}, ${locatorDescription});`);
|
|
5518
|
+
writer.writeLine(`await this.clickByTestId(${testIdBinding.expression}, ${annotationArg}, ${waitArg}, ${locatorDescription}, { componentName: ${JSON.stringify(componentName)}, methodName: ${JSON.stringify(spec.name)} });`);
|
|
5292
5519
|
}
|
|
5293
5520
|
})
|
|
5294
5521
|
];
|
|
@@ -5310,7 +5537,7 @@ function generateExtraClickMethodMembers(spec, componentName) {
|
|
|
5310
5537
|
for (const statement of labelBinding.setupStatements) {
|
|
5311
5538
|
writer.writeLine(statement);
|
|
5312
5539
|
}
|
|
5313
|
-
writer.writeLine(`await this.clickWithinTestIdByLabel(${rootBinding.expression}, ${labelBinding.expression}, ${annotationArg}, ${waitArg}, { description: ${locatorDescription} });`);
|
|
5540
|
+
writer.writeLine(`await this.clickWithinTestIdByLabel(${rootBinding.expression}, ${labelBinding.expression}, ${annotationArg}, ${waitArg}, { description: ${locatorDescription}, componentName: ${JSON.stringify(componentName)}, methodName: ${JSON.stringify(spec.name)} });`);
|
|
5314
5541
|
}
|
|
5315
5542
|
})
|
|
5316
5543
|
];
|
|
@@ -5382,7 +5609,8 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5382
5609
|
pageDirs,
|
|
5383
5610
|
componentDirs,
|
|
5384
5611
|
layoutDirs,
|
|
5385
|
-
routeMetaByComponent: routeMetaByComponentOverride
|
|
5612
|
+
routeMetaByComponent: routeMetaByComponentOverride,
|
|
5613
|
+
elementMetadata = /* @__PURE__ */ new Map()
|
|
5386
5614
|
} = options;
|
|
5387
5615
|
const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
|
|
5388
5616
|
const outDir = outDirOverride ?? "./pom";
|
|
@@ -5423,13 +5651,15 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5423
5651
|
for (const file of files) {
|
|
5424
5652
|
writeGeneratedFile(file);
|
|
5425
5653
|
}
|
|
5426
|
-
const
|
|
5654
|
+
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
5427
5655
|
generateFixtures,
|
|
5428
5656
|
pomOutDir: outDir,
|
|
5429
5657
|
projectRoot,
|
|
5430
|
-
customPomDir
|
|
5658
|
+
customPomDir,
|
|
5659
|
+
elementMetadata,
|
|
5660
|
+
testIdAttribute
|
|
5431
5661
|
});
|
|
5432
|
-
|
|
5662
|
+
for (const fixtureRegistryFile of fixtureRegistryFiles) {
|
|
5433
5663
|
writeGeneratedFile(fixtureRegistryFile);
|
|
5434
5664
|
}
|
|
5435
5665
|
}
|
|
@@ -5911,7 +6141,7 @@ function generateAggregatedCSharpFiles(componentHierarchyMap, outDir, options =
|
|
|
5911
6141
|
function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
5912
6142
|
const { generateFixtures, pomOutDir } = options;
|
|
5913
6143
|
if (!generateFixtures)
|
|
5914
|
-
return
|
|
6144
|
+
return [];
|
|
5915
6145
|
const defaultFixtureOutDirRel = pomOutDir;
|
|
5916
6146
|
const fixtureOutRel = typeof generateFixtures === "string" ? generateFixtures : typeof generateFixtures === "object" && generateFixtures?.outDir ? generateFixtures.outDir : defaultFixtureOutDirRel;
|
|
5917
6147
|
const looksLikeFilePath = fixtureOutRel.endsWith(".ts") || fixtureOutRel.endsWith(".tsx") || fixtureOutRel.endsWith(".mts") || fixtureOutRel.endsWith(".cts");
|
|
@@ -5924,6 +6154,10 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5924
6154
|
const overridePomDirAbs = path.resolve(path.dirname(customPomDirAbs), "overrides");
|
|
5925
6155
|
const pomDirAbs = path.isAbsolute(pomOutDir) ? pomOutDir : path.resolve(root, pomOutDir);
|
|
5926
6156
|
const pomImport = toPosixRelativePath(fixtureOutDirAbs, pomDirAbs);
|
|
6157
|
+
const diagnosticsImport = stripExtension(toPosixRelativePath(
|
|
6158
|
+
fixtureOutDirAbs,
|
|
6159
|
+
path.join(pomDirAbs, "_pom-runtime", "class-generation", "diagnostics.ts")
|
|
6160
|
+
));
|
|
5927
6161
|
const viewClassNames = Array.from(componentHierarchyMap.entries()).filter(([, deps]) => !!deps.isView).map(([name]) => name).sort((a, b) => a.localeCompare(b));
|
|
5928
6162
|
const reservedPlaywrightFixtureNames = /* @__PURE__ */ new Set([
|
|
5929
6163
|
// Built-in Playwright fixtures
|
|
@@ -5933,7 +6167,8 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5933
6167
|
"browserName",
|
|
5934
6168
|
"request",
|
|
5935
6169
|
// Our own fixtureOptions
|
|
5936
|
-
"animation"
|
|
6170
|
+
"animation",
|
|
6171
|
+
"pomDiagnostics"
|
|
5937
6172
|
]);
|
|
5938
6173
|
const viewFixtureNames = new Set(viewClassNames.map((name) => lowerFirst(name)));
|
|
5939
6174
|
const componentClassNames = Array.from(componentHierarchyMap.entries()).filter(([, deps]) => !deps.isView).map(([name]) => name).filter((name) => {
|
|
@@ -5977,13 +6212,27 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5977
6212
|
namedImports: [
|
|
5978
6213
|
{ name: "Page", alias: "PwPage" },
|
|
5979
6214
|
"PlaywrightTestArgs",
|
|
6215
|
+
"TestInfo",
|
|
5980
6216
|
"TestType"
|
|
5981
6217
|
]
|
|
5982
6218
|
});
|
|
6219
|
+
addNamedImport(sourceFile, {
|
|
6220
|
+
moduleSpecifier: diagnosticsImport,
|
|
6221
|
+
namedImports: ["installPomFailureDiagnostics"]
|
|
6222
|
+
});
|
|
6223
|
+
addNamedImport(sourceFile, {
|
|
6224
|
+
moduleSpecifier: diagnosticsImport,
|
|
6225
|
+
isTypeOnly: true,
|
|
6226
|
+
namedImports: ["PomFailureDiagnosticsOptions"]
|
|
6227
|
+
});
|
|
5983
6228
|
sourceFile.addImportDeclaration({
|
|
5984
6229
|
namespaceImport: "Pom",
|
|
5985
6230
|
moduleSpecifier: pomImport
|
|
5986
6231
|
});
|
|
6232
|
+
addNamedImport(sourceFile, {
|
|
6233
|
+
moduleSpecifier: "./pom-manifest.g",
|
|
6234
|
+
namedImports: ["pomManifest"]
|
|
6235
|
+
});
|
|
5987
6236
|
for (const entry of overrideCtorEntries) {
|
|
5988
6237
|
addNamedImport(sourceFile, {
|
|
5989
6238
|
moduleSpecifier: entry.importSpecifier,
|
|
@@ -5996,6 +6245,9 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5996
6245
|
properties: [{
|
|
5997
6246
|
name: "animation",
|
|
5998
6247
|
type: "Pom.PlaywrightAnimationOptions"
|
|
6248
|
+
}, {
|
|
6249
|
+
name: "pomDiagnostics",
|
|
6250
|
+
type: "PomFailureDiagnosticsOptions"
|
|
5999
6251
|
}]
|
|
6000
6252
|
});
|
|
6001
6253
|
sourceFile.addTypeAlias({
|
|
@@ -6022,6 +6274,10 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6022
6274
|
name: "PomFactoryFixture",
|
|
6023
6275
|
type: "{ pomFactory: PomFactory }"
|
|
6024
6276
|
});
|
|
6277
|
+
sourceFile.addTypeAlias({
|
|
6278
|
+
name: "PomDiagnosticsSetupFixture",
|
|
6279
|
+
type: "{ pomDiagnosticsSetup: void }"
|
|
6280
|
+
});
|
|
6025
6281
|
sourceFile.addVariableStatement({
|
|
6026
6282
|
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
6027
6283
|
declarations: [{
|
|
@@ -6068,7 +6324,7 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6068
6324
|
docs: [{
|
|
6069
6325
|
description: "Every fixture contributed by the generator: the `animation` option, the internal\n`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM."
|
|
6070
6326
|
}],
|
|
6071
|
-
type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
|
|
6327
|
+
type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & PomDiagnosticsSetupFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
|
|
6072
6328
|
});
|
|
6073
6329
|
sourceFile.addFunction({
|
|
6074
6330
|
name: "makePomFixture",
|
|
@@ -6120,16 +6376,32 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6120
6376
|
writer.block(() => {
|
|
6121
6377
|
writer.writeLine("animation: [{");
|
|
6122
6378
|
writer.indent(() => {
|
|
6379
|
+
writer.writeLine("enabled: false,");
|
|
6123
6380
|
writer.writeLine('pointer: { durationMilliseconds: 250, transitionStyle: "ease-in-out", clickDelayMilliseconds: 0 },');
|
|
6124
6381
|
writer.writeLine("keyboard: { typeDelayMilliseconds: 100 },");
|
|
6125
6382
|
});
|
|
6126
6383
|
writer.writeLine("}, { option: true }],");
|
|
6384
|
+
writer.writeLine(`pomDiagnostics: [{ captureBudgetMs: 5_000, testIdAttribute: ${JSON.stringify(options.testIdAttribute ?? "data-testid")} }, { option: true }],`);
|
|
6127
6385
|
writer.writeLine("pomSetup: [async ({ animation }: PomFixtures, use: (r: void) => Promise<void>) => {");
|
|
6128
6386
|
writer.indent(() => {
|
|
6129
6387
|
writer.writeLine("Pom.setPlaywrightAnimationOptions(animation);");
|
|
6130
6388
|
writer.writeLine("await use();");
|
|
6131
6389
|
});
|
|
6132
6390
|
writer.writeLine("}, { auto: true }],");
|
|
6391
|
+
writer.writeLine("pomDiagnosticsSetup: [async ({ page, pomDiagnostics }: { page: PwPage; pomDiagnostics: PomFailureDiagnosticsOptions }, use: (r: void) => Promise<void>, testInfo: TestInfo) => {");
|
|
6392
|
+
writer.indent(() => {
|
|
6393
|
+
writer.writeLine("const capture = installPomFailureDiagnostics(page, pomManifest, testInfo, pomDiagnostics);");
|
|
6394
|
+
writer.writeLine("try {");
|
|
6395
|
+
writer.indent(() => writer.writeLine("await use();"));
|
|
6396
|
+
writer.writeLine("} finally {");
|
|
6397
|
+
writer.indent(() => {
|
|
6398
|
+
writer.writeLine("if (testInfo.status !== undefined && testInfo.status !== testInfo.expectedStatus) {");
|
|
6399
|
+
writer.indent(() => writer.writeLine("await capture.capture().catch(() => undefined);"));
|
|
6400
|
+
writer.writeLine("}");
|
|
6401
|
+
});
|
|
6402
|
+
writer.writeLine("}");
|
|
6403
|
+
});
|
|
6404
|
+
writer.writeLine("}, { auto: true }],");
|
|
6133
6405
|
writer.writeLine("pomFactory: async ({ page }: { page: PwPage }, use: (r: PomFactory) => Promise<void>) => {");
|
|
6134
6406
|
writer.indent(() => {
|
|
6135
6407
|
writer.writeLine("await use({");
|
|
@@ -6159,10 +6431,31 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6159
6431
|
]
|
|
6160
6432
|
})
|
|
6161
6433
|
});
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6434
|
+
const manifestFileName = "pom-manifest.g.ts";
|
|
6435
|
+
const manifestContent = generatePomManifestModule(
|
|
6436
|
+
componentHierarchyMap,
|
|
6437
|
+
options.elementMetadata,
|
|
6438
|
+
manifestFileName
|
|
6439
|
+
);
|
|
6440
|
+
const [diagnosticsRuntimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
|
|
6441
|
+
absolutePath: resolvePluginAsset("../class-generation/diagnostics.ts"),
|
|
6442
|
+
description: "diagnostics.ts",
|
|
6443
|
+
outputPath: path.join(pomDirAbs, "_pom-runtime", "class-generation", "diagnostics.ts")
|
|
6444
|
+
}]);
|
|
6445
|
+
if (!diagnosticsRuntimeFile) {
|
|
6446
|
+
throw new Error("[vue-pom-generator] Failed to generate the Playwright diagnostics runtime.");
|
|
6447
|
+
}
|
|
6448
|
+
return [
|
|
6449
|
+
{
|
|
6450
|
+
filePath: path.resolve(fixtureOutDirAbs, fixtureFileName),
|
|
6451
|
+
content: fixturesContent
|
|
6452
|
+
},
|
|
6453
|
+
{
|
|
6454
|
+
filePath: path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
6455
|
+
content: manifestContent
|
|
6456
|
+
},
|
|
6457
|
+
diagnosticsRuntimeFile
|
|
6458
|
+
];
|
|
6166
6459
|
}
|
|
6167
6460
|
function prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, options = {}) {
|
|
6168
6461
|
const { isView, childrenComponentSet, usedComponentSet } = dependencies;
|
|
@@ -6195,6 +6488,23 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
6195
6488
|
}
|
|
6196
6489
|
return match;
|
|
6197
6490
|
};
|
|
6491
|
+
const hasGeneratedPomSurface = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
6492
|
+
const resolvedRef = resolveTrackedComponentRef(value);
|
|
6493
|
+
if (!resolvedRef || seen.has(resolvedRef)) {
|
|
6494
|
+
return false;
|
|
6495
|
+
}
|
|
6496
|
+
const resolvedDependencies = componentHierarchyMap.get(resolvedRef);
|
|
6497
|
+
if (!resolvedDependencies) {
|
|
6498
|
+
return false;
|
|
6499
|
+
}
|
|
6500
|
+
if (resolvedDependencies.dataTestIdSet.size > 0 || (resolvedDependencies.pomExtraMethods?.length ?? 0) > 0 || (resolvedDependencies.generatedMethods?.size ?? 0) > 0) {
|
|
6501
|
+
return true;
|
|
6502
|
+
}
|
|
6503
|
+
const nextSeen = new Set(seen);
|
|
6504
|
+
nextSeen.add(resolvedRef);
|
|
6505
|
+
const nestedRefs = resolvedDependencies.usedComponentSet?.size ? resolvedDependencies.usedComponentSet : resolvedDependencies.childrenComponentSet;
|
|
6506
|
+
return Array.from(nestedRefs).some((child) => hasGeneratedPomSurface(child, nextSeen));
|
|
6507
|
+
};
|
|
6198
6508
|
const rawComponentRefsForInstances = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
|
|
6199
6509
|
const ownClassName = toPascalCaseLocal(componentName);
|
|
6200
6510
|
const isSelfReference = (ref) => {
|
|
@@ -6206,8 +6516,7 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
6206
6516
|
if (isSelfReference(resolvedRef)) {
|
|
6207
6517
|
continue;
|
|
6208
6518
|
}
|
|
6209
|
-
|
|
6210
|
-
if (!resolvedDependencies?.dataTestIdSet.size) {
|
|
6519
|
+
if (!hasGeneratedPomSurface(resolvedRef, /* @__PURE__ */ new Set([componentName]))) {
|
|
6211
6520
|
continue;
|
|
6212
6521
|
}
|
|
6213
6522
|
componentRefsForInstances.add(resolvedRef);
|
|
@@ -6251,7 +6560,7 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
6251
6560
|
}));
|
|
6252
6561
|
const widgetInstances = isView ? getWidgetInstancesForView(componentName, dependencies.dataTestIdSet, customPomAvailableClassIdentifiers) : [];
|
|
6253
6562
|
const className = toPascalCaseLocal(componentName);
|
|
6254
|
-
const childInstancePropertyNames = Array.from(componentRefsForInstances).
|
|
6563
|
+
const childInstancePropertyNames = Array.from(componentRefsForInstances).map((child) => child.split(".vue")[0]);
|
|
6255
6564
|
const blockedViewPassthroughMethodNames = new Set(
|
|
6256
6565
|
attachmentsForThisClass.filter((a) => a.flatten).flatMap((a) => Array.from(a.methodSignatures.keys()))
|
|
6257
6566
|
);
|
|
@@ -6349,10 +6658,7 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
|
|
|
6349
6658
|
};
|
|
6350
6659
|
for (const child of prepared.componentRefsForInstances) {
|
|
6351
6660
|
const childName = child.endsWith(".vue") ? child.slice(0, -4) : child;
|
|
6352
|
-
|
|
6353
|
-
if (childDeps?.dataTestIdSet.size) {
|
|
6354
|
-
addGeneratedImport(childName);
|
|
6355
|
-
}
|
|
6661
|
+
addGeneratedImport(childName);
|
|
6356
6662
|
}
|
|
6357
6663
|
const targetClassNames = Array.from(
|
|
6358
6664
|
new Set(
|
|
@@ -6695,7 +7001,7 @@ function getRuntimeGeneratedAssetSpecs(baseDir, basePageClassPath) {
|
|
|
6695
7001
|
const runtimeDirAbs = path.join(baseDir, "_pom-runtime");
|
|
6696
7002
|
const runtimeClassGenAbs = path.join(runtimeDirAbs, "class-generation");
|
|
6697
7003
|
const runtimeClassGenSourceDir = resolvePluginAsset("../class-generation");
|
|
6698
|
-
const runtimeClassGenFiles = fs.readdirSync(runtimeClassGenSourceDir).filter((file) => file.endsWith(".ts")).filter((file) => file !== "base-page.ts" && file !== "index.ts").sort((left, right) => left.localeCompare(right));
|
|
7004
|
+
const runtimeClassGenFiles = fs.readdirSync(runtimeClassGenSourceDir).filter((file) => file.endsWith(".ts")).filter((file) => file !== "base-page.ts" && file !== "diagnostics.ts" && file !== "index.ts").sort((left, right) => left.localeCompare(right));
|
|
6699
7005
|
return [
|
|
6700
7006
|
{
|
|
6701
7007
|
absolutePath: resolvePluginAsset("../click-instrumentation.ts"),
|
|
@@ -7114,7 +7420,7 @@ function getComponentInstances(childrenComponent, componentHierarchyMap, attachm
|
|
|
7114
7420
|
}));
|
|
7115
7421
|
}
|
|
7116
7422
|
childrenComponent.forEach((child) => {
|
|
7117
|
-
if (componentHierarchyMap.has(child)
|
|
7423
|
+
if (componentHierarchyMap.has(child)) {
|
|
7118
7424
|
const childName = child.split(".vue")[0];
|
|
7119
7425
|
declarations.push(createClassProperty({
|
|
7120
7426
|
name: childName,
|
|
@@ -7137,7 +7443,7 @@ function getConstructor(childrenComponent, componentHierarchyMap, attachmentsFor
|
|
|
7137
7443
|
writer.writeLine(`this.${w.propertyName} = new ${w.className}(this.page, ${JSON.stringify(w.testId)});`);
|
|
7138
7444
|
}
|
|
7139
7445
|
childrenComponent.forEach((child) => {
|
|
7140
|
-
if (componentHierarchyMap.has(child)
|
|
7446
|
+
if (componentHierarchyMap.has(child)) {
|
|
7141
7447
|
const childName = child.split(".vue")[0];
|
|
7142
7448
|
writer.writeLine(`this.${childName} = new ${childName}(page);`);
|
|
7143
7449
|
}
|
|
@@ -7537,6 +7843,13 @@ ${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
|
7537
7843
|
}
|
|
7538
7844
|
try {
|
|
7539
7845
|
const ast = compilerDom.parse(template, { comments: false });
|
|
7846
|
+
const renderedRoots = ast.children.filter((child) => {
|
|
7847
|
+
return child.type !== compilerCore.NodeTypes.COMMENT && !(child.type === compilerCore.NodeTypes.TEXT && child.content.trim() === "");
|
|
7848
|
+
});
|
|
7849
|
+
if (renderedRoots.length !== 1) {
|
|
7850
|
+
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7851
|
+
return null;
|
|
7852
|
+
}
|
|
7540
7853
|
const nextSeen = new Set(seenTags);
|
|
7541
7854
|
nextSeen.add(tag);
|
|
7542
7855
|
const isComponentLikeTag = (value) => {
|
|
@@ -7943,7 +8256,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
7943
8256
|
const inferred = tryInferNativeWrapperRoleFromSfc(element.tag, vueFilesPathMap, wrapperSearchRoots);
|
|
7944
8257
|
if (inferred?.role) {
|
|
7945
8258
|
nativeWrappers[element.tag] = { role: inferred.role, inferred: true };
|
|
7946
|
-
} else if (element.tag.endsWith("Button")) {
|
|
8259
|
+
} else if (element.tag.endsWith("Button") && !tryResolveSfcPathForTag(element.tag, vueFilesPathMap, wrapperSearchRoots)) {
|
|
7947
8260
|
nativeWrappers[element.tag] = { role: "button" };
|
|
7948
8261
|
} else if (element.tag === "DxDataGrid") {
|
|
7949
8262
|
nativeWrappers[element.tag] = { role: "grid" };
|
|
@@ -8246,7 +8559,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8246
8559
|
});
|
|
8247
8560
|
return;
|
|
8248
8561
|
}
|
|
8249
|
-
if (handlerInfo) {
|
|
8562
|
+
if (handlerInfo && nativeWrappers[element.tag]) {
|
|
8250
8563
|
const testId = getHandlerAttributeValueDataTestId(handlerInfo.semanticNameHint);
|
|
8251
8564
|
applyResolvedDataTestIdForElement({
|
|
8252
8565
|
preferredGeneratedValue: testId,
|
|
@@ -8314,59 +8627,6 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8314
8627
|
}
|
|
8315
8628
|
};
|
|
8316
8629
|
}
|
|
8317
|
-
function supportsInlineTextAccessibleName(role) {
|
|
8318
|
-
return role === "button" || role === "radio";
|
|
8319
|
-
}
|
|
8320
|
-
function buildAccessibilityAudit(metadata, inferredRole) {
|
|
8321
|
-
if (!metadata || !inferredRole) {
|
|
8322
|
-
return void 0;
|
|
8323
|
-
}
|
|
8324
|
-
const role = normalizePomRoleLabel(inferredRole).toLowerCase();
|
|
8325
|
-
const dynamicProps = new Set(metadata.dynamicProps ?? []);
|
|
8326
|
-
const hasDynamicAccessibleNameSignal = dynamicProps.has("aria-label") || dynamicProps.has("title") || !!metadata.hasDynamicText;
|
|
8327
|
-
let accessibleNameSource;
|
|
8328
|
-
const reasons = [];
|
|
8329
|
-
if (metadata.staticAriaLabel) {
|
|
8330
|
-
accessibleNameSource = "aria-label";
|
|
8331
|
-
} else if (supportsInlineTextAccessibleName(role) && metadata.staticTextContent) {
|
|
8332
|
-
accessibleNameSource = "text";
|
|
8333
|
-
} else if (metadata.staticTitle) {
|
|
8334
|
-
accessibleNameSource = "title";
|
|
8335
|
-
} else if (hasDynamicAccessibleNameSignal) {
|
|
8336
|
-
accessibleNameSource = "dynamic";
|
|
8337
|
-
} else if (role === "input" || role === "select") {
|
|
8338
|
-
accessibleNameSource = "unknown";
|
|
8339
|
-
reasons.push("No inline accessible-name signal was found; the element may rely on external markup such as a separate <label>.");
|
|
8340
|
-
} else {
|
|
8341
|
-
accessibleNameSource = "missing";
|
|
8342
|
-
reasons.push("No compile-time accessible-name signal was found.");
|
|
8343
|
-
}
|
|
8344
|
-
return {
|
|
8345
|
-
needsReview: accessibleNameSource === "unknown" || accessibleNameSource === "missing",
|
|
8346
|
-
accessibleNameSource,
|
|
8347
|
-
reasons,
|
|
8348
|
-
...metadata.staticAriaLabel ? { staticAriaLabel: metadata.staticAriaLabel } : {},
|
|
8349
|
-
...metadata.staticRole ? { staticRole: metadata.staticRole } : {},
|
|
8350
|
-
...metadata.staticTitle ? { staticTitle: metadata.staticTitle } : {},
|
|
8351
|
-
...metadata.staticTextContent ? { staticTextContent: metadata.staticTextContent } : {}
|
|
8352
|
-
};
|
|
8353
|
-
}
|
|
8354
|
-
function collectAccessibilityReviewWarnings(manifest) {
|
|
8355
|
-
const warnings = [];
|
|
8356
|
-
for (const [componentName, component] of Object.entries(manifest)) {
|
|
8357
|
-
for (const entry of component.entries) {
|
|
8358
|
-
if (!entry.accessibility?.needsReview) {
|
|
8359
|
-
continue;
|
|
8360
|
-
}
|
|
8361
|
-
const entryLabel = entry.generatedPropertyName ?? entry.testId;
|
|
8362
|
-
const reasonText = entry.accessibility.reasons.join(" ");
|
|
8363
|
-
warnings.push(
|
|
8364
|
-
`[vue-pom-generator] Accessibility review suggested for ${componentName}.${entryLabel} (role=${entry.inferredRole ?? "unknown"}, testId=${JSON.stringify(entry.testId)}): ${reasonText}`
|
|
8365
|
-
);
|
|
8366
|
-
}
|
|
8367
|
-
}
|
|
8368
|
-
return warnings;
|
|
8369
|
-
}
|
|
8370
8630
|
function findDataTestIdProp(element, attributeName = "data-testid") {
|
|
8371
8631
|
return element.props.find(
|
|
8372
8632
|
(prop) => prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === attributeName || prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === attributeName
|
|
@@ -8491,151 +8751,6 @@ function tryCreateElementMetadata(args) {
|
|
|
8491
8751
|
};
|
|
8492
8752
|
return metadata;
|
|
8493
8753
|
}
|
|
8494
|
-
function matchesPrimarySelector(extraMethod, pom) {
|
|
8495
|
-
if (extraMethod.selector.kind !== "testId") {
|
|
8496
|
-
return false;
|
|
8497
|
-
}
|
|
8498
|
-
return extraMethod.selector.testId.formatted === pom.selector.formatted && extraMethod.selector.testId.patternKind === pom.selector.patternKind;
|
|
8499
|
-
}
|
|
8500
|
-
function getManifestEntry(componentName, entry, componentMetadata, extraMethods) {
|
|
8501
|
-
const testId = entry.selectorValue.formatted;
|
|
8502
|
-
const metadata = componentMetadata?.get(testId);
|
|
8503
|
-
const pom = entry.pom;
|
|
8504
|
-
const generatedActionName = pom ? buildPomGeneratedActionName(pom) : null;
|
|
8505
|
-
const extraActionNames = pom ? extraMethods.filter((extraMethod) => matchesPrimarySelector(extraMethod, pom)).map((extraMethod) => extraMethod.name).sort((a, b) => a.localeCompare(b)) : [];
|
|
8506
|
-
const generatedActionNames = Array.from(/* @__PURE__ */ new Set([
|
|
8507
|
-
...generatedActionName ? [generatedActionName] : [],
|
|
8508
|
-
...extraActionNames.filter((name) => name !== generatedActionName)
|
|
8509
|
-
]));
|
|
8510
|
-
const accessibility = buildAccessibilityAudit(metadata, pom?.nativeRole ?? null);
|
|
8511
|
-
return {
|
|
8512
|
-
testId,
|
|
8513
|
-
selectorPatternKind: entry.selectorValue.patternKind,
|
|
8514
|
-
semanticName: metadata?.semanticName ?? (pom ? humanizePomMethodName(pom.methodName) : testId),
|
|
8515
|
-
locatorDescription: pom ? buildPomLocatorDescription({
|
|
8516
|
-
componentName,
|
|
8517
|
-
methodName: pom.methodName,
|
|
8518
|
-
nativeRole: pom.nativeRole
|
|
8519
|
-
}) : componentName,
|
|
8520
|
-
inferredRole: pom?.nativeRole ?? null,
|
|
8521
|
-
...accessibility ? { accessibility } : {},
|
|
8522
|
-
generatedPropertyName: pom ? buildPomGeneratedPropertyName(pom) : null,
|
|
8523
|
-
generatedActionName,
|
|
8524
|
-
generatedActionNames,
|
|
8525
|
-
emitPrimary: pom?.emitPrimary !== false,
|
|
8526
|
-
...entry.targetPageObjectModelClass ? { targetPageObjectModelClass: entry.targetPageObjectModelClass } : {},
|
|
8527
|
-
...metadata?.tag ? { sourceTag: metadata.tag } : {},
|
|
8528
|
-
...metadata ? { sourceTagType: metadata.tagType } : {},
|
|
8529
|
-
...metadata?.sourceLine !== void 0 ? { sourceLine: metadata.sourceLine } : {},
|
|
8530
|
-
...metadata?.sourceColumn !== void 0 ? { sourceColumn: metadata.sourceColumn } : {},
|
|
8531
|
-
...metadata?.patchFlag !== void 0 ? { patchFlag: metadata.patchFlag } : {},
|
|
8532
|
-
...metadata?.dynamicProps?.length ? { dynamicProps: metadata.dynamicProps } : {},
|
|
8533
|
-
...metadata?.hasClickHandler !== void 0 ? { hasClickHandler: metadata.hasClickHandler } : {},
|
|
8534
|
-
...metadata?.hasDynamicClass !== void 0 ? { hasDynamicClass: metadata.hasDynamicClass } : {},
|
|
8535
|
-
...metadata?.hasDynamicStyle !== void 0 ? { hasDynamicStyle: metadata.hasDynamicStyle } : {},
|
|
8536
|
-
...metadata?.hasDynamicText !== void 0 ? { hasDynamicText: metadata.hasDynamicText } : {}
|
|
8537
|
-
};
|
|
8538
|
-
}
|
|
8539
|
-
function buildPomManifest(componentHierarchyMap, elementMetadata) {
|
|
8540
|
-
const manifestEntries = Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
8541
|
-
const entries = Array.from(dependencies.dataTestIdSet).sort((a, b) => a.selectorValue.formatted.localeCompare(b.selectorValue.formatted)).map((entry) => getManifestEntry(componentName, entry, elementMetadata.get(componentName), dependencies.pomExtraMethods ?? []));
|
|
8542
|
-
if (!entries.length) {
|
|
8543
|
-
return null;
|
|
8544
|
-
}
|
|
8545
|
-
return [componentName, {
|
|
8546
|
-
componentName,
|
|
8547
|
-
className: componentName,
|
|
8548
|
-
sourceFile: dependencies.filePath,
|
|
8549
|
-
kind: dependencies.isView ? "view" : "component",
|
|
8550
|
-
testIds: Array.from(new Set(entries.map((entry) => entry.testId))),
|
|
8551
|
-
entries
|
|
8552
|
-
}];
|
|
8553
|
-
}).filter((entry) => entry !== null);
|
|
8554
|
-
return Object.fromEntries(manifestEntries);
|
|
8555
|
-
}
|
|
8556
|
-
function buildTestIdManifest(componentHierarchyMap) {
|
|
8557
|
-
return Object.fromEntries(
|
|
8558
|
-
Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
8559
|
-
const testIds = Array.from(dependencies.dataTestIdSet).map((entry) => entry.selectorValue.formatted).filter(Boolean);
|
|
8560
|
-
if (!testIds.length) {
|
|
8561
|
-
return null;
|
|
8562
|
-
}
|
|
8563
|
-
return [componentName, Array.from(new Set(testIds)).sort((a, b) => a.localeCompare(b))];
|
|
8564
|
-
}).filter((entry) => entry !== null)
|
|
8565
|
-
);
|
|
8566
|
-
}
|
|
8567
|
-
function writeConstJson(value) {
|
|
8568
|
-
return (writer) => {
|
|
8569
|
-
writer.write(`${JSON.stringify(value, null, 2)} as const`);
|
|
8570
|
-
};
|
|
8571
|
-
}
|
|
8572
|
-
function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
8573
|
-
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
8574
|
-
const testIdManifest = buildTestIdManifest(componentHierarchyMap);
|
|
8575
|
-
return renderSourceFile("virtual-testids.ts", (sourceFile) => {
|
|
8576
|
-
sourceFile.addStatements("// Virtual module: test id manifest");
|
|
8577
|
-
sourceFile.addVariableStatement({
|
|
8578
|
-
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
8579
|
-
isExported: true,
|
|
8580
|
-
declarations: [{
|
|
8581
|
-
name: "testIdManifest",
|
|
8582
|
-
initializer: writeConstJson(testIdManifest)
|
|
8583
|
-
}]
|
|
8584
|
-
});
|
|
8585
|
-
sourceFile.addVariableStatement({
|
|
8586
|
-
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
8587
|
-
isExported: true,
|
|
8588
|
-
declarations: [{
|
|
8589
|
-
name: "pomManifest",
|
|
8590
|
-
initializer: writeConstJson(pomManifest)
|
|
8591
|
-
}]
|
|
8592
|
-
});
|
|
8593
|
-
sourceFile.addTypeAlias({
|
|
8594
|
-
isExported: true,
|
|
8595
|
-
name: "TestIdManifest",
|
|
8596
|
-
type: "typeof testIdManifest"
|
|
8597
|
-
});
|
|
8598
|
-
sourceFile.addTypeAlias({
|
|
8599
|
-
isExported: true,
|
|
8600
|
-
name: "ComponentName",
|
|
8601
|
-
type: "keyof TestIdManifest"
|
|
8602
|
-
});
|
|
8603
|
-
sourceFile.addTypeAlias({
|
|
8604
|
-
isExported: true,
|
|
8605
|
-
name: "PomManifest",
|
|
8606
|
-
type: "typeof pomManifest"
|
|
8607
|
-
});
|
|
8608
|
-
sourceFile.addTypeAlias({
|
|
8609
|
-
isExported: true,
|
|
8610
|
-
name: "PomManifestComponentName",
|
|
8611
|
-
type: "keyof PomManifest"
|
|
8612
|
-
});
|
|
8613
|
-
});
|
|
8614
|
-
}
|
|
8615
|
-
function generatePomManifestModule(componentHierarchyMap, elementMetadata) {
|
|
8616
|
-
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
8617
|
-
return renderSourceFile("virtual-pom-manifest.ts", (sourceFile) => {
|
|
8618
|
-
sourceFile.addStatements("// Virtual module: richer POM discoverability manifest");
|
|
8619
|
-
sourceFile.addVariableStatement({
|
|
8620
|
-
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
8621
|
-
isExported: true,
|
|
8622
|
-
declarations: [{
|
|
8623
|
-
name: "pomManifest",
|
|
8624
|
-
initializer: writeConstJson(pomManifest)
|
|
8625
|
-
}]
|
|
8626
|
-
});
|
|
8627
|
-
sourceFile.addTypeAlias({
|
|
8628
|
-
isExported: true,
|
|
8629
|
-
name: "PomManifest",
|
|
8630
|
-
type: "typeof pomManifest"
|
|
8631
|
-
});
|
|
8632
|
-
sourceFile.addTypeAlias({
|
|
8633
|
-
isExported: true,
|
|
8634
|
-
name: "PomManifestComponentName",
|
|
8635
|
-
type: "keyof PomManifest"
|
|
8636
|
-
});
|
|
8637
|
-
});
|
|
8638
|
-
}
|
|
8639
8754
|
function resolveExistingIdBehavior(config, componentName) {
|
|
8640
8755
|
return typeof config === "string" ? config : config.components[componentName] ?? config.default;
|
|
8641
8756
|
}
|
|
@@ -8964,6 +9079,7 @@ function isLessRich(candidate, previous) {
|
|
|
8964
9079
|
function createBuildProcessorPlugin(options) {
|
|
8965
9080
|
const {
|
|
8966
9081
|
componentHierarchyMap,
|
|
9082
|
+
elementMetadata,
|
|
8967
9083
|
crossFileKeyRegistry,
|
|
8968
9084
|
vueFilesPathMap,
|
|
8969
9085
|
getPageDirs,
|
|
@@ -9216,7 +9332,8 @@ function createBuildProcessorPlugin(options) {
|
|
|
9216
9332
|
routerType,
|
|
9217
9333
|
pageDirs: getPageDirs(),
|
|
9218
9334
|
componentDirs: getComponentDirs(),
|
|
9219
|
-
layoutDirs: getLayoutDirs()
|
|
9335
|
+
layoutDirs: getLayoutDirs(),
|
|
9336
|
+
elementMetadata
|
|
9220
9337
|
});
|
|
9221
9338
|
lastGeneratedMetrics = metrics;
|
|
9222
9339
|
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
@@ -9228,6 +9345,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9228
9345
|
}
|
|
9229
9346
|
function createDevProcessorPlugin(options) {
|
|
9230
9347
|
const {
|
|
9348
|
+
elementMetadata,
|
|
9231
9349
|
nativeWrappers,
|
|
9232
9350
|
optionKeyAttribute,
|
|
9233
9351
|
excludedComponents,
|
|
@@ -9520,7 +9638,8 @@ function createDevProcessorPlugin(options) {
|
|
|
9520
9638
|
testIdAttribute,
|
|
9521
9639
|
vueRouterFluentChaining: routerAwarePoms,
|
|
9522
9640
|
routerEntry: getResolvedRouterEntry(),
|
|
9523
|
-
routerType
|
|
9641
|
+
routerType,
|
|
9642
|
+
elementMetadata
|
|
9524
9643
|
});
|
|
9525
9644
|
const t1 = node_perf_hooks.performance.now();
|
|
9526
9645
|
logInfo(`generate(${logLabel}): components=${snapshotHierarchy.size} in ${formatMs(t1 - t0)}`);
|
|
@@ -9836,6 +9955,7 @@ function createInternalPlugins(options) {
|
|
|
9836
9955
|
const normalizedBasePagePath = path.posix.normalize(basePageClassPath);
|
|
9837
9956
|
const tsProcessor = createBuildProcessorPlugin({
|
|
9838
9957
|
componentHierarchyMap,
|
|
9958
|
+
elementMetadata,
|
|
9839
9959
|
crossFileKeyRegistry,
|
|
9840
9960
|
vueFilesPathMap,
|
|
9841
9961
|
getPageDirs,
|
|
@@ -9855,6 +9975,7 @@ function createInternalPlugins(options) {
|
|
|
9855
9975
|
loggerRef
|
|
9856
9976
|
});
|
|
9857
9977
|
const devProcessor = createDevProcessorPlugin({
|
|
9978
|
+
elementMetadata,
|
|
9858
9979
|
nativeWrappers,
|
|
9859
9980
|
optionKeyAttribute,
|
|
9860
9981
|
excludedComponents,
|