@immense/vue-pom-generator 1.0.78 → 1.0.80
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 +46 -3
- package/RELEASE_NOTES.md +34 -52
- package/class-generation/index.ts +87 -37
- package/dist/index.cjs +135 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +135 -38
- package/dist/index.mjs.map +1 -1
- package/dist/transform.d.ts.map +1 -1
- package/dist/utils.d.ts +24 -0
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1503,6 +1503,66 @@ function tryExtractSlotScopeVariableNames(expression) {
|
|
|
1503
1503
|
}
|
|
1504
1504
|
return names;
|
|
1505
1505
|
}
|
|
1506
|
+
function unwrapToBareCallbackIdentifier(node) {
|
|
1507
|
+
if (!node) {
|
|
1508
|
+
return null;
|
|
1509
|
+
}
|
|
1510
|
+
if (isFile(node)) {
|
|
1511
|
+
const stmt = node.program.body[0];
|
|
1512
|
+
return isExpressionStatement(stmt) ? unwrapToBareCallbackIdentifier(stmt.expression) : null;
|
|
1513
|
+
}
|
|
1514
|
+
if (isProgram(node)) {
|
|
1515
|
+
const stmt = node.body[0];
|
|
1516
|
+
return isExpressionStatement(stmt) ? unwrapToBareCallbackIdentifier(stmt.expression) : null;
|
|
1517
|
+
}
|
|
1518
|
+
if (isExpressionStatement(node)) {
|
|
1519
|
+
return unwrapToBareCallbackIdentifier(node.expression);
|
|
1520
|
+
}
|
|
1521
|
+
if (isIdentifier(node)) {
|
|
1522
|
+
return node.name;
|
|
1523
|
+
}
|
|
1524
|
+
if (isCallExpression(node) || isOptionalCallExpression(node)) {
|
|
1525
|
+
const callee = node.callee;
|
|
1526
|
+
if (isIdentifier(callee) && (callee.name === "withModifiers" || callee.name === "_withModifiers")) {
|
|
1527
|
+
return unwrapToBareCallbackIdentifier(node.arguments[0]);
|
|
1528
|
+
}
|
|
1529
|
+
return null;
|
|
1530
|
+
}
|
|
1531
|
+
if (isArrowFunctionExpression(node)) {
|
|
1532
|
+
return isBlockStatement(node.body) ? null : unwrapToBareCallbackIdentifier(node.body);
|
|
1533
|
+
}
|
|
1534
|
+
return null;
|
|
1535
|
+
}
|
|
1536
|
+
function tryGetBareCallbackClickHandlerName(node) {
|
|
1537
|
+
const click = tryGetClickDirective(node);
|
|
1538
|
+
if (!click?.exp) {
|
|
1539
|
+
return null;
|
|
1540
|
+
}
|
|
1541
|
+
const source = getVueExpressionSource(click.exp, "content", "compiled");
|
|
1542
|
+
if (!source) {
|
|
1543
|
+
return null;
|
|
1544
|
+
}
|
|
1545
|
+
const parsed = tryParseBabelAstFromHandlerSource(source);
|
|
1546
|
+
if (!parsed) {
|
|
1547
|
+
return null;
|
|
1548
|
+
}
|
|
1549
|
+
return unwrapToBareCallbackIdentifier(parsed);
|
|
1550
|
+
}
|
|
1551
|
+
function isSlotScopeCallbackClickHandler(node, hierarchyMap2) {
|
|
1552
|
+
const handlerName = tryGetBareCallbackClickHandlerName(node);
|
|
1553
|
+
if (!handlerName) {
|
|
1554
|
+
return false;
|
|
1555
|
+
}
|
|
1556
|
+
const templateNode = getContainedInSlotTemplateNode(node, hierarchyMap2);
|
|
1557
|
+
if (!templateNode) {
|
|
1558
|
+
return false;
|
|
1559
|
+
}
|
|
1560
|
+
const scopeExpression = findTemplateSlotScopeExpression(templateNode);
|
|
1561
|
+
if (!scopeExpression) {
|
|
1562
|
+
return false;
|
|
1563
|
+
}
|
|
1564
|
+
return tryExtractSlotScopeVariableNames(scopeExpression).includes(handlerName);
|
|
1565
|
+
}
|
|
1506
1566
|
function nodeHasToDirective(node) {
|
|
1507
1567
|
const toDirective = findDirectiveByName(node, "bind", "to");
|
|
1508
1568
|
if (toDirective?.exp) {
|
|
@@ -5485,15 +5545,16 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5485
5545
|
sourceFile.addStatements("/** Generated Playwright fixtures (typed page objects). */");
|
|
5486
5546
|
addNamedImport(sourceFile, {
|
|
5487
5547
|
moduleSpecifier: "@playwright/test",
|
|
5488
|
-
namedImports: [
|
|
5489
|
-
"expect",
|
|
5490
|
-
{ name: "test", alias: "base" }
|
|
5491
|
-
]
|
|
5548
|
+
namedImports: ["expect"]
|
|
5492
5549
|
});
|
|
5493
5550
|
addNamedImport(sourceFile, {
|
|
5494
5551
|
moduleSpecifier: "@playwright/test",
|
|
5495
5552
|
isTypeOnly: true,
|
|
5496
|
-
namedImports: [
|
|
5553
|
+
namedImports: [
|
|
5554
|
+
{ name: "Page", alias: "PwPage" },
|
|
5555
|
+
"PlaywrightTestArgs",
|
|
5556
|
+
"TestType"
|
|
5557
|
+
]
|
|
5497
5558
|
});
|
|
5498
5559
|
sourceFile.addImportDeclaration({
|
|
5499
5560
|
namespaceImport: "Pom",
|
|
@@ -5577,6 +5638,14 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5577
5638
|
name: "GeneratedComponentFixtures",
|
|
5578
5639
|
type: "{ [K in keyof typeof componentCtors]: InstanceType<(typeof componentCtors)[K]> }"
|
|
5579
5640
|
});
|
|
5641
|
+
sourceFile.addTypeAlias({
|
|
5642
|
+
isExported: true,
|
|
5643
|
+
name: "PomFixtures",
|
|
5644
|
+
docs: [{
|
|
5645
|
+
description: "Every fixture contributed by the generator: the `animation` option, the internal\n`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM."
|
|
5646
|
+
}],
|
|
5647
|
+
type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
|
|
5648
|
+
});
|
|
5580
5649
|
sourceFile.addFunction({
|
|
5581
5650
|
name: "makePomFixture",
|
|
5582
5651
|
typeParameters: [{ name: "T" }],
|
|
@@ -5599,43 +5668,61 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
5599
5668
|
"return out as any;"
|
|
5600
5669
|
]
|
|
5601
5670
|
});
|
|
5602
|
-
sourceFile.
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5671
|
+
sourceFile.addStatements([
|
|
5672
|
+
"/**",
|
|
5673
|
+
" * Attach the generated POM fixtures to a project-owned Playwright `test`.",
|
|
5674
|
+
" *",
|
|
5675
|
+
" * This generator deliberately does not export a `test` of its own. Projects should own",
|
|
5676
|
+
" * exactly one `test` object so project-wide fixtures (console-error capture, error-overlay",
|
|
5677
|
+
" * detection, auth, ...) are inherited by every spec. Compose it once in a project module:",
|
|
5678
|
+
" *",
|
|
5679
|
+
" * const base = playwrightTest.extend({ ...project-wide fixtures... });",
|
|
5680
|
+
" * export const test = withPomFixtures(base);",
|
|
5681
|
+
" *",
|
|
5682
|
+
" * Then have every spec import `test` from that module.",
|
|
5683
|
+
" */"
|
|
5684
|
+
].join("\n"));
|
|
5685
|
+
sourceFile.addFunction({
|
|
5686
|
+
isExported: true,
|
|
5687
|
+
name: "withPomFixtures",
|
|
5688
|
+
typeParameters: [
|
|
5689
|
+
{ name: "TTestArgs", constraint: "PlaywrightTestArgs" },
|
|
5690
|
+
{ name: "TWorkerArgs", constraint: "object" }
|
|
5691
|
+
],
|
|
5692
|
+
parameters: [{ name: "base", type: "TestType<TTestArgs, TWorkerArgs>" }],
|
|
5693
|
+
returnType: "TestType<TTestArgs & PomFixtures, TWorkerArgs>",
|
|
5694
|
+
statements: (writer) => {
|
|
5695
|
+
writer.write("return base.extend<PomFixtures>(");
|
|
5696
|
+
writer.block(() => {
|
|
5697
|
+
writer.writeLine("animation: [{");
|
|
5698
|
+
writer.indent(() => {
|
|
5699
|
+
writer.writeLine('pointer: { durationMilliseconds: 250, transitionStyle: "ease-in-out", clickDelayMilliseconds: 0 },');
|
|
5700
|
+
writer.writeLine("keyboard: { typeDelayMilliseconds: 100 },");
|
|
5701
|
+
});
|
|
5702
|
+
writer.writeLine("}, { option: true }],");
|
|
5703
|
+
writer.writeLine("pomSetup: [async ({ animation }: PomFixtures, use: (r: void) => Promise<void>) => {");
|
|
5704
|
+
writer.indent(() => {
|
|
5705
|
+
writer.writeLine("Pom.setPlaywrightAnimationOptions(animation);");
|
|
5706
|
+
writer.writeLine("await use();");
|
|
5707
|
+
});
|
|
5708
|
+
writer.writeLine("}, { auto: true }],");
|
|
5709
|
+
writer.writeLine("pomFactory: async ({ page }: { page: PwPage }, use: (r: PomFactory) => Promise<void>) => {");
|
|
5710
|
+
writer.indent(() => {
|
|
5711
|
+
writer.writeLine("await use({");
|
|
5622
5712
|
writer.indent(() => {
|
|
5623
|
-
writer.writeLine("
|
|
5624
|
-
writer.indent(() => {
|
|
5625
|
-
writer.writeLine("create: <T>(ctor: PomConstructor<T>) => new ctor(page),");
|
|
5626
|
-
});
|
|
5627
|
-
writer.writeLine("});");
|
|
5713
|
+
writer.writeLine("create: <T>(ctor: PomConstructor<T>) => new ctor(page),");
|
|
5628
5714
|
});
|
|
5629
|
-
writer.writeLine("}
|
|
5630
|
-
writer.writeLine("...createPomFixtures(pageCtors),");
|
|
5631
|
-
writer.writeLine("...createPomFixtures(componentCtors),");
|
|
5715
|
+
writer.writeLine("});");
|
|
5632
5716
|
});
|
|
5633
|
-
writer.
|
|
5634
|
-
|
|
5635
|
-
|
|
5717
|
+
writer.writeLine("},");
|
|
5718
|
+
writer.writeLine("...createPomFixtures(pageCtors),");
|
|
5719
|
+
writer.writeLine("...createPomFixtures(componentCtors),");
|
|
5720
|
+
});
|
|
5721
|
+
writer.write(") as TestType<TTestArgs & PomFixtures, TWorkerArgs>;");
|
|
5722
|
+
}
|
|
5636
5723
|
});
|
|
5637
5724
|
sourceFile.addExportDeclaration({
|
|
5638
|
-
namedExports: ["
|
|
5725
|
+
namedExports: ["expect"]
|
|
5639
5726
|
});
|
|
5640
5727
|
}, {
|
|
5641
5728
|
prefixText: buildFilePrefix({
|
|
@@ -5685,9 +5772,16 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
5685
5772
|
return match;
|
|
5686
5773
|
};
|
|
5687
5774
|
const rawComponentRefsForInstances = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
|
|
5775
|
+
const ownClassName = toPascalCaseLocal(componentName);
|
|
5776
|
+
const isSelfReference = (ref) => {
|
|
5777
|
+
return toPascalCaseLocal(normalizeTrackedComponentRef(ref)) === ownClassName && ownClassName.length > 0;
|
|
5778
|
+
};
|
|
5688
5779
|
const componentRefsForInstances = /* @__PURE__ */ new Set();
|
|
5689
5780
|
for (const ref of rawComponentRefsForInstances) {
|
|
5690
5781
|
const resolvedRef = resolveTrackedComponentRef(ref) ?? normalizeTrackedComponentRef(ref);
|
|
5782
|
+
if (isSelfReference(resolvedRef)) {
|
|
5783
|
+
continue;
|
|
5784
|
+
}
|
|
5691
5785
|
const resolvedDependencies = componentHierarchyMap.get(resolvedRef);
|
|
5692
5786
|
if (!resolvedDependencies?.dataTestIdSet.size) {
|
|
5693
5787
|
continue;
|
|
@@ -7412,7 +7506,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
7412
7506
|
const inferred = tryInferNativeWrapperRoleFromSfc(element.tag, vueFilesPathMap, wrapperSearchRoots);
|
|
7413
7507
|
if (inferred?.role) {
|
|
7414
7508
|
nativeWrappers[element.tag] = { role: inferred.role, inferred: true };
|
|
7415
|
-
} else if (element.tag.endsWith("Button")
|
|
7509
|
+
} else if (element.tag.endsWith("Button")) {
|
|
7416
7510
|
nativeWrappers[element.tag] = { role: "button" };
|
|
7417
7511
|
} else if (element.tag === "DxDataGrid") {
|
|
7418
7512
|
nativeWrappers[element.tag] = { role: "grid" };
|
|
@@ -7427,6 +7521,9 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
7427
7521
|
}
|
|
7428
7522
|
const slotKeyInfo = getContainedInSlotDataKeyInfo(element, hierarchyMap);
|
|
7429
7523
|
if (slotKeyInfo) {
|
|
7524
|
+
if (isSlotScopeCallbackClickHandler(element, hierarchyMap)) {
|
|
7525
|
+
return null;
|
|
7526
|
+
}
|
|
7430
7527
|
return slotKeyInfo;
|
|
7431
7528
|
}
|
|
7432
7529
|
if (crossFileKeyRegistry) {
|