generateFromRecording function ✓ 100.0%
Last updated: 2026-03-01T23:25:47.083Z
Metrics
LOC: 53
Complexity: 18
Params: 3
Coverage: 100.0% (25/25 lines, 20x executed)
Signature
generateFromRecording(
steps: RecordedStep[],
options?: RecordingGenerateOptions,
): : string
Architecture violations
- [warning] max-cyclomatic-complexity: 'generateFromRecording' has cyclomatic complexity 18 (max 10)
Source Code
function generateFromRecording(
steps: RecordedStep[],
options?: RecordingGenerateOptions,
): string {
const opts = options ?? {};
const testName = opts.testName ?? "recorded test";
const useSmartSelectors = opts.useSmartSelectors !== false;
const minWait = opts.minWaitThreshold ?? 1000;
const lines: string[] = [];
for (let i = 0; i < steps.length; i++) {
const step = steps[i];
if (step.type === "scroll" && !opts.includeScrollSteps) continue;
if (step.type === "hover" && !opts.includeHoverSteps) continue;
if (i === 0 && step.type === "navigate" && opts.pageUrl) continue;
if (i > 0) {
const delta = step.timestamp - steps[i - 1].timestamp;
if (delta >= minWait) {
lines.push(` // User paused for ~${Math.round(delta / 1000)}s`);
lines.push(` cy.wait(${delta});`);
}
}
lines.push(recordedStepLine(step, useSmartSelectors));
}
const urlLine = opts.pageUrl
? ` cy.visit('${escapeString(opts.pageUrl)}');\n\n`
: "";
const assertionLines =
opts.includeAssertions && opts.assertions?.length
? ["\n // Assertions", ...opts.assertions.map(assertionLine)]
: [];
const parts = [
`describe('${escapeString(testName)}', () => {`,
` it('should complete recorded flow', () => {`,
urlLine + lines.join("\n"),
];
if (assertionLines.length > 0) {
parts.push(assertionLines.join("\n"));
}
parts.push(` });`);
parts.push(`});`);
parts.push("");
return parts.join("\n");
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| recordedStepLine | calls |
| escapeString | calls |
No incoming dependencies.