Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a task after all test are launch cypress

I need to execute some code after all tests run. I add this test on after hook. But this task needs the report to be created, but on after hook, the report is not created yet.

I also tried to use

 on('run:end', () => {
        console.log("gdfgfdsafkañjsdfjñaldfkjsñkasfdñlassfjdskafmjassd");
  });

but it does nothing.

like image 408
Marc Avatar asked May 06 '19 14:05

Marc


3 Answers

You can't, there is an open issue for that.

At the moment you can only leverage a package.json post hook. So, if you have a dedicated command in your package.json file

"scripts": {
  "cy:run": "cypress run"
}

you can add a postcy:run script

"scripts": {
  "cy:run": "cypress run",
  "postcy:run": "<YOUR_COMMAND>"
}

I hope it helps you 😊

like image 183
NoriSte Avatar answered Oct 09 '22 19:10

NoriSte


You can now listen to after:run events in the plugins file:

on('after:run', (results) => { /* ... */ })

The event fires after the run.

See more info at After Run API

like image 22
t_dom93 Avatar answered Oct 09 '22 18:10

t_dom93


Be aware that the post hook might not run when the tests fail. I'm currently using a global after hook in support/index.ts for running after all tests

I'm currently using a global after hook in support/index.ts

after(() => {
  // something here
});
like image 2
Maxim Avatar answered Oct 09 '22 18:10

Maxim