webpipe-js 2.0.41 → 2.0.43

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/dist/index.cjs CHANGED
@@ -1652,6 +1652,11 @@ function printMock(mock, indent = " ") {
1652
1652
  }
1653
1653
  function printCondition(condition, indent = " ") {
1654
1654
  const condType = condition.conditionType.toLowerCase();
1655
+ if (condition.isCallAssertion && condition.callTarget) {
1656
+ const [callType, callName] = condition.callTarget.split(".");
1657
+ const value2 = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1658
+ return `${indent}${condType} call ${callType} ${callName} ${condition.comparison} ${value2}`;
1659
+ }
1655
1660
  if (condition.field === "selector" && condition.selector && condition.domAssert) {
1656
1661
  const selector = condition.selector;
1657
1662
  const formatValue = (val) => {
@@ -1661,13 +1666,13 @@ function printCondition(condition, indent = " ") {
1661
1666
  };
1662
1667
  if (condition.domAssert.kind === "Exists") {
1663
1668
  const operation = condition.comparison === "exists" ? "exists" : "does not exist";
1664
- return `${indent}${condType} selector "${selector}" ${operation}`;
1669
+ return `${indent}${condType} selector \`${selector}\` ${operation}`;
1665
1670
  } else if (condition.domAssert.kind === "Text") {
1666
- return `${indent}${condType} selector "${selector}" text ${condition.comparison} ${formatValue(condition.value)}`;
1671
+ return `${indent}${condType} selector \`${selector}\` text ${condition.comparison} ${formatValue(condition.value)}`;
1667
1672
  } else if (condition.domAssert.kind === "Count") {
1668
- return `${indent}${condType} selector "${selector}" count ${condition.comparison} ${condition.value}`;
1673
+ return `${indent}${condType} selector \`${selector}\` count ${condition.comparison} ${condition.value}`;
1669
1674
  } else if (condition.domAssert.kind === "Attribute") {
1670
- return `${indent}${condType} selector "${selector}" attribute "${condition.domAssert.name}" ${condition.comparison} ${formatValue(condition.value)}`;
1675
+ return `${indent}${condType} selector \`${selector}\` attribute "${condition.domAssert.name}" ${condition.comparison} ${formatValue(condition.value)}`;
1671
1676
  }
1672
1677
  }
1673
1678
  const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
@@ -1680,13 +1685,14 @@ function printTest(test) {
1680
1685
  test.mocks.forEach((mock) => {
1681
1686
  lines.push(printMock(mock, " "));
1682
1687
  });
1683
- lines.push(` when ${formatWhen(test.when)}`);
1684
- if (test.variables) {
1688
+ if (test.variables && test.variables.length > 0) {
1685
1689
  test.variables.forEach((variable) => {
1686
1690
  const formattedValue = variable.format === "quoted" ? `"${variable.value}"` : variable.format === "backtick" ? `\`${variable.value}\`` : variable.value;
1687
1691
  lines.push(` let ${variable.name} = ${formattedValue}`);
1688
1692
  });
1693
+ lines.push("");
1689
1694
  }
1695
+ lines.push(` when ${formatWhen(test.when)}`);
1690
1696
  if (test.input) {
1691
1697
  lines.push(` with input \`${test.input}\``);
1692
1698
  }
@@ -1867,10 +1873,16 @@ function formatPipelineStep(step, indent = " ") {
1867
1873
  } else if (step.kind === "Dispatch") {
1868
1874
  const lines = [`${indent}|> dispatch`];
1869
1875
  step.branches.forEach((branch) => {
1870
- lines.push(`${indent} case ${formatTagExpr(branch.condition)}:`);
1871
- branch.pipeline.steps.forEach((branchStep) => {
1872
- lines.push(formatPipelineStep(branchStep, indent + " "));
1873
- });
1876
+ if (branch.pipeline.steps.length === 1) {
1877
+ const inlineStep = formatPipelineStep(branch.pipeline.steps[0], indent + " ");
1878
+ const stepContent = inlineStep.substring((indent + " ").length);
1879
+ lines.push(`${indent} case ${formatTagExpr(branch.condition)}: ${stepContent}`);
1880
+ } else {
1881
+ lines.push(`${indent} case ${formatTagExpr(branch.condition)}:`);
1882
+ branch.pipeline.steps.forEach((branchStep) => {
1883
+ lines.push(formatPipelineStep(branchStep, indent + " "));
1884
+ });
1885
+ }
1874
1886
  });
1875
1887
  if (step.default) {
1876
1888
  lines.push(`${indent} default:`);
package/dist/index.mjs CHANGED
@@ -1599,6 +1599,11 @@ function printMock(mock, indent = " ") {
1599
1599
  }
1600
1600
  function printCondition(condition, indent = " ") {
1601
1601
  const condType = condition.conditionType.toLowerCase();
1602
+ if (condition.isCallAssertion && condition.callTarget) {
1603
+ const [callType, callName] = condition.callTarget.split(".");
1604
+ const value2 = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1605
+ return `${indent}${condType} call ${callType} ${callName} ${condition.comparison} ${value2}`;
1606
+ }
1602
1607
  if (condition.field === "selector" && condition.selector && condition.domAssert) {
1603
1608
  const selector = condition.selector;
1604
1609
  const formatValue = (val) => {
@@ -1608,13 +1613,13 @@ function printCondition(condition, indent = " ") {
1608
1613
  };
1609
1614
  if (condition.domAssert.kind === "Exists") {
1610
1615
  const operation = condition.comparison === "exists" ? "exists" : "does not exist";
1611
- return `${indent}${condType} selector "${selector}" ${operation}`;
1616
+ return `${indent}${condType} selector \`${selector}\` ${operation}`;
1612
1617
  } else if (condition.domAssert.kind === "Text") {
1613
- return `${indent}${condType} selector "${selector}" text ${condition.comparison} ${formatValue(condition.value)}`;
1618
+ return `${indent}${condType} selector \`${selector}\` text ${condition.comparison} ${formatValue(condition.value)}`;
1614
1619
  } else if (condition.domAssert.kind === "Count") {
1615
- return `${indent}${condType} selector "${selector}" count ${condition.comparison} ${condition.value}`;
1620
+ return `${indent}${condType} selector \`${selector}\` count ${condition.comparison} ${condition.value}`;
1616
1621
  } else if (condition.domAssert.kind === "Attribute") {
1617
- return `${indent}${condType} selector "${selector}" attribute "${condition.domAssert.name}" ${condition.comparison} ${formatValue(condition.value)}`;
1622
+ return `${indent}${condType} selector \`${selector}\` attribute "${condition.domAssert.name}" ${condition.comparison} ${formatValue(condition.value)}`;
1618
1623
  }
1619
1624
  }
1620
1625
  const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
@@ -1627,13 +1632,14 @@ function printTest(test) {
1627
1632
  test.mocks.forEach((mock) => {
1628
1633
  lines.push(printMock(mock, " "));
1629
1634
  });
1630
- lines.push(` when ${formatWhen(test.when)}`);
1631
- if (test.variables) {
1635
+ if (test.variables && test.variables.length > 0) {
1632
1636
  test.variables.forEach((variable) => {
1633
1637
  const formattedValue = variable.format === "quoted" ? `"${variable.value}"` : variable.format === "backtick" ? `\`${variable.value}\`` : variable.value;
1634
1638
  lines.push(` let ${variable.name} = ${formattedValue}`);
1635
1639
  });
1640
+ lines.push("");
1636
1641
  }
1642
+ lines.push(` when ${formatWhen(test.when)}`);
1637
1643
  if (test.input) {
1638
1644
  lines.push(` with input \`${test.input}\``);
1639
1645
  }
@@ -1814,10 +1820,16 @@ function formatPipelineStep(step, indent = " ") {
1814
1820
  } else if (step.kind === "Dispatch") {
1815
1821
  const lines = [`${indent}|> dispatch`];
1816
1822
  step.branches.forEach((branch) => {
1817
- lines.push(`${indent} case ${formatTagExpr(branch.condition)}:`);
1818
- branch.pipeline.steps.forEach((branchStep) => {
1819
- lines.push(formatPipelineStep(branchStep, indent + " "));
1820
- });
1823
+ if (branch.pipeline.steps.length === 1) {
1824
+ const inlineStep = formatPipelineStep(branch.pipeline.steps[0], indent + " ");
1825
+ const stepContent = inlineStep.substring((indent + " ").length);
1826
+ lines.push(`${indent} case ${formatTagExpr(branch.condition)}: ${stepContent}`);
1827
+ } else {
1828
+ lines.push(`${indent} case ${formatTagExpr(branch.condition)}:`);
1829
+ branch.pipeline.steps.forEach((branchStep) => {
1830
+ lines.push(formatPipelineStep(branchStep, indent + " "));
1831
+ });
1832
+ }
1821
1833
  });
1822
1834
  if (step.default) {
1823
1835
  lines.push(`${indent} default:`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.41",
3
+ "version": "2.0.43",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",