Skip to content

Instantly share code, notes, and snippets.

@filiphric
Created March 9, 2020 15:49
Show Gist options
  • Save filiphric/fcd1aa541a85cd0c5c70929b10b58403 to your computer and use it in GitHub Desktop.
Save filiphric/fcd1aa541a85cd0c5c70929b10b58403 to your computer and use it in GitHub Desktop.
beforeEach( function() {
window.logCalls = 1;
window.testFlow = [];
});
Cypress.Commands.overwrite('log', (originalFn, message) => {
Cypress.log({
displayName: `--- ${window.logCalls}. ${message} ---`,
name: `--- ${window.logCalls}. ${message} ---`,
message: ''
});
window.testFlow.push(`${window.logCalls}. ${message}`);
window.logCalls++;
});
Cypress.on('fail', (error) => {
throw new Error(error + '\n\nTest flow:\n' + window.testFlow.join('\n'));
});
@clasicul
Copy link

clasicul commented Apr 2, 2020

@filiphric
Copy link
Author

Nice! 👍

@kamilnecas
Copy link

It looks like this is working in Typescript as well. But for some reason "logCalls" and "testFlow" are getting highlighted for not existing property for window. Any recommended solution how to avoid highlighting?

I have found it is feasible to use "any" command but it is a bit dirty according to feedback.

@filiphric
Copy link
Author

I added these to my support/index.js as well:

declare global {
  interface Window {
    logCalls: number;
    testFlow: string[];
  }
}

@kamilnecas
Copy link

Perfect! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment