cypress-realworld-app
cypress-realworld-app copied to clipboard
Trash assets failure with screenshots in nested folders
If a test fails, then the option trashAssetsBeforeRuns with default true fails to delete previous screenshots on Windows 11 if there have been previous runs which produced screenshots in nested sub-folders of cypress/screenshots.
The error message is:
DevTools listening on ws://127.0.0.1:59399/devtools/browser/d422c0e5-e2d8-456e-9962-e48e167e8351
Warning: We failed to trash the existing run results.
This error will not affect or change the exit code.
Error: Command failed: C:\Users\mikem\AppData\Local\Cypress\Cache\12.13.0\Cypress\resources\app\node_modules\trash\lib\win-trash.exe C:\Users\mikem\github\cypress-io\cypress-realworld-app\cypress\screenshots\ui
at ChildProcess.exithandler (node:child_process:407:12)
at ChildProcess.emit (node:events:527:28)
at maybeClose (node:internal/child_process:1092:16)
at Process.onexit (node:internal/child_process:302:5)
The script dev is opening the screenshots, which prevents Cypress trash from working.
Steps to reproduce
Cypress: ~~12.13.0~~ 13.0.0 Operating system: Windows 11 Node.js: ~~16.16.0~~ 18.16.1
Create a new test spec cypress/tests/demo/show-fail.spec.ts with the following contents which will always fail when run:
it("show test failing", function () {
throw new Error("deliberate hard failure");
});
Execute
yarn
yarn dev
then in a separate terminal window, execute
yarn cypress:run
The new test should fail and generate 3 screenshots ~~and 1 video~~.
Kill the devprocess (if necessary sign out and back in again) and repeat
yarn dev
and again in a separate terminal window, execute
yarn cypress:run
Note the error message (see above).
Attempt to delete cypress/screenshots in Windows Explorer.
Note message "Folder Access Denied / You'll need to provide administrator permission to delete this folder". Deletion is not possible.
Kill yarn dev process.
Attempt to delete cypress/screenshots in Windows Explorer.
This is successful.
Suggestions
~~- When RWA is reworked, consider if this can be fixed.~~
- For Cypress itself, consider if the npm module trash is the best option for cleaning up temporary files (screenshots, etc.). trash readme says that the Linux implementation is not maintained. As shown by this issue it cannot delete open files. Perhaps the npm module rimraf would be a better choice for Cypress?