Skip to content

Commit

Permalink
Capture failed cypress commands via log events (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjduffy authored Aug 9, 2023
1 parent 73a6bd2 commit 58907b5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/cypress/src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,37 @@ export default function register() {
lastCommand = cmd;
lastAssertionCommand = undefined;

function handleCommandLogAdded(newLog: any) {
function handleCommandLogChanged(changedLog: any) {
if (changedLog.id === newLog.id) {
if (changedLog.state === "failed" && changedLog.err) {
const err: TestError = {
name: changedLog.err.name,
message: changedLog.err.message,
line: changedLog.codeFrame?.line,
column: changedLog.codeFrame?.column,
};

addAnnotationWithReferences(
currentTestScope!,
"step:end",
getReplayId(getCypressId(cmd)),
cmd,
changedLog
);
handleCypressEvent(currentTestScope!, "step:end", "command", toCommandJSON(cmd), err);
}
}
}

if (cmd.get("logs")?.find((l: any) => l.get("id") === newLog.id)) {
Cypress.on("log:changed", handleCommandLogChanged);
Cypress.off("log:added", handleCommandLogAdded);
}
}

Cypress.on("log:added", handleCommandLogAdded);

addAnnotationWithReferences(
currentTestScope!,
"step:start",
Expand Down

0 comments on commit 58907b5

Please sign in to comment.