Skip to content

Instantly share code, notes, and snippets.

@michalcs
Last active September 5, 2021 20:30
Show Gist options
  • Save michalcs/13bf9a264977a7d086658f6c611d29d9 to your computer and use it in GitHub Desktop.
Save michalcs/13bf9a264977a7d086658f6c611d29d9 to your computer and use it in GitHub Desktop.
Cypress Speed Test
// 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