generate function ✓ 100.0%

Last updated: 2026-03-01T23:25:47.083Z

Metrics

LOC: 56 Complexity: 12 Params: 3 Coverage: 100.0% (26/26 lines, 16x executed)

Signature

generate( actions: CapturedAction[], options?: E2EGenerateOptions, ): : string

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'generate' has cyclomatic complexity 12 (max 10)

Source Code

function generate(
  actions: CapturedAction[],
  options?: E2EGenerateOptions,
): string {
  const opts = options ?? {};
  const testName = opts.testName ?? "fill form";
  const useSmartSelectors = opts.useSmartSelectors !== false;
  const urlLine = opts.pageUrl
    ? `    cy.visit('${escapeString(opts.pageUrl)}');\n\n`
    : "";

  const fillActions = actions.filter(
    (a) => a.actionType !== "click" && a.actionType !== "submit",
  );
  const submitActions = actions.filter(
    (a) => a.actionType === "click" || a.actionType === "submit",
  );

  const fillLines = fillActions.map((a) => actionLine(a, useSmartSelectors));
  const submitLines = submitActions.map((a) =>
    actionLine(a, useSmartSelectors),
  );

  const assertionLines =
    opts.includeAssertions && opts.assertions?.length
      ? ["\n    // Assertions", ...opts.assertions.map(assertionLine)]
      : [];

  const parts = [
    `describe('${escapeString(testName)}', () => {`,
    `  it('should fill all fields', () => {`,
    urlLine + fillLines.join("\n"),
  ];

  if (submitLines.length > 0) {
    parts.push("");
    parts.push("    // Submit");
    parts.push(submitLines.join("\n"));
  }

  if (assertionLines.length > 0) {
    parts.push(assertionLines.join("\n"));
  }

  parts.push(`  });`);

  // Negative test
  if (opts.includeNegativeTest) {
    const negativeTest = generateNegativeTest(actions, opts, useSmartSelectors);
    if (negativeTest) parts.push(negativeTest);
  }

  parts.push(`});`);
  parts.push("");
  return parts.join("\n");
}

Dependencies (Outgoing)

graph LR generate["generate"] escapeString["escapeString"] actionLine["actionLine"] generateNegativeTest["generateNegativeTest"] generate -->|calls| escapeString generate -->|calls| actionLine generate -->|calls| generateNegativeTest style generate fill:#dbeafe,stroke:#2563eb,stroke-width:2px click generate "99b2368cd85b1514.html" click escapeString "5c2f25e3b4548c2d.html" click actionLine "1971834c4f9bc9c3.html" click generateNegativeTest "764ef404a760ebd4.html"
TargetType
escapeString calls
actionLine calls
generateNegativeTest calls

No incoming dependencies.