Last active
September 5, 2021 20:30
-
-
Save michalcs/13bf9a264977a7d086658f6c611d29d9 to your computer and use it in GitHub Desktop.
Cypress Speed Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// START Test speed of run | |
let commands = [] | |
Cypress.on('test:after:run', (attributes) => { | |
/* eslint-disable no-console */ | |
console.log('Test "%s" has finished in %dms', | |
attributes.title, attributes.duration) | |
console.table(commands) | |
commands.length = 0 | |
}) | |
Cypress.on('command:start', (c) => { | |
commands.push({ | |
name: c.attributes.name, | |
started: +new Date(), | |
}) | |
}) | |
Cypress.on('command:end', (c) => { | |
const lastCommand = commands[commands.length - 1] | |
if (lastCommand.name !== c.attributes.name) { | |
throw new Error('Last command is wrong') | |
} | |
lastCommand.endedAt = +new Date() | |
lastCommand.elapsed = lastCommand.endedAt - lastCommand.started | |
}) | |
// END Test speed of run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment