generate function ✓ 100.0%

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

Metrics

LOC: 61 Complexity: 12 Params: 3 Coverage: 100.0% (24/24 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 visitLine = opts.pageUrl
    ? `            ->visit('${escapeString(opts.pageUrl)}')\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 chain = [visitLine + fillLines.join("\n")];

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

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

  const parts = [
    `<?php`,
    ``,
    `use Laravel\\Dusk\\Browser;`,
    ``,
    `test('${escapeString(testName)}', function () {`,
    `    $this->browse(function (Browser $browser) {`,
    `        $browser`,
    chain.join("\n"),
    `        ;`,
    `    });`,
    `});`,
  ];

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

  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 "99ff7b1c2c040790.html" click escapeString "5c2f25e3b4548c2d.html" click actionLine "1971834c4f9bc9c3.html" click generateNegativeTest "764ef404a760ebd4.html"
TargetType
escapeString calls
actionLine calls
generateNegativeTest calls

No incoming dependencies.