@immense/vue-pom-generator 1.0.91 → 1.0.93
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 +76 -2
- package/RELEASE_NOTES.md +22 -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/playwright/runtime.cjs +945 -0
- package/dist/playwright/runtime.cjs.map +1 -0
- package/dist/playwright/runtime.mjs +945 -0
- package/dist/playwright/runtime.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 +13 -1
package/dist/index.mjs
CHANGED
|
@@ -624,6 +624,10 @@ function upperFirst$1(value) {
|
|
|
624
624
|
}
|
|
625
625
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
626
626
|
}
|
|
627
|
+
function generatedActionMetadata(componentName, methodName, options = {}) {
|
|
628
|
+
const preferAssociatedLabel = options.preferAssociatedLabel ? ", preferAssociatedLabel: true" : "";
|
|
629
|
+
return `{ componentName: ${JSON.stringify(componentName)}, methodName: ${JSON.stringify(methodName)}${preferAssociatedLabel} }`;
|
|
630
|
+
}
|
|
627
631
|
function createParameters(params) {
|
|
628
632
|
return toTypeScriptPomParameterStructures(params);
|
|
629
633
|
}
|
|
@@ -649,7 +653,7 @@ function createAsyncMethod(name, parameters, statements) {
|
|
|
649
653
|
statements
|
|
650
654
|
});
|
|
651
655
|
}
|
|
652
|
-
function generateClickMethod(componentName, methodName, selector, alternateSelectors, parameters) {
|
|
656
|
+
function generateClickMethod(componentName, methodName, nativeRole, selector, alternateSelectors, parameters) {
|
|
653
657
|
const name = `click${methodName}`;
|
|
654
658
|
const noWaitName = `${name}NoWait`;
|
|
655
659
|
const locatorDescription = JSON.stringify(buildPomLocatorDescription({
|
|
@@ -663,6 +667,9 @@ function generateClickMethod(componentName, methodName, selector, alternateSelec
|
|
|
663
667
|
const argsForForward = getPomParameterNames(selectorParams).join(", ");
|
|
664
668
|
const alternates = uniquePomStringPatterns(selector, alternateSelectors).slice(1);
|
|
665
669
|
const primaryTestIdExpr = toTypeScriptPomPatternExpression(selector);
|
|
670
|
+
const actionMetadata = generatedActionMetadata(componentName, name, {
|
|
671
|
+
preferAssociatedLabel: nativeRole === "checkbox"
|
|
672
|
+
});
|
|
666
673
|
if (alternates.length > 0) {
|
|
667
674
|
const candidatesExpr = [primaryTestIdExpr, ...alternates.map((id) => toTypeScriptPomPatternExpression(id))].join(", ");
|
|
668
675
|
const clickMethod = createAsyncMethod(
|
|
@@ -677,20 +684,8 @@ function generateClickMethod(componentName, methodName, selector, alternateSelec
|
|
|
677
684
|
],
|
|
678
685
|
(writer) => {
|
|
679
686
|
writer.writeLine(`const candidates = [${candidatesExpr}] as const;`);
|
|
680
|
-
writer.writeLine(
|
|
681
|
-
writer.
|
|
682
|
-
writer.writeLine(`const locator = this.locatorByTestId(testId, ${locatorDescription});`);
|
|
683
|
-
writer.write("try ").block(() => {
|
|
684
|
-
writer.write("if (await locator.count()) ").block(() => {
|
|
685
|
-
writer.writeLine("await this.clickLocator(locator, annotationText, wait);");
|
|
686
|
-
writer.writeLine("return;");
|
|
687
|
-
});
|
|
688
|
-
});
|
|
689
|
-
writer.write("catch (e) ").block(() => {
|
|
690
|
-
writer.writeLine("lastError = e;");
|
|
691
|
-
});
|
|
692
|
-
});
|
|
693
|
-
writer.writeLine(`throw (lastError instanceof Error) ? lastError : new Error("[pom] Failed to click any candidate locator for ${name}.");`);
|
|
687
|
+
writer.writeLine(`const locator = await this.resolveVisibleTestIdLocator(candidates, ${locatorDescription}, ${JSON.stringify(name)}, ${JSON.stringify(componentName)});`);
|
|
688
|
+
writer.writeLine("await this.clickLocator(locator, annotationText, wait);");
|
|
694
689
|
}
|
|
695
690
|
);
|
|
696
691
|
const noWaitArgs = argsForForward ? `${argsForForward}, false, annotationText` : "false, annotationText";
|
|
@@ -713,7 +708,7 @@ function generateClickMethod(componentName, methodName, selector, alternateSelec
|
|
|
713
708
|
createInlineParameter("annotationText", { type: "string", initializer: '""' })
|
|
714
709
|
],
|
|
715
710
|
(writer) => {
|
|
716
|
-
writer.writeLine(`await this.clickByTestId(${primaryTestIdExpr}, annotationText, wait, ${locatorDescription});`);
|
|
711
|
+
writer.writeLine(`await this.clickByTestId(${primaryTestIdExpr}, annotationText, wait, ${locatorDescription}, ${actionMetadata});`);
|
|
717
712
|
}
|
|
718
713
|
),
|
|
719
714
|
createAsyncMethod(
|
|
@@ -733,7 +728,7 @@ function generateClickMethod(componentName, methodName, selector, alternateSelec
|
|
|
733
728
|
createInlineParameter("annotationText", { type: "string", initializer: '""' })
|
|
734
729
|
],
|
|
735
730
|
(writer) => {
|
|
736
|
-
writer.writeLine(`await this.clickByTestId(${primaryTestIdExpr}, annotationText, wait, ${locatorDescription});`);
|
|
731
|
+
writer.writeLine(`await this.clickByTestId(${primaryTestIdExpr}, annotationText, wait, ${locatorDescription}, ${actionMetadata});`);
|
|
737
732
|
}
|
|
738
733
|
),
|
|
739
734
|
createAsyncMethod(
|
|
@@ -757,7 +752,7 @@ function generateRadioMethod(componentName, methodName, selector, parameters) {
|
|
|
757
752
|
const testIdExpr = toTypeScriptPomPatternExpression(selector);
|
|
758
753
|
return [
|
|
759
754
|
createAsyncMethod(name, methodParameters, (writer) => {
|
|
760
|
-
writer.writeLine(`await this.clickByTestId(${testIdExpr}, annotationText, true, ${locatorDescription});`);
|
|
755
|
+
writer.writeLine(`await this.clickByTestId(${testIdExpr}, annotationText, true, ${locatorDescription}, ${generatedActionMetadata(componentName, name, { preferAssociatedLabel: true })});`);
|
|
761
756
|
})
|
|
762
757
|
];
|
|
763
758
|
}
|
|
@@ -776,7 +771,8 @@ function generateSelectMethod(componentName, methodName, selector, parameters) {
|
|
|
776
771
|
createParameters(selectorParams),
|
|
777
772
|
(writer) => {
|
|
778
773
|
writer.writeLine(`const testId = ${testIdExpr};`);
|
|
779
|
-
writer.writeLine(`
|
|
774
|
+
writer.writeLine(`this.recordPomAction(${JSON.stringify(componentName)}, ${JSON.stringify(name)}, [testId]);`);
|
|
775
|
+
writer.writeLine(`const locator = this.locatorByTestId(testId, ${locatorDescription}).filter({ visible: true }).first();`);
|
|
780
776
|
writer.writeLine("await this.animateCursorToElement(locator, false, 500, annotationText);");
|
|
781
777
|
writer.writeLine("await locator.selectOption(value);");
|
|
782
778
|
}
|
|
@@ -790,13 +786,13 @@ function generateVSelectMethod(componentName, methodName, selector, parameters)
|
|
|
790
786
|
methodName,
|
|
791
787
|
nativeRole: "vselect"
|
|
792
788
|
}));
|
|
793
|
-
const selectorParams = orderPomPatternParameters(parameters, [selector]);
|
|
789
|
+
const selectorParams = orderPomPatternParameters(parameters, [selector]).filter((parameter) => parameter.name !== "timeOut" && parameter.name !== "timeout");
|
|
794
790
|
return [
|
|
795
791
|
createAsyncMethod(
|
|
796
792
|
name,
|
|
797
793
|
createParameters(selectorParams),
|
|
798
794
|
(writer) => {
|
|
799
|
-
writer.writeLine(`await this.selectVSelectByTestId(${toTypeScriptPomPatternExpression(selector)}, value,
|
|
795
|
+
writer.writeLine(`await this.selectVSelectByTestId(${toTypeScriptPomPatternExpression(selector)}, value, annotationText, ${locatorDescription}, ${generatedActionMetadata(componentName, name)});`);
|
|
800
796
|
}
|
|
801
797
|
)
|
|
802
798
|
];
|
|
@@ -814,7 +810,7 @@ function generateTypeMethod(componentName, methodName, selector, parameters) {
|
|
|
814
810
|
name,
|
|
815
811
|
createParameters(selectorParams),
|
|
816
812
|
(writer) => {
|
|
817
|
-
writer.writeLine(`await this.fillInputByTestId(${toTypeScriptPomPatternExpression(selector)}, text, annotationText, ${locatorDescription});`);
|
|
813
|
+
writer.writeLine(`await this.fillInputByTestId(${toTypeScriptPomPatternExpression(selector)}, text, annotationText, ${locatorDescription}, ${generatedActionMetadata(componentName, name)});`);
|
|
818
814
|
}
|
|
819
815
|
)
|
|
820
816
|
];
|
|
@@ -894,20 +890,9 @@ function generateNavigationMethod(args) {
|
|
|
894
890
|
statements: (writer) => {
|
|
895
891
|
writer.write("return this.fluent(async () => ").block(() => {
|
|
896
892
|
writer.writeLine(`const candidates = [${candidatesExpr}] as const;`);
|
|
897
|
-
writer.writeLine(
|
|
898
|
-
writer.
|
|
899
|
-
|
|
900
|
-
writer.write("try ").block(() => {
|
|
901
|
-
writer.write("if (await locator.count()) ").block(() => {
|
|
902
|
-
writer.writeLine("await this.clickLocator(locator);");
|
|
903
|
-
writer.writeLine(`return new ${target}(this.page);`);
|
|
904
|
-
});
|
|
905
|
-
});
|
|
906
|
-
writer.write("catch (e) ").block(() => {
|
|
907
|
-
writer.writeLine("lastError = e;");
|
|
908
|
-
});
|
|
909
|
-
});
|
|
910
|
-
writer.writeLine(`throw (lastError instanceof Error) ? lastError : new Error("[pom] Failed to navigate using any candidate locator for ${methodName}.");`);
|
|
893
|
+
writer.writeLine(`const locator = await this.resolveVisibleTestIdLocator(candidates, ${locatorDescription}, ${JSON.stringify(methodName)}, ${JSON.stringify(componentName)});`);
|
|
894
|
+
writer.writeLine("await this.clickLocator(locator);");
|
|
895
|
+
writer.writeLine(`return new ${target}(this.page);`);
|
|
911
896
|
});
|
|
912
897
|
writer.writeLine(");");
|
|
913
898
|
}
|
|
@@ -922,6 +907,7 @@ function generateNavigationMethod(args) {
|
|
|
922
907
|
statements: (writer) => {
|
|
923
908
|
writer.write("return this.fluent(async () => ").block(() => {
|
|
924
909
|
writer.writeLine(`const locator = this.locatorByTestId(${toTypeScriptPomPatternExpression(selector)}, ${locatorDescription});`);
|
|
910
|
+
writer.writeLine(`this.recordPomAction(${JSON.stringify(componentName)}, ${JSON.stringify(methodName)}, [${toTypeScriptPomPatternExpression(selector)}]);`);
|
|
925
911
|
writer.writeLine("await this.clickLocator(locator);");
|
|
926
912
|
writer.writeLine(`return new ${target}(this.page);`);
|
|
927
913
|
});
|
|
@@ -966,7 +952,60 @@ function generateViewObjectModelMembers(componentName, targetPageObjectModelClas
|
|
|
966
952
|
if (nativeRole === "radio") {
|
|
967
953
|
return [...members, ...generateRadioMethod(componentName, baseMethodName || "Radio", selector, parameters)];
|
|
968
954
|
}
|
|
969
|
-
return [...members, ...generateClickMethod(componentName, baseMethodName, selector, alternateSelectors, parameters)];
|
|
955
|
+
return [...members, ...generateClickMethod(componentName, baseMethodName, nativeRole, selector, alternateSelectors, parameters)];
|
|
956
|
+
}
|
|
957
|
+
function supportsInlineTextAccessibleName(role) {
|
|
958
|
+
return role === "button" || role === "radio";
|
|
959
|
+
}
|
|
960
|
+
function buildAccessibilityAudit(metadata, inferredRole) {
|
|
961
|
+
if (!metadata || !inferredRole) {
|
|
962
|
+
return void 0;
|
|
963
|
+
}
|
|
964
|
+
const role = normalizePomRoleLabel(inferredRole).toLowerCase();
|
|
965
|
+
const dynamicProps = new Set(metadata.dynamicProps ?? []);
|
|
966
|
+
const hasDynamicAccessibleNameSignal = dynamicProps.has("aria-label") || dynamicProps.has("title") || !!metadata.hasDynamicText;
|
|
967
|
+
let accessibleNameSource;
|
|
968
|
+
const reasons = [];
|
|
969
|
+
if (metadata.staticAriaLabel) {
|
|
970
|
+
accessibleNameSource = "aria-label";
|
|
971
|
+
} else if (supportsInlineTextAccessibleName(role) && metadata.staticTextContent) {
|
|
972
|
+
accessibleNameSource = "text";
|
|
973
|
+
} else if (metadata.staticTitle) {
|
|
974
|
+
accessibleNameSource = "title";
|
|
975
|
+
} else if (hasDynamicAccessibleNameSignal) {
|
|
976
|
+
accessibleNameSource = "dynamic";
|
|
977
|
+
} else if (role === "input" || role === "select") {
|
|
978
|
+
accessibleNameSource = "unknown";
|
|
979
|
+
reasons.push("No inline accessible-name signal was found; the element may rely on external markup such as a separate <label>.");
|
|
980
|
+
} else {
|
|
981
|
+
accessibleNameSource = "missing";
|
|
982
|
+
reasons.push("No compile-time accessible-name signal was found.");
|
|
983
|
+
}
|
|
984
|
+
return {
|
|
985
|
+
needsReview: accessibleNameSource === "unknown" || accessibleNameSource === "missing",
|
|
986
|
+
accessibleNameSource,
|
|
987
|
+
reasons,
|
|
988
|
+
...metadata.staticAriaLabel ? { staticAriaLabel: metadata.staticAriaLabel } : {},
|
|
989
|
+
...metadata.staticRole ? { staticRole: metadata.staticRole } : {},
|
|
990
|
+
...metadata.staticTitle ? { staticTitle: metadata.staticTitle } : {},
|
|
991
|
+
...metadata.staticTextContent ? { staticTextContent: metadata.staticTextContent } : {}
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
function collectAccessibilityReviewWarnings(manifest) {
|
|
995
|
+
const warnings = [];
|
|
996
|
+
for (const [componentName, component] of Object.entries(manifest)) {
|
|
997
|
+
for (const entry of component.entries) {
|
|
998
|
+
if (!entry.accessibility?.needsReview) {
|
|
999
|
+
continue;
|
|
1000
|
+
}
|
|
1001
|
+
const entryLabel = entry.generatedPropertyName ?? entry.testId;
|
|
1002
|
+
const reasonText = entry.accessibility.reasons.join(" ");
|
|
1003
|
+
warnings.push(
|
|
1004
|
+
`[vue-pom-generator] Accessibility review suggested for ${componentName}.${entryLabel} (role=${entry.inferredRole ?? "unknown"}, testId=${JSON.stringify(entry.testId)}): ${reasonText}`
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
return warnings;
|
|
970
1009
|
}
|
|
971
1010
|
function isSimpleExpressionNode(value) {
|
|
972
1011
|
return value !== null && "type" in value && value.type === NodeTypes.SIMPLE_EXPRESSION;
|
|
@@ -1312,7 +1351,7 @@ function findTemplateSlotScopeExpression(node) {
|
|
|
1312
1351
|
return slotProp?.exp && (slotProp.exp.type === NodeTypes.SIMPLE_EXPRESSION || slotProp.exp.type === NodeTypes.COMPOUND_EXPRESSION) ? slotProp.exp : null;
|
|
1313
1352
|
}
|
|
1314
1353
|
function buildSlotScopeFallbackKeyExpression(identifier) {
|
|
1315
|
-
return `${identifier}.key ?? ${identifier}.data?.id ?? ${identifier}.id ?? ${identifier}.value ?? ${identifier}`;
|
|
1354
|
+
return `${identifier}.key ?? ${identifier}.data?.id ?? ${identifier}.id ?? ${identifier}.value ?? ${identifier}.url ?? ${identifier}`;
|
|
1316
1355
|
}
|
|
1317
1356
|
function tryGetBindingIdentifierName(node) {
|
|
1318
1357
|
if (!node) {
|
|
@@ -3604,6 +3643,157 @@ function buildPomGeneratedPropertyName(pom) {
|
|
|
3604
3643
|
function buildPomGeneratedActionName(pom) {
|
|
3605
3644
|
return requireStructuredPomName(pom.generatedActionName, "generatedActionName", pom);
|
|
3606
3645
|
}
|
|
3646
|
+
function matchesPrimarySelector(extraMethod, pom) {
|
|
3647
|
+
if (extraMethod.selector.kind !== "testId") {
|
|
3648
|
+
return false;
|
|
3649
|
+
}
|
|
3650
|
+
return extraMethod.selector.testId.formatted === pom.selector.formatted && extraMethod.selector.testId.patternKind === pom.selector.patternKind;
|
|
3651
|
+
}
|
|
3652
|
+
function getManifestEntry(componentName, entry, componentMetadata, extraMethods) {
|
|
3653
|
+
const testId = entry.selectorValue.formatted;
|
|
3654
|
+
const metadata = componentMetadata?.get(testId);
|
|
3655
|
+
const pom = entry.pom;
|
|
3656
|
+
const generatedActionName = pom ? buildPomGeneratedActionName(pom) : null;
|
|
3657
|
+
const extraActionNames = pom ? extraMethods.filter((extraMethod) => matchesPrimarySelector(extraMethod, pom)).map((extraMethod) => extraMethod.name).sort((a, b) => a.localeCompare(b)) : [];
|
|
3658
|
+
const generatedActionNames = Array.from(/* @__PURE__ */ new Set([
|
|
3659
|
+
...generatedActionName ? [generatedActionName] : [],
|
|
3660
|
+
...extraActionNames.filter((name) => name !== generatedActionName)
|
|
3661
|
+
]));
|
|
3662
|
+
const generatedMethods = [
|
|
3663
|
+
...pom && generatedActionName ? [{ name: generatedActionName, kind: "action", parameters: pom.parameters }] : [],
|
|
3664
|
+
...pom ? extraMethods.filter((extraMethod) => matchesPrimarySelector(extraMethod, pom)).map((extraMethod) => ({ name: extraMethod.name, kind: "action", parameters: extraMethod.parameters })) : [],
|
|
3665
|
+
...pom ? [{ name: buildPomGeneratedPropertyName(pom), kind: "locator", parameters: pom.parameters }] : []
|
|
3666
|
+
].filter((method, index, methods) => methods.findIndex((candidate) => candidate.name === method.name && candidate.kind === method.kind) === index);
|
|
3667
|
+
const accessibility = buildAccessibilityAudit(metadata, pom?.nativeRole ?? null);
|
|
3668
|
+
return {
|
|
3669
|
+
testId,
|
|
3670
|
+
selectorPatternKind: entry.selectorValue.patternKind,
|
|
3671
|
+
semanticName: metadata?.semanticName ?? (pom ? humanizePomMethodName(pom.methodName) : testId),
|
|
3672
|
+
locatorDescription: pom ? buildPomLocatorDescription({
|
|
3673
|
+
componentName,
|
|
3674
|
+
methodName: pom.methodName,
|
|
3675
|
+
nativeRole: pom.nativeRole
|
|
3676
|
+
}) : componentName,
|
|
3677
|
+
inferredRole: pom?.nativeRole ?? null,
|
|
3678
|
+
...accessibility ? { accessibility } : {},
|
|
3679
|
+
generatedPropertyName: pom ? buildPomGeneratedPropertyName(pom) : null,
|
|
3680
|
+
generatedActionName,
|
|
3681
|
+
generatedActionNames,
|
|
3682
|
+
generatedMethods,
|
|
3683
|
+
emitPrimary: pom?.emitPrimary !== false,
|
|
3684
|
+
...entry.targetPageObjectModelClass ? { targetPageObjectModelClass: entry.targetPageObjectModelClass } : {},
|
|
3685
|
+
...metadata?.tag ? { sourceTag: metadata.tag } : {},
|
|
3686
|
+
...metadata ? { sourceTagType: metadata.tagType } : {},
|
|
3687
|
+
...metadata?.sourceLine !== void 0 ? { sourceLine: metadata.sourceLine } : {},
|
|
3688
|
+
...metadata?.sourceColumn !== void 0 ? { sourceColumn: metadata.sourceColumn } : {},
|
|
3689
|
+
...metadata?.patchFlag !== void 0 ? { patchFlag: metadata.patchFlag } : {},
|
|
3690
|
+
...metadata?.dynamicProps?.length ? { dynamicProps: metadata.dynamicProps } : {},
|
|
3691
|
+
...metadata?.hasClickHandler !== void 0 ? { hasClickHandler: metadata.hasClickHandler } : {},
|
|
3692
|
+
...metadata?.hasDynamicClass !== void 0 ? { hasDynamicClass: metadata.hasDynamicClass } : {},
|
|
3693
|
+
...metadata?.hasDynamicStyle !== void 0 ? { hasDynamicStyle: metadata.hasDynamicStyle } : {},
|
|
3694
|
+
...metadata?.hasDynamicText !== void 0 ? { hasDynamicText: metadata.hasDynamicText } : {}
|
|
3695
|
+
};
|
|
3696
|
+
}
|
|
3697
|
+
function buildPomManifest(componentHierarchyMap, elementMetadata) {
|
|
3698
|
+
const manifestEntries = Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
3699
|
+
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 ?? []));
|
|
3700
|
+
if (!entries.length) {
|
|
3701
|
+
return null;
|
|
3702
|
+
}
|
|
3703
|
+
return [componentName, {
|
|
3704
|
+
componentName,
|
|
3705
|
+
className: componentName,
|
|
3706
|
+
sourceFile: dependencies.filePath,
|
|
3707
|
+
kind: dependencies.isView ? "view" : "component",
|
|
3708
|
+
testIds: Array.from(new Set(entries.map((entry) => entry.testId))),
|
|
3709
|
+
entries
|
|
3710
|
+
}];
|
|
3711
|
+
}).filter((entry) => entry !== null);
|
|
3712
|
+
return Object.fromEntries(manifestEntries);
|
|
3713
|
+
}
|
|
3714
|
+
function buildTestIdManifest(componentHierarchyMap) {
|
|
3715
|
+
return Object.fromEntries(
|
|
3716
|
+
Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
3717
|
+
const testIds = Array.from(dependencies.dataTestIdSet).map((entry) => entry.selectorValue.formatted).filter(Boolean);
|
|
3718
|
+
if (!testIds.length) {
|
|
3719
|
+
return null;
|
|
3720
|
+
}
|
|
3721
|
+
return [componentName, Array.from(new Set(testIds)).sort((a, b) => a.localeCompare(b))];
|
|
3722
|
+
}).filter((entry) => entry !== null)
|
|
3723
|
+
);
|
|
3724
|
+
}
|
|
3725
|
+
function writeConstJson(value) {
|
|
3726
|
+
return (writer) => {
|
|
3727
|
+
writer.write(`${JSON.stringify(value, null, 2)} as const`);
|
|
3728
|
+
};
|
|
3729
|
+
}
|
|
3730
|
+
function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
3731
|
+
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
3732
|
+
const testIdManifest = buildTestIdManifest(componentHierarchyMap);
|
|
3733
|
+
return renderSourceFile("virtual-testids.ts", (sourceFile) => {
|
|
3734
|
+
sourceFile.addStatements("// Virtual module: test id manifest");
|
|
3735
|
+
sourceFile.addVariableStatement({
|
|
3736
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
3737
|
+
isExported: true,
|
|
3738
|
+
declarations: [{
|
|
3739
|
+
name: "testIdManifest",
|
|
3740
|
+
initializer: writeConstJson(testIdManifest)
|
|
3741
|
+
}]
|
|
3742
|
+
});
|
|
3743
|
+
sourceFile.addVariableStatement({
|
|
3744
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
3745
|
+
isExported: true,
|
|
3746
|
+
declarations: [{
|
|
3747
|
+
name: "pomManifest",
|
|
3748
|
+
initializer: writeConstJson(pomManifest)
|
|
3749
|
+
}]
|
|
3750
|
+
});
|
|
3751
|
+
sourceFile.addTypeAlias({
|
|
3752
|
+
isExported: true,
|
|
3753
|
+
name: "TestIdManifest",
|
|
3754
|
+
type: "typeof testIdManifest"
|
|
3755
|
+
});
|
|
3756
|
+
sourceFile.addTypeAlias({
|
|
3757
|
+
isExported: true,
|
|
3758
|
+
name: "ComponentName",
|
|
3759
|
+
type: "keyof TestIdManifest"
|
|
3760
|
+
});
|
|
3761
|
+
sourceFile.addTypeAlias({
|
|
3762
|
+
isExported: true,
|
|
3763
|
+
name: "PomManifest",
|
|
3764
|
+
type: "typeof pomManifest"
|
|
3765
|
+
});
|
|
3766
|
+
sourceFile.addTypeAlias({
|
|
3767
|
+
isExported: true,
|
|
3768
|
+
name: "PomManifestComponentName",
|
|
3769
|
+
type: "keyof PomManifest"
|
|
3770
|
+
});
|
|
3771
|
+
});
|
|
3772
|
+
}
|
|
3773
|
+
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts") {
|
|
3774
|
+
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
3775
|
+
return renderSourceFile(fileName, (sourceFile) => {
|
|
3776
|
+
sourceFile.addStatements("// Rich POM discoverability manifest.");
|
|
3777
|
+
sourceFile.addVariableStatement({
|
|
3778
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
3779
|
+
isExported: true,
|
|
3780
|
+
declarations: [{
|
|
3781
|
+
name: "pomManifest",
|
|
3782
|
+
initializer: writeConstJson(pomManifest)
|
|
3783
|
+
}]
|
|
3784
|
+
});
|
|
3785
|
+
sourceFile.addTypeAlias({
|
|
3786
|
+
isExported: true,
|
|
3787
|
+
name: "PomManifest",
|
|
3788
|
+
type: "typeof pomManifest"
|
|
3789
|
+
});
|
|
3790
|
+
sourceFile.addTypeAlias({
|
|
3791
|
+
isExported: true,
|
|
3792
|
+
name: "PomManifestComponentName",
|
|
3793
|
+
type: "keyof PomManifest"
|
|
3794
|
+
});
|
|
3795
|
+
});
|
|
3796
|
+
}
|
|
3607
3797
|
function safeRealpath(value) {
|
|
3608
3798
|
try {
|
|
3609
3799
|
if (fs.existsSync(value)) {
|
|
@@ -4674,11 +4864,9 @@ function writeRouterTargetType(writer, includeQuery) {
|
|
|
4674
4864
|
writer.write(" }");
|
|
4675
4865
|
}
|
|
4676
4866
|
function writeRouterType(writer, includeQuery) {
|
|
4677
|
-
writer.write(`{ ${POM_ROUTER_GLOBAL_NAME}?: {
|
|
4867
|
+
writer.write(`{ ${POM_ROUTER_GLOBAL_NAME}?: { beginNavigation: (to: `);
|
|
4678
4868
|
writeRouterTargetType(writer, includeQuery);
|
|
4679
|
-
writer.write(
|
|
4680
|
-
writeRouterTargetType(writer, includeQuery);
|
|
4681
|
-
writer.write(") => { href: string } } }");
|
|
4869
|
+
writer.write(') => number; navigation?: { id: number; status: "pending" | "succeeded" | "failed"; stage: "waiting-for-router-ready" | "pushing-route" | "complete"; targetName: string; error?: string } } }');
|
|
4682
4870
|
}
|
|
4683
4871
|
function writeRouterBinding(writer, includeQuery) {
|
|
4684
4872
|
writer.write("{ name, params");
|
|
@@ -4696,6 +4884,66 @@ function writeRouterTarget(writer, writeName, includeQuery, paramsExpression, qu
|
|
|
4696
4884
|
}
|
|
4697
4885
|
writer.write(" }");
|
|
4698
4886
|
}
|
|
4887
|
+
function writeRouterNavigation(writer, writeName, includeQuery) {
|
|
4888
|
+
writer.write("const navigationId = await this.page.evaluate((");
|
|
4889
|
+
writeRouterBinding(writer, includeQuery);
|
|
4890
|
+
writer.write(") => {").newLine();
|
|
4891
|
+
writer.indent(() => {
|
|
4892
|
+
writer.write("const router = (globalThis as ");
|
|
4893
|
+
writeRouterType(writer, includeQuery);
|
|
4894
|
+
writer.write(`).${POM_ROUTER_GLOBAL_NAME};`).newLine();
|
|
4895
|
+
writer.writeLine("if (!router) {");
|
|
4896
|
+
writer.indent(() => {
|
|
4897
|
+
writer.writeLine('throw new Error("[vue-pom-generator] Vue Router bridge is unavailable.");');
|
|
4898
|
+
});
|
|
4899
|
+
writer.writeLine("}");
|
|
4900
|
+
writer.write("return router.beginNavigation(");
|
|
4901
|
+
writeRouterBinding(writer, includeQuery);
|
|
4902
|
+
writer.write(");").newLine();
|
|
4903
|
+
});
|
|
4904
|
+
writer.write("}, ");
|
|
4905
|
+
writeRouterTarget(writer, writeName, includeQuery, "routeParams", "routeQuery");
|
|
4906
|
+
writer.write(");").newLine();
|
|
4907
|
+
writer.writeLine("try {");
|
|
4908
|
+
writer.indent(() => {
|
|
4909
|
+
writer.write("await this.page.waitForFunction((id) => {").newLine();
|
|
4910
|
+
writer.indent(() => {
|
|
4911
|
+
writer.write("const navigation = (globalThis as ");
|
|
4912
|
+
writeRouterType(writer, includeQuery);
|
|
4913
|
+
writer.write(`).${POM_ROUTER_GLOBAL_NAME}?.navigation;`).newLine();
|
|
4914
|
+
writer.writeLine('return navigation?.id === id && navigation.status !== "pending";');
|
|
4915
|
+
});
|
|
4916
|
+
writer.writeLine("}, navigationId, { timeout: 5000 });");
|
|
4917
|
+
});
|
|
4918
|
+
writer.writeLine("}");
|
|
4919
|
+
writer.writeLine("catch (error) {");
|
|
4920
|
+
writer.indent(() => {
|
|
4921
|
+
writer.write("const navigation = await this.page.evaluate((id) => {").newLine();
|
|
4922
|
+
writer.indent(() => {
|
|
4923
|
+
writer.write("const current = (globalThis as ");
|
|
4924
|
+
writeRouterType(writer, includeQuery);
|
|
4925
|
+
writer.write(`).${POM_ROUTER_GLOBAL_NAME}?.navigation;`).newLine();
|
|
4926
|
+
writer.writeLine("return current?.id === id ? current : undefined;");
|
|
4927
|
+
});
|
|
4928
|
+
writer.writeLine("}, navigationId).catch(() => undefined);");
|
|
4929
|
+
writer.writeLine("const detail = error instanceof Error ? error.message : String(error);");
|
|
4930
|
+
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}`);');
|
|
4931
|
+
});
|
|
4932
|
+
writer.writeLine("}");
|
|
4933
|
+
writer.write("const navigationError = await this.page.evaluate((id) => {").newLine();
|
|
4934
|
+
writer.indent(() => {
|
|
4935
|
+
writer.write("const navigation = (globalThis as ");
|
|
4936
|
+
writeRouterType(writer, includeQuery);
|
|
4937
|
+
writer.write(`).${POM_ROUTER_GLOBAL_NAME}?.navigation;`).newLine();
|
|
4938
|
+
writer.writeLine('return navigation?.id === id && navigation.status === "failed" ? navigation.error ?? "Unknown navigation error" : undefined;');
|
|
4939
|
+
});
|
|
4940
|
+
writer.writeLine("}, navigationId);");
|
|
4941
|
+
writer.writeLine("if (navigationError) {");
|
|
4942
|
+
writer.indent(() => {
|
|
4943
|
+
writer.writeLine("throw new Error(`[vue-pom-generator] Vue Router navigation failed: ${navigationError}`);");
|
|
4944
|
+
});
|
|
4945
|
+
writer.writeLine("}");
|
|
4946
|
+
}
|
|
4699
4947
|
function requireNavigationInput(input, context) {
|
|
4700
4948
|
if (!input) {
|
|
4701
4949
|
throw new Error(`${context} requires a navigation input.`);
|
|
@@ -4735,6 +4983,7 @@ function writeSelectedTarget(writer, selection, input) {
|
|
|
4735
4983
|
}
|
|
4736
4984
|
function createRouterNavigationWriter(options) {
|
|
4737
4985
|
return (writer) => {
|
|
4986
|
+
writer.writeLine(`this.recordPomAction(${JSON.stringify(options.componentName)}, "goTo", []);`);
|
|
4738
4987
|
writeSelectionPrelude(writer, options.routeName, options.input, options.pathParamNames);
|
|
4739
4988
|
const writeRouteName = (nameWriter) => writeSelectedTarget(nameWriter, options.routeName, options.input);
|
|
4740
4989
|
const includeQuery = options.queryNames.length > 0;
|
|
@@ -4751,40 +5000,11 @@ function createRouterNavigationWriter(options) {
|
|
|
4751
5000
|
writer.indent(() => {
|
|
4752
5001
|
writer.writeLine('await this.page.goto("/", { waitUntil: "commit" });');
|
|
4753
5002
|
writer.writeLine(
|
|
4754
|
-
`await this.page.waitForFunction(() => typeof (globalThis as { ${POM_ROUTER_GLOBAL_NAME}?: unknown }).${POM_ROUTER_GLOBAL_NAME} !== "undefined", { timeout:
|
|
5003
|
+
`await this.page.waitForFunction(() => typeof (globalThis as { ${POM_ROUTER_GLOBAL_NAME}?: unknown }).${POM_ROUTER_GLOBAL_NAME} !== "undefined", undefined, { timeout: 5000 });`
|
|
4755
5004
|
);
|
|
4756
|
-
writer.write("const href = await this.page.evaluate((");
|
|
4757
|
-
writeRouterBinding(writer, includeQuery);
|
|
4758
|
-
writer.write(") => (globalThis as ");
|
|
4759
|
-
writeRouterType(writer, includeQuery);
|
|
4760
|
-
writer.write(`).${POM_ROUTER_GLOBAL_NAME}?.resolve(`);
|
|
4761
|
-
writeRouterBinding(writer, includeQuery);
|
|
4762
|
-
writer.write(")?.href, ");
|
|
4763
|
-
writeRouterTarget(writer, writeRouteName, includeQuery, "routeParams", "routeQuery");
|
|
4764
|
-
writer.write(");").newLine();
|
|
4765
|
-
writer.writeLine("if (href) {");
|
|
4766
|
-
writer.indent(() => {
|
|
4767
|
-
writer.writeLine('await this.page.goto(href, { waitUntil: "domcontentloaded" });');
|
|
4768
|
-
});
|
|
4769
|
-
writer.writeLine("}");
|
|
4770
|
-
});
|
|
4771
|
-
writer.writeLine("} else {");
|
|
4772
|
-
writer.indent(() => {
|
|
4773
|
-
writer.write("await this.page.evaluate(async (");
|
|
4774
|
-
writeRouterBinding(writer, includeQuery);
|
|
4775
|
-
writer.write(") => {").newLine();
|
|
4776
|
-
writer.indent(() => {
|
|
4777
|
-
writer.write("await (globalThis as ");
|
|
4778
|
-
writeRouterType(writer, includeQuery);
|
|
4779
|
-
writer.write(`).${POM_ROUTER_GLOBAL_NAME}?.push(`);
|
|
4780
|
-
writeRouterBinding(writer, includeQuery);
|
|
4781
|
-
writer.write(");").newLine();
|
|
4782
|
-
});
|
|
4783
|
-
writer.write("}, ");
|
|
4784
|
-
writeRouterTarget(writer, writeRouteName, includeQuery, "routeParams", "routeQuery");
|
|
4785
|
-
writer.write(");").newLine();
|
|
4786
5005
|
});
|
|
4787
5006
|
writer.writeLine("}");
|
|
5007
|
+
writeRouterNavigation(writer, writeRouteName, includeQuery);
|
|
4788
5008
|
};
|
|
4789
5009
|
}
|
|
4790
5010
|
function writePathParamAssignments(writer, input, pathParams) {
|
|
@@ -4838,6 +5058,7 @@ function writeRuntimeUrlNavigation(writer) {
|
|
|
4838
5058
|
}
|
|
4839
5059
|
function createUrlNavigationWriter(options) {
|
|
4840
5060
|
return (writer) => {
|
|
5061
|
+
writer.writeLine(`this.recordPomAction(${JSON.stringify(options.componentName)}, "goTo", []);`);
|
|
4841
5062
|
writeSelectionPrelude(writer, options.routeTemplate, options.input, options.pathParams.map((param) => param.name));
|
|
4842
5063
|
if (options.routeTemplate.kind === "single") {
|
|
4843
5064
|
writer.write(`let targetUrl = ${JSON.stringify(options.routeTemplate.target)};`).newLine();
|
|
@@ -5130,11 +5351,13 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
5130
5351
|
isAsync: true,
|
|
5131
5352
|
parameters: hasQuery2 ? [{ name: "params", type: paramType2, hasQuestionToken: true }] : [],
|
|
5132
5353
|
statements: route.name !== null ? createRouterNavigationWriter({
|
|
5354
|
+
componentName,
|
|
5133
5355
|
routeName: { kind: "single", target: route.name },
|
|
5134
5356
|
input: hasQuery2 ? { identifier: "params", optional: true } : void 0,
|
|
5135
5357
|
pathParamNames: [],
|
|
5136
5358
|
queryNames: route.query
|
|
5137
5359
|
}) : createUrlNavigationWriter({
|
|
5360
|
+
componentName,
|
|
5138
5361
|
routeTemplate: { kind: "single", target: route.template },
|
|
5139
5362
|
input: hasQuery2 ? { identifier: "params", optional: true } : void 0,
|
|
5140
5363
|
pathParams: [],
|
|
@@ -5153,11 +5376,13 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
5153
5376
|
isAsync: true,
|
|
5154
5377
|
parameters: [{ name: "params", type: paramType, hasQuestionToken: allOptional }],
|
|
5155
5378
|
statements: route.name !== null ? createRouterNavigationWriter({
|
|
5379
|
+
componentName,
|
|
5156
5380
|
routeName: { kind: "single", target: route.name },
|
|
5157
5381
|
input: { identifier: "params", optional: allOptional },
|
|
5158
5382
|
pathParamNames: route.params.map((param) => param.name),
|
|
5159
5383
|
queryNames: route.query
|
|
5160
5384
|
}) : createUrlNavigationWriter({
|
|
5385
|
+
componentName,
|
|
5161
5386
|
routeTemplate: { kind: "single", target: route.template },
|
|
5162
5387
|
input: { identifier: "params", optional: allOptional },
|
|
5163
5388
|
pathParams: route.params,
|
|
@@ -5187,6 +5412,7 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
5187
5412
|
],
|
|
5188
5413
|
parameters: [{ name: "params", type: implementationType, hasQuestionToken: true }],
|
|
5189
5414
|
statements: usePush ? createRouterNavigationWriter({
|
|
5415
|
+
componentName,
|
|
5190
5416
|
routeName: {
|
|
5191
5417
|
kind: "dual",
|
|
5192
5418
|
parametrizedTarget: requireRouteName(parametrizedRoute),
|
|
@@ -5197,6 +5423,7 @@ function generateGoToMethod(componentName, routeMeta) {
|
|
|
5197
5423
|
pathParamNames: parametrizedRoute.params.map((param) => param.name),
|
|
5198
5424
|
queryNames: hasQuery ? queryNames : []
|
|
5199
5425
|
}) : createUrlNavigationWriter({
|
|
5426
|
+
componentName,
|
|
5200
5427
|
routeTemplate: {
|
|
5201
5428
|
kind: "dual",
|
|
5202
5429
|
parametrizedTarget: parametrizedRoute.template,
|
|
@@ -5247,7 +5474,7 @@ function generateExtraClickMethodMembers(spec, componentName) {
|
|
|
5247
5474
|
for (const statement of testIdBinding.setupStatements) {
|
|
5248
5475
|
writer.writeLine(statement);
|
|
5249
5476
|
}
|
|
5250
|
-
writer.writeLine(`await this.clickByTestId(${testIdBinding.expression}, ${annotationArg}, ${waitArg}, ${locatorDescription});`);
|
|
5477
|
+
writer.writeLine(`await this.clickByTestId(${testIdBinding.expression}, ${annotationArg}, ${waitArg}, ${locatorDescription}, { componentName: ${JSON.stringify(componentName)}, methodName: ${JSON.stringify(spec.name)} });`);
|
|
5251
5478
|
}
|
|
5252
5479
|
})
|
|
5253
5480
|
];
|
|
@@ -5269,7 +5496,7 @@ function generateExtraClickMethodMembers(spec, componentName) {
|
|
|
5269
5496
|
for (const statement of labelBinding.setupStatements) {
|
|
5270
5497
|
writer.writeLine(statement);
|
|
5271
5498
|
}
|
|
5272
|
-
writer.writeLine(`await this.clickWithinTestIdByLabel(${rootBinding.expression}, ${labelBinding.expression}, ${annotationArg}, ${waitArg}, { description: ${locatorDescription} });`);
|
|
5499
|
+
writer.writeLine(`await this.clickWithinTestIdByLabel(${rootBinding.expression}, ${labelBinding.expression}, ${annotationArg}, ${waitArg}, { description: ${locatorDescription}, componentName: ${JSON.stringify(componentName)}, methodName: ${JSON.stringify(spec.name)} });`);
|
|
5273
5500
|
}
|
|
5274
5501
|
})
|
|
5275
5502
|
];
|
|
@@ -5341,7 +5568,8 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5341
5568
|
pageDirs,
|
|
5342
5569
|
componentDirs,
|
|
5343
5570
|
layoutDirs,
|
|
5344
|
-
routeMetaByComponent: routeMetaByComponentOverride
|
|
5571
|
+
routeMetaByComponent: routeMetaByComponentOverride,
|
|
5572
|
+
elementMetadata = /* @__PURE__ */ new Map()
|
|
5345
5573
|
} = options;
|
|
5346
5574
|
const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
|
|
5347
5575
|
const outDir = outDirOverride ?? "./pom";
|
|
@@ -5382,13 +5610,15 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5382
5610
|
for (const file of files) {
|
|
5383
5611
|
writeGeneratedFile(file);
|
|
5384
5612
|
}
|
|
5385
|
-
const
|
|
5613
|
+
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
5386
5614
|
generateFixtures,
|
|
5387
5615
|
pomOutDir: outDir,
|
|
5388
5616
|
projectRoot,
|
|
5389
|
-
customPomDir
|
|
5617
|
+
customPomDir,
|
|
5618
|
+
elementMetadata,
|
|
5619
|
+
testIdAttribute
|
|
5390
5620
|
});
|
|
5391
|
-
|
|
5621
|
+
for (const fixtureRegistryFile of fixtureRegistryFiles) {
|
|
5392
5622
|
writeGeneratedFile(fixtureRegistryFile);
|
|
5393
5623
|
}
|
|
5394
5624
|
}
|
|
@@ -5870,7 +6100,7 @@ function generateAggregatedCSharpFiles(componentHierarchyMap, outDir, options =
|
|
|
5870
6100
|
function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
5871
6101
|
const { generateFixtures, pomOutDir } = options;
|
|
5872
6102
|
if (!generateFixtures)
|
|
5873
|
-
return
|
|
6103
|
+
return [];
|
|
5874
6104
|
const defaultFixtureOutDirRel = pomOutDir;
|
|
5875
6105
|
const fixtureOutRel = typeof generateFixtures === "string" ? generateFixtures : typeof generateFixtures === "object" && generateFixtures?.outDir ? generateFixtures.outDir : defaultFixtureOutDirRel;
|
|
5876
6106
|
const looksLikeFilePath = fixtureOutRel.endsWith(".ts") || fixtureOutRel.endsWith(".tsx") || fixtureOutRel.endsWith(".mts") || fixtureOutRel.endsWith(".cts");
|
|
@@ -5883,6 +6113,10 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5883
6113
|
const overridePomDirAbs = path.resolve(path.dirname(customPomDirAbs), "overrides");
|
|
5884
6114
|
const pomDirAbs = path.isAbsolute(pomOutDir) ? pomOutDir : path.resolve(root, pomOutDir);
|
|
5885
6115
|
const pomImport = toPosixRelativePath(fixtureOutDirAbs, pomDirAbs);
|
|
6116
|
+
const diagnosticsImport = stripExtension(toPosixRelativePath(
|
|
6117
|
+
fixtureOutDirAbs,
|
|
6118
|
+
path.join(pomDirAbs, "_pom-runtime", "class-generation", "diagnostics.ts")
|
|
6119
|
+
));
|
|
5886
6120
|
const viewClassNames = Array.from(componentHierarchyMap.entries()).filter(([, deps]) => !!deps.isView).map(([name]) => name).sort((a, b) => a.localeCompare(b));
|
|
5887
6121
|
const reservedPlaywrightFixtureNames = /* @__PURE__ */ new Set([
|
|
5888
6122
|
// Built-in Playwright fixtures
|
|
@@ -5892,7 +6126,8 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5892
6126
|
"browserName",
|
|
5893
6127
|
"request",
|
|
5894
6128
|
// Our own fixtureOptions
|
|
5895
|
-
"animation"
|
|
6129
|
+
"animation",
|
|
6130
|
+
"pomDiagnostics"
|
|
5896
6131
|
]);
|
|
5897
6132
|
const viewFixtureNames = new Set(viewClassNames.map((name) => lowerFirst(name)));
|
|
5898
6133
|
const componentClassNames = Array.from(componentHierarchyMap.entries()).filter(([, deps]) => !deps.isView).map(([name]) => name).filter((name) => {
|
|
@@ -5936,13 +6171,27 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5936
6171
|
namedImports: [
|
|
5937
6172
|
{ name: "Page", alias: "PwPage" },
|
|
5938
6173
|
"PlaywrightTestArgs",
|
|
6174
|
+
"TestInfo",
|
|
5939
6175
|
"TestType"
|
|
5940
6176
|
]
|
|
5941
6177
|
});
|
|
6178
|
+
addNamedImport(sourceFile, {
|
|
6179
|
+
moduleSpecifier: diagnosticsImport,
|
|
6180
|
+
namedImports: ["installPomFailureDiagnostics"]
|
|
6181
|
+
});
|
|
6182
|
+
addNamedImport(sourceFile, {
|
|
6183
|
+
moduleSpecifier: diagnosticsImport,
|
|
6184
|
+
isTypeOnly: true,
|
|
6185
|
+
namedImports: ["PomFailureDiagnosticsOptions"]
|
|
6186
|
+
});
|
|
5942
6187
|
sourceFile.addImportDeclaration({
|
|
5943
6188
|
namespaceImport: "Pom",
|
|
5944
6189
|
moduleSpecifier: pomImport
|
|
5945
6190
|
});
|
|
6191
|
+
addNamedImport(sourceFile, {
|
|
6192
|
+
moduleSpecifier: "./pom-manifest.g",
|
|
6193
|
+
namedImports: ["pomManifest"]
|
|
6194
|
+
});
|
|
5946
6195
|
for (const entry of overrideCtorEntries) {
|
|
5947
6196
|
addNamedImport(sourceFile, {
|
|
5948
6197
|
moduleSpecifier: entry.importSpecifier,
|
|
@@ -5955,6 +6204,9 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5955
6204
|
properties: [{
|
|
5956
6205
|
name: "animation",
|
|
5957
6206
|
type: "Pom.PlaywrightAnimationOptions"
|
|
6207
|
+
}, {
|
|
6208
|
+
name: "pomDiagnostics",
|
|
6209
|
+
type: "PomFailureDiagnosticsOptions"
|
|
5958
6210
|
}]
|
|
5959
6211
|
});
|
|
5960
6212
|
sourceFile.addTypeAlias({
|
|
@@ -5981,6 +6233,10 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5981
6233
|
name: "PomFactoryFixture",
|
|
5982
6234
|
type: "{ pomFactory: PomFactory }"
|
|
5983
6235
|
});
|
|
6236
|
+
sourceFile.addTypeAlias({
|
|
6237
|
+
name: "PomDiagnosticsSetupFixture",
|
|
6238
|
+
type: "{ pomDiagnosticsSetup: void }"
|
|
6239
|
+
});
|
|
5984
6240
|
sourceFile.addVariableStatement({
|
|
5985
6241
|
declarationKind: VariableDeclarationKind.Const,
|
|
5986
6242
|
declarations: [{
|
|
@@ -6027,7 +6283,7 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6027
6283
|
docs: [{
|
|
6028
6284
|
description: "Every fixture contributed by the generator: the `animation` option, the internal\n`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM."
|
|
6029
6285
|
}],
|
|
6030
|
-
type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
|
|
6286
|
+
type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & PomDiagnosticsSetupFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
|
|
6031
6287
|
});
|
|
6032
6288
|
sourceFile.addFunction({
|
|
6033
6289
|
name: "makePomFixture",
|
|
@@ -6079,16 +6335,32 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6079
6335
|
writer.block(() => {
|
|
6080
6336
|
writer.writeLine("animation: [{");
|
|
6081
6337
|
writer.indent(() => {
|
|
6338
|
+
writer.writeLine("enabled: false,");
|
|
6082
6339
|
writer.writeLine('pointer: { durationMilliseconds: 250, transitionStyle: "ease-in-out", clickDelayMilliseconds: 0 },');
|
|
6083
6340
|
writer.writeLine("keyboard: { typeDelayMilliseconds: 100 },");
|
|
6084
6341
|
});
|
|
6085
6342
|
writer.writeLine("}, { option: true }],");
|
|
6343
|
+
writer.writeLine(`pomDiagnostics: [{ captureBudgetMs: 5_000, testIdAttribute: ${JSON.stringify(options.testIdAttribute ?? "data-testid")} }, { option: true }],`);
|
|
6086
6344
|
writer.writeLine("pomSetup: [async ({ animation }: PomFixtures, use: (r: void) => Promise<void>) => {");
|
|
6087
6345
|
writer.indent(() => {
|
|
6088
6346
|
writer.writeLine("Pom.setPlaywrightAnimationOptions(animation);");
|
|
6089
6347
|
writer.writeLine("await use();");
|
|
6090
6348
|
});
|
|
6091
6349
|
writer.writeLine("}, { auto: true }],");
|
|
6350
|
+
writer.writeLine("pomDiagnosticsSetup: [async ({ page, pomDiagnostics }: { page: PwPage; pomDiagnostics: PomFailureDiagnosticsOptions }, use: (r: void) => Promise<void>, testInfo: TestInfo) => {");
|
|
6351
|
+
writer.indent(() => {
|
|
6352
|
+
writer.writeLine("const capture = installPomFailureDiagnostics(page, pomManifest, testInfo, pomDiagnostics);");
|
|
6353
|
+
writer.writeLine("try {");
|
|
6354
|
+
writer.indent(() => writer.writeLine("await use();"));
|
|
6355
|
+
writer.writeLine("} finally {");
|
|
6356
|
+
writer.indent(() => {
|
|
6357
|
+
writer.writeLine("if (testInfo.status !== undefined && testInfo.status !== testInfo.expectedStatus) {");
|
|
6358
|
+
writer.indent(() => writer.writeLine("await capture.capture().catch(() => undefined);"));
|
|
6359
|
+
writer.writeLine("}");
|
|
6360
|
+
});
|
|
6361
|
+
writer.writeLine("}");
|
|
6362
|
+
});
|
|
6363
|
+
writer.writeLine("}, { auto: true }],");
|
|
6092
6364
|
writer.writeLine("pomFactory: async ({ page }: { page: PwPage }, use: (r: PomFactory) => Promise<void>) => {");
|
|
6093
6365
|
writer.indent(() => {
|
|
6094
6366
|
writer.writeLine("await use({");
|
|
@@ -6118,10 +6390,31 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6118
6390
|
]
|
|
6119
6391
|
})
|
|
6120
6392
|
});
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6393
|
+
const manifestFileName = "pom-manifest.g.ts";
|
|
6394
|
+
const manifestContent = generatePomManifestModule(
|
|
6395
|
+
componentHierarchyMap,
|
|
6396
|
+
options.elementMetadata,
|
|
6397
|
+
manifestFileName
|
|
6398
|
+
);
|
|
6399
|
+
const [diagnosticsRuntimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
|
|
6400
|
+
absolutePath: resolvePluginAsset("../class-generation/diagnostics.ts"),
|
|
6401
|
+
description: "diagnostics.ts",
|
|
6402
|
+
outputPath: path.join(pomDirAbs, "_pom-runtime", "class-generation", "diagnostics.ts")
|
|
6403
|
+
}]);
|
|
6404
|
+
if (!diagnosticsRuntimeFile) {
|
|
6405
|
+
throw new Error("[vue-pom-generator] Failed to generate the Playwright diagnostics runtime.");
|
|
6406
|
+
}
|
|
6407
|
+
return [
|
|
6408
|
+
{
|
|
6409
|
+
filePath: path.resolve(fixtureOutDirAbs, fixtureFileName),
|
|
6410
|
+
content: fixturesContent
|
|
6411
|
+
},
|
|
6412
|
+
{
|
|
6413
|
+
filePath: path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
6414
|
+
content: manifestContent
|
|
6415
|
+
},
|
|
6416
|
+
diagnosticsRuntimeFile
|
|
6417
|
+
];
|
|
6125
6418
|
}
|
|
6126
6419
|
function prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, options = {}) {
|
|
6127
6420
|
const { isView, childrenComponentSet, usedComponentSet } = dependencies;
|
|
@@ -6154,6 +6447,23 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
6154
6447
|
}
|
|
6155
6448
|
return match;
|
|
6156
6449
|
};
|
|
6450
|
+
const hasGeneratedPomSurface = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
6451
|
+
const resolvedRef = resolveTrackedComponentRef(value);
|
|
6452
|
+
if (!resolvedRef || seen.has(resolvedRef)) {
|
|
6453
|
+
return false;
|
|
6454
|
+
}
|
|
6455
|
+
const resolvedDependencies = componentHierarchyMap.get(resolvedRef);
|
|
6456
|
+
if (!resolvedDependencies) {
|
|
6457
|
+
return false;
|
|
6458
|
+
}
|
|
6459
|
+
if (resolvedDependencies.dataTestIdSet.size > 0 || (resolvedDependencies.pomExtraMethods?.length ?? 0) > 0 || (resolvedDependencies.generatedMethods?.size ?? 0) > 0) {
|
|
6460
|
+
return true;
|
|
6461
|
+
}
|
|
6462
|
+
const nextSeen = new Set(seen);
|
|
6463
|
+
nextSeen.add(resolvedRef);
|
|
6464
|
+
const nestedRefs = resolvedDependencies.usedComponentSet?.size ? resolvedDependencies.usedComponentSet : resolvedDependencies.childrenComponentSet;
|
|
6465
|
+
return Array.from(nestedRefs).some((child) => hasGeneratedPomSurface(child, nextSeen));
|
|
6466
|
+
};
|
|
6157
6467
|
const rawComponentRefsForInstances = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
|
|
6158
6468
|
const ownClassName = toPascalCaseLocal(componentName);
|
|
6159
6469
|
const isSelfReference = (ref) => {
|
|
@@ -6165,8 +6475,7 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
6165
6475
|
if (isSelfReference(resolvedRef)) {
|
|
6166
6476
|
continue;
|
|
6167
6477
|
}
|
|
6168
|
-
|
|
6169
|
-
if (!resolvedDependencies?.dataTestIdSet.size) {
|
|
6478
|
+
if (!hasGeneratedPomSurface(resolvedRef, /* @__PURE__ */ new Set([componentName]))) {
|
|
6170
6479
|
continue;
|
|
6171
6480
|
}
|
|
6172
6481
|
componentRefsForInstances.add(resolvedRef);
|
|
@@ -6210,7 +6519,7 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
6210
6519
|
}));
|
|
6211
6520
|
const widgetInstances = isView ? getWidgetInstancesForView(componentName, dependencies.dataTestIdSet, customPomAvailableClassIdentifiers) : [];
|
|
6212
6521
|
const className = toPascalCaseLocal(componentName);
|
|
6213
|
-
const childInstancePropertyNames = Array.from(componentRefsForInstances).
|
|
6522
|
+
const childInstancePropertyNames = Array.from(componentRefsForInstances).map((child) => child.split(".vue")[0]);
|
|
6214
6523
|
const blockedViewPassthroughMethodNames = new Set(
|
|
6215
6524
|
attachmentsForThisClass.filter((a) => a.flatten).flatMap((a) => Array.from(a.methodSignatures.keys()))
|
|
6216
6525
|
);
|
|
@@ -6308,10 +6617,7 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
|
|
|
6308
6617
|
};
|
|
6309
6618
|
for (const child of prepared.componentRefsForInstances) {
|
|
6310
6619
|
const childName = child.endsWith(".vue") ? child.slice(0, -4) : child;
|
|
6311
|
-
|
|
6312
|
-
if (childDeps?.dataTestIdSet.size) {
|
|
6313
|
-
addGeneratedImport(childName);
|
|
6314
|
-
}
|
|
6620
|
+
addGeneratedImport(childName);
|
|
6315
6621
|
}
|
|
6316
6622
|
const targetClassNames = Array.from(
|
|
6317
6623
|
new Set(
|
|
@@ -6654,7 +6960,7 @@ function getRuntimeGeneratedAssetSpecs(baseDir, basePageClassPath) {
|
|
|
6654
6960
|
const runtimeDirAbs = path.join(baseDir, "_pom-runtime");
|
|
6655
6961
|
const runtimeClassGenAbs = path.join(runtimeDirAbs, "class-generation");
|
|
6656
6962
|
const runtimeClassGenSourceDir = resolvePluginAsset("../class-generation");
|
|
6657
|
-
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));
|
|
6963
|
+
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));
|
|
6658
6964
|
return [
|
|
6659
6965
|
{
|
|
6660
6966
|
absolutePath: resolvePluginAsset("../click-instrumentation.ts"),
|
|
@@ -7073,7 +7379,7 @@ function getComponentInstances(childrenComponent, componentHierarchyMap, attachm
|
|
|
7073
7379
|
}));
|
|
7074
7380
|
}
|
|
7075
7381
|
childrenComponent.forEach((child) => {
|
|
7076
|
-
if (componentHierarchyMap.has(child)
|
|
7382
|
+
if (componentHierarchyMap.has(child)) {
|
|
7077
7383
|
const childName = child.split(".vue")[0];
|
|
7078
7384
|
declarations.push(createClassProperty({
|
|
7079
7385
|
name: childName,
|
|
@@ -7096,7 +7402,7 @@ function getConstructor(childrenComponent, componentHierarchyMap, attachmentsFor
|
|
|
7096
7402
|
writer.writeLine(`this.${w.propertyName} = new ${w.className}(this.page, ${JSON.stringify(w.testId)});`);
|
|
7097
7403
|
}
|
|
7098
7404
|
childrenComponent.forEach((child) => {
|
|
7099
|
-
if (componentHierarchyMap.has(child)
|
|
7405
|
+
if (componentHierarchyMap.has(child)) {
|
|
7100
7406
|
const childName = child.split(".vue")[0];
|
|
7101
7407
|
writer.writeLine(`this.${childName} = new ${childName}(page);`);
|
|
7102
7408
|
}
|
|
@@ -7496,6 +7802,13 @@ ${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
|
7496
7802
|
}
|
|
7497
7803
|
try {
|
|
7498
7804
|
const ast = parse$2(template, { comments: false });
|
|
7805
|
+
const renderedRoots = ast.children.filter((child) => {
|
|
7806
|
+
return child.type !== NodeTypes.COMMENT && !(child.type === NodeTypes.TEXT && child.content.trim() === "");
|
|
7807
|
+
});
|
|
7808
|
+
if (renderedRoots.length !== 1) {
|
|
7809
|
+
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7810
|
+
return null;
|
|
7811
|
+
}
|
|
7499
7812
|
const nextSeen = new Set(seenTags);
|
|
7500
7813
|
nextSeen.add(tag);
|
|
7501
7814
|
const isComponentLikeTag = (value) => {
|
|
@@ -7902,7 +8215,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
7902
8215
|
const inferred = tryInferNativeWrapperRoleFromSfc(element.tag, vueFilesPathMap, wrapperSearchRoots);
|
|
7903
8216
|
if (inferred?.role) {
|
|
7904
8217
|
nativeWrappers[element.tag] = { role: inferred.role, inferred: true };
|
|
7905
|
-
} else if (element.tag.endsWith("Button")) {
|
|
8218
|
+
} else if (element.tag.endsWith("Button") && !tryResolveSfcPathForTag(element.tag, vueFilesPathMap, wrapperSearchRoots)) {
|
|
7906
8219
|
nativeWrappers[element.tag] = { role: "button" };
|
|
7907
8220
|
} else if (element.tag === "DxDataGrid") {
|
|
7908
8221
|
nativeWrappers[element.tag] = { role: "grid" };
|
|
@@ -8205,7 +8518,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8205
8518
|
});
|
|
8206
8519
|
return;
|
|
8207
8520
|
}
|
|
8208
|
-
if (handlerInfo) {
|
|
8521
|
+
if (handlerInfo && nativeWrappers[element.tag]) {
|
|
8209
8522
|
const testId = getHandlerAttributeValueDataTestId(handlerInfo.semanticNameHint);
|
|
8210
8523
|
applyResolvedDataTestIdForElement({
|
|
8211
8524
|
preferredGeneratedValue: testId,
|
|
@@ -8273,59 +8586,6 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8273
8586
|
}
|
|
8274
8587
|
};
|
|
8275
8588
|
}
|
|
8276
|
-
function supportsInlineTextAccessibleName(role) {
|
|
8277
|
-
return role === "button" || role === "radio";
|
|
8278
|
-
}
|
|
8279
|
-
function buildAccessibilityAudit(metadata, inferredRole) {
|
|
8280
|
-
if (!metadata || !inferredRole) {
|
|
8281
|
-
return void 0;
|
|
8282
|
-
}
|
|
8283
|
-
const role = normalizePomRoleLabel(inferredRole).toLowerCase();
|
|
8284
|
-
const dynamicProps = new Set(metadata.dynamicProps ?? []);
|
|
8285
|
-
const hasDynamicAccessibleNameSignal = dynamicProps.has("aria-label") || dynamicProps.has("title") || !!metadata.hasDynamicText;
|
|
8286
|
-
let accessibleNameSource;
|
|
8287
|
-
const reasons = [];
|
|
8288
|
-
if (metadata.staticAriaLabel) {
|
|
8289
|
-
accessibleNameSource = "aria-label";
|
|
8290
|
-
} else if (supportsInlineTextAccessibleName(role) && metadata.staticTextContent) {
|
|
8291
|
-
accessibleNameSource = "text";
|
|
8292
|
-
} else if (metadata.staticTitle) {
|
|
8293
|
-
accessibleNameSource = "title";
|
|
8294
|
-
} else if (hasDynamicAccessibleNameSignal) {
|
|
8295
|
-
accessibleNameSource = "dynamic";
|
|
8296
|
-
} else if (role === "input" || role === "select") {
|
|
8297
|
-
accessibleNameSource = "unknown";
|
|
8298
|
-
reasons.push("No inline accessible-name signal was found; the element may rely on external markup such as a separate <label>.");
|
|
8299
|
-
} else {
|
|
8300
|
-
accessibleNameSource = "missing";
|
|
8301
|
-
reasons.push("No compile-time accessible-name signal was found.");
|
|
8302
|
-
}
|
|
8303
|
-
return {
|
|
8304
|
-
needsReview: accessibleNameSource === "unknown" || accessibleNameSource === "missing",
|
|
8305
|
-
accessibleNameSource,
|
|
8306
|
-
reasons,
|
|
8307
|
-
...metadata.staticAriaLabel ? { staticAriaLabel: metadata.staticAriaLabel } : {},
|
|
8308
|
-
...metadata.staticRole ? { staticRole: metadata.staticRole } : {},
|
|
8309
|
-
...metadata.staticTitle ? { staticTitle: metadata.staticTitle } : {},
|
|
8310
|
-
...metadata.staticTextContent ? { staticTextContent: metadata.staticTextContent } : {}
|
|
8311
|
-
};
|
|
8312
|
-
}
|
|
8313
|
-
function collectAccessibilityReviewWarnings(manifest) {
|
|
8314
|
-
const warnings = [];
|
|
8315
|
-
for (const [componentName, component] of Object.entries(manifest)) {
|
|
8316
|
-
for (const entry of component.entries) {
|
|
8317
|
-
if (!entry.accessibility?.needsReview) {
|
|
8318
|
-
continue;
|
|
8319
|
-
}
|
|
8320
|
-
const entryLabel = entry.generatedPropertyName ?? entry.testId;
|
|
8321
|
-
const reasonText = entry.accessibility.reasons.join(" ");
|
|
8322
|
-
warnings.push(
|
|
8323
|
-
`[vue-pom-generator] Accessibility review suggested for ${componentName}.${entryLabel} (role=${entry.inferredRole ?? "unknown"}, testId=${JSON.stringify(entry.testId)}): ${reasonText}`
|
|
8324
|
-
);
|
|
8325
|
-
}
|
|
8326
|
-
}
|
|
8327
|
-
return warnings;
|
|
8328
|
-
}
|
|
8329
8589
|
function findDataTestIdProp(element, attributeName = "data-testid") {
|
|
8330
8590
|
return element.props.find(
|
|
8331
8591
|
(prop) => prop.type === NodeTypes.ATTRIBUTE && prop.name === attributeName || prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === attributeName
|
|
@@ -8450,151 +8710,6 @@ function tryCreateElementMetadata(args) {
|
|
|
8450
8710
|
};
|
|
8451
8711
|
return metadata;
|
|
8452
8712
|
}
|
|
8453
|
-
function matchesPrimarySelector(extraMethod, pom) {
|
|
8454
|
-
if (extraMethod.selector.kind !== "testId") {
|
|
8455
|
-
return false;
|
|
8456
|
-
}
|
|
8457
|
-
return extraMethod.selector.testId.formatted === pom.selector.formatted && extraMethod.selector.testId.patternKind === pom.selector.patternKind;
|
|
8458
|
-
}
|
|
8459
|
-
function getManifestEntry(componentName, entry, componentMetadata, extraMethods) {
|
|
8460
|
-
const testId = entry.selectorValue.formatted;
|
|
8461
|
-
const metadata = componentMetadata?.get(testId);
|
|
8462
|
-
const pom = entry.pom;
|
|
8463
|
-
const generatedActionName = pom ? buildPomGeneratedActionName(pom) : null;
|
|
8464
|
-
const extraActionNames = pom ? extraMethods.filter((extraMethod) => matchesPrimarySelector(extraMethod, pom)).map((extraMethod) => extraMethod.name).sort((a, b) => a.localeCompare(b)) : [];
|
|
8465
|
-
const generatedActionNames = Array.from(/* @__PURE__ */ new Set([
|
|
8466
|
-
...generatedActionName ? [generatedActionName] : [],
|
|
8467
|
-
...extraActionNames.filter((name) => name !== generatedActionName)
|
|
8468
|
-
]));
|
|
8469
|
-
const accessibility = buildAccessibilityAudit(metadata, pom?.nativeRole ?? null);
|
|
8470
|
-
return {
|
|
8471
|
-
testId,
|
|
8472
|
-
selectorPatternKind: entry.selectorValue.patternKind,
|
|
8473
|
-
semanticName: metadata?.semanticName ?? (pom ? humanizePomMethodName(pom.methodName) : testId),
|
|
8474
|
-
locatorDescription: pom ? buildPomLocatorDescription({
|
|
8475
|
-
componentName,
|
|
8476
|
-
methodName: pom.methodName,
|
|
8477
|
-
nativeRole: pom.nativeRole
|
|
8478
|
-
}) : componentName,
|
|
8479
|
-
inferredRole: pom?.nativeRole ?? null,
|
|
8480
|
-
...accessibility ? { accessibility } : {},
|
|
8481
|
-
generatedPropertyName: pom ? buildPomGeneratedPropertyName(pom) : null,
|
|
8482
|
-
generatedActionName,
|
|
8483
|
-
generatedActionNames,
|
|
8484
|
-
emitPrimary: pom?.emitPrimary !== false,
|
|
8485
|
-
...entry.targetPageObjectModelClass ? { targetPageObjectModelClass: entry.targetPageObjectModelClass } : {},
|
|
8486
|
-
...metadata?.tag ? { sourceTag: metadata.tag } : {},
|
|
8487
|
-
...metadata ? { sourceTagType: metadata.tagType } : {},
|
|
8488
|
-
...metadata?.sourceLine !== void 0 ? { sourceLine: metadata.sourceLine } : {},
|
|
8489
|
-
...metadata?.sourceColumn !== void 0 ? { sourceColumn: metadata.sourceColumn } : {},
|
|
8490
|
-
...metadata?.patchFlag !== void 0 ? { patchFlag: metadata.patchFlag } : {},
|
|
8491
|
-
...metadata?.dynamicProps?.length ? { dynamicProps: metadata.dynamicProps } : {},
|
|
8492
|
-
...metadata?.hasClickHandler !== void 0 ? { hasClickHandler: metadata.hasClickHandler } : {},
|
|
8493
|
-
...metadata?.hasDynamicClass !== void 0 ? { hasDynamicClass: metadata.hasDynamicClass } : {},
|
|
8494
|
-
...metadata?.hasDynamicStyle !== void 0 ? { hasDynamicStyle: metadata.hasDynamicStyle } : {},
|
|
8495
|
-
...metadata?.hasDynamicText !== void 0 ? { hasDynamicText: metadata.hasDynamicText } : {}
|
|
8496
|
-
};
|
|
8497
|
-
}
|
|
8498
|
-
function buildPomManifest(componentHierarchyMap, elementMetadata) {
|
|
8499
|
-
const manifestEntries = Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
8500
|
-
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 ?? []));
|
|
8501
|
-
if (!entries.length) {
|
|
8502
|
-
return null;
|
|
8503
|
-
}
|
|
8504
|
-
return [componentName, {
|
|
8505
|
-
componentName,
|
|
8506
|
-
className: componentName,
|
|
8507
|
-
sourceFile: dependencies.filePath,
|
|
8508
|
-
kind: dependencies.isView ? "view" : "component",
|
|
8509
|
-
testIds: Array.from(new Set(entries.map((entry) => entry.testId))),
|
|
8510
|
-
entries
|
|
8511
|
-
}];
|
|
8512
|
-
}).filter((entry) => entry !== null);
|
|
8513
|
-
return Object.fromEntries(manifestEntries);
|
|
8514
|
-
}
|
|
8515
|
-
function buildTestIdManifest(componentHierarchyMap) {
|
|
8516
|
-
return Object.fromEntries(
|
|
8517
|
-
Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
8518
|
-
const testIds = Array.from(dependencies.dataTestIdSet).map((entry) => entry.selectorValue.formatted).filter(Boolean);
|
|
8519
|
-
if (!testIds.length) {
|
|
8520
|
-
return null;
|
|
8521
|
-
}
|
|
8522
|
-
return [componentName, Array.from(new Set(testIds)).sort((a, b) => a.localeCompare(b))];
|
|
8523
|
-
}).filter((entry) => entry !== null)
|
|
8524
|
-
);
|
|
8525
|
-
}
|
|
8526
|
-
function writeConstJson(value) {
|
|
8527
|
-
return (writer) => {
|
|
8528
|
-
writer.write(`${JSON.stringify(value, null, 2)} as const`);
|
|
8529
|
-
};
|
|
8530
|
-
}
|
|
8531
|
-
function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
8532
|
-
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
8533
|
-
const testIdManifest = buildTestIdManifest(componentHierarchyMap);
|
|
8534
|
-
return renderSourceFile("virtual-testids.ts", (sourceFile) => {
|
|
8535
|
-
sourceFile.addStatements("// Virtual module: test id manifest");
|
|
8536
|
-
sourceFile.addVariableStatement({
|
|
8537
|
-
declarationKind: VariableDeclarationKind.Const,
|
|
8538
|
-
isExported: true,
|
|
8539
|
-
declarations: [{
|
|
8540
|
-
name: "testIdManifest",
|
|
8541
|
-
initializer: writeConstJson(testIdManifest)
|
|
8542
|
-
}]
|
|
8543
|
-
});
|
|
8544
|
-
sourceFile.addVariableStatement({
|
|
8545
|
-
declarationKind: VariableDeclarationKind.Const,
|
|
8546
|
-
isExported: true,
|
|
8547
|
-
declarations: [{
|
|
8548
|
-
name: "pomManifest",
|
|
8549
|
-
initializer: writeConstJson(pomManifest)
|
|
8550
|
-
}]
|
|
8551
|
-
});
|
|
8552
|
-
sourceFile.addTypeAlias({
|
|
8553
|
-
isExported: true,
|
|
8554
|
-
name: "TestIdManifest",
|
|
8555
|
-
type: "typeof testIdManifest"
|
|
8556
|
-
});
|
|
8557
|
-
sourceFile.addTypeAlias({
|
|
8558
|
-
isExported: true,
|
|
8559
|
-
name: "ComponentName",
|
|
8560
|
-
type: "keyof TestIdManifest"
|
|
8561
|
-
});
|
|
8562
|
-
sourceFile.addTypeAlias({
|
|
8563
|
-
isExported: true,
|
|
8564
|
-
name: "PomManifest",
|
|
8565
|
-
type: "typeof pomManifest"
|
|
8566
|
-
});
|
|
8567
|
-
sourceFile.addTypeAlias({
|
|
8568
|
-
isExported: true,
|
|
8569
|
-
name: "PomManifestComponentName",
|
|
8570
|
-
type: "keyof PomManifest"
|
|
8571
|
-
});
|
|
8572
|
-
});
|
|
8573
|
-
}
|
|
8574
|
-
function generatePomManifestModule(componentHierarchyMap, elementMetadata) {
|
|
8575
|
-
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
8576
|
-
return renderSourceFile("virtual-pom-manifest.ts", (sourceFile) => {
|
|
8577
|
-
sourceFile.addStatements("// Virtual module: richer POM discoverability manifest");
|
|
8578
|
-
sourceFile.addVariableStatement({
|
|
8579
|
-
declarationKind: VariableDeclarationKind.Const,
|
|
8580
|
-
isExported: true,
|
|
8581
|
-
declarations: [{
|
|
8582
|
-
name: "pomManifest",
|
|
8583
|
-
initializer: writeConstJson(pomManifest)
|
|
8584
|
-
}]
|
|
8585
|
-
});
|
|
8586
|
-
sourceFile.addTypeAlias({
|
|
8587
|
-
isExported: true,
|
|
8588
|
-
name: "PomManifest",
|
|
8589
|
-
type: "typeof pomManifest"
|
|
8590
|
-
});
|
|
8591
|
-
sourceFile.addTypeAlias({
|
|
8592
|
-
isExported: true,
|
|
8593
|
-
name: "PomManifestComponentName",
|
|
8594
|
-
type: "keyof PomManifest"
|
|
8595
|
-
});
|
|
8596
|
-
});
|
|
8597
|
-
}
|
|
8598
8713
|
function resolveExistingIdBehavior(config, componentName) {
|
|
8599
8714
|
return typeof config === "string" ? config : config.components[componentName] ?? config.default;
|
|
8600
8715
|
}
|
|
@@ -8923,6 +9038,7 @@ function isLessRich(candidate, previous) {
|
|
|
8923
9038
|
function createBuildProcessorPlugin(options) {
|
|
8924
9039
|
const {
|
|
8925
9040
|
componentHierarchyMap,
|
|
9041
|
+
elementMetadata,
|
|
8926
9042
|
crossFileKeyRegistry,
|
|
8927
9043
|
vueFilesPathMap,
|
|
8928
9044
|
getPageDirs,
|
|
@@ -9175,7 +9291,8 @@ function createBuildProcessorPlugin(options) {
|
|
|
9175
9291
|
routerType,
|
|
9176
9292
|
pageDirs: getPageDirs(),
|
|
9177
9293
|
componentDirs: getComponentDirs(),
|
|
9178
|
-
layoutDirs: getLayoutDirs()
|
|
9294
|
+
layoutDirs: getLayoutDirs(),
|
|
9295
|
+
elementMetadata
|
|
9179
9296
|
});
|
|
9180
9297
|
lastGeneratedMetrics = metrics;
|
|
9181
9298
|
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
@@ -9187,6 +9304,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9187
9304
|
}
|
|
9188
9305
|
function createDevProcessorPlugin(options) {
|
|
9189
9306
|
const {
|
|
9307
|
+
elementMetadata,
|
|
9190
9308
|
nativeWrappers,
|
|
9191
9309
|
optionKeyAttribute,
|
|
9192
9310
|
excludedComponents,
|
|
@@ -9479,7 +9597,8 @@ function createDevProcessorPlugin(options) {
|
|
|
9479
9597
|
testIdAttribute,
|
|
9480
9598
|
vueRouterFluentChaining: routerAwarePoms,
|
|
9481
9599
|
routerEntry: getResolvedRouterEntry(),
|
|
9482
|
-
routerType
|
|
9600
|
+
routerType,
|
|
9601
|
+
elementMetadata
|
|
9483
9602
|
});
|
|
9484
9603
|
const t1 = performance.now();
|
|
9485
9604
|
logInfo(`generate(${logLabel}): components=${snapshotHierarchy.size} in ${formatMs(t1 - t0)}`);
|
|
@@ -9795,6 +9914,7 @@ function createInternalPlugins(options) {
|
|
|
9795
9914
|
const normalizedBasePagePath = path.posix.normalize(basePageClassPath);
|
|
9796
9915
|
const tsProcessor = createBuildProcessorPlugin({
|
|
9797
9916
|
componentHierarchyMap,
|
|
9917
|
+
elementMetadata,
|
|
9798
9918
|
crossFileKeyRegistry,
|
|
9799
9919
|
vueFilesPathMap,
|
|
9800
9920
|
getPageDirs,
|
|
@@ -9814,6 +9934,7 @@ function createInternalPlugins(options) {
|
|
|
9814
9934
|
loggerRef
|
|
9815
9935
|
});
|
|
9816
9936
|
const devProcessor = createDevProcessorPlugin({
|
|
9937
|
+
elementMetadata,
|
|
9817
9938
|
nativeWrappers,
|
|
9818
9939
|
optionKeyAttribute,
|
|
9819
9940
|
excludedComponents,
|