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
- [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)
| Target | Type |
|---|---|
| escapeString | calls |
| actionLine | calls |
| generateNegativeTest | calls |
No incoming dependencies.