Skip to content

fix: prevent overwriting of video files #30673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Apr 29, 2025

Conversation

YJDoc2
Copy link
Contributor

@YJDoc2 YJDoc2 commented Nov 25, 2024

Additional details

Why was this change necessary?

Currently multiple runs of cypress in same dir (with trashAssetsBeforeRuns=false) will keep the screenshots files across runs, but will overwrite the video file. For more details, please check the issue discussion.

What is affected by this change?

The videos dir will now retain existing video files if trashAssetsBeforeRuns=false is set

Any implementation details to explain?

Nothing much, I have moved the getPath function used for generating screenshot paths into fs.ts from screenshot.js and did some minor modifications to accommodate both screenshots and videos. There is one "hack" which I'm not sure how to fix, help appreciated :

  • The existing impl of getPath actually creates a file on the path to see if that has ENAMETOOLONG error.
  • Because of this, when getting path for compressed video file, it creates a file with -compressed suffix even if video compression is off.
  • For this I am removing the file manually in the video compression check, but is there any other way?

Steps to test

  • Use a simple cypress spec with screenshot and video recording turned on in the config. Have atleast one failing test in that.
  • Run cypress on it once. list all files in screenshots as well as videos
  • Run cypress again.
  • After the second run :

For current develop branch,

  • screenshot folder will have two copies of each failed test, one with name like spec1 -- testCase1 (failed).png and other with name spec1 -- testCase1 (failed) (1).png
  • Video folder will only have spec1.cy.js.mp4

For this branch,

  • screenshot folder will have two copies of each failed test, one with name like spec1 -- testCase1 (failed).png and other with name spec1 -- testCase1 (failed) (1).png
  • Video folder will have spec1.cy.js.mp4 and spec1.cy.js (1).mp4

How has the user experience changed?

They will keep the videos from previous runs if any.

PR Tasks

  • Have tests been added/updated : Added system test
  • Has a PR for user-facing changes been opened in cypress-documentation: This is a bug fix, I don't think this is applicable,
  • Have API changes been updated in the type definitions : I don't think this is applicable.

@CLAassistant
Copy link

CLAassistant commented Nov 25, 2024

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link
Collaborator

@YJDoc2
Copy link
Contributor Author

YJDoc2 commented Nov 25, 2024

Not sure why semantic CI is failing, I have added changelog entry. I don't think this will make to the next release so might have to update it later.

btw, this PR is ready for review.

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Nov 25, 2024

@YJDoc2

Not sure why semantic CI is failing, I have added changelog entry. I don't think this will make to the next release so might have to update it later.

The previous PR introduced an unwanted blank line 2 which is causing your failure.

<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 13.16.1

The blank line should be removed.

Signed-off-by: Yashodhan Joshi <[email protected]>
@YJDoc2
Copy link
Contributor Author

YJDoc2 commented Nov 26, 2024

Hey @MikeMcC399 , thanks for the help! I have fixed the changelog and pushed.

@jennifer-shehane
Copy link
Member

@YJDoc2 Thanks for the contribution. Can you write a test that verifies the change in behavior?

@jennifer-shehane jennifer-shehane self-requested a review December 2, 2024 15:47
@YJDoc2
Copy link
Contributor Author

YJDoc2 commented Dec 10, 2024

Hey @jennifer-shehane , I have added a system test for this change. Also I synced the branch using develop-merge, if you want me to rebase instead, I'll do it and push.
Also there is some code repetition in the test code, but because it is isolated and not reusable outside this, I have kept it. Let me know if you want me to refactor it as well.

Thanks :)

@jennifer-shehane
Copy link
Member

@YJDoc2 Thanks! We'll give it a look over as soon as we can.

@AtofStryker AtofStryker self-requested a review December 10, 2024 15:20
@YJDoc2
Copy link
Contributor Author

YJDoc2 commented Jan 9, 2025

Hey I'm facing some issues while syncing my branch with develop. There were some conflicts because develop has changed the screenshot.js to screenshot.ts , but even after fixing those, the pre-commit hook is failing eslint on files which are from the develop branch (i.e. I have only changed screenshot.ts file, and it is passing the eslint).

cc: @jennifer-shehane

@jennifer-shehane
Copy link
Member

@YJDoc2 We haven't forgotten about this PR! We're working hard on getting Cypress 14 out first because we don't want to add any more scope to that release, so this will go in a release after that if approved.

We can take a look at the conflicts - indeed a lot changed.

@YJDoc2
Copy link
Contributor Author

YJDoc2 commented Jan 16, 2025

We're working hard on getting Cypress 14 out first because we don't want to add any more scope to that release, so this will go in a release after that if approved.

I didn't know that, makes sense to wait for release before adding this then.

We can take a look at the conflicts - indeed a lot changed.

Yep, I'm still interested in following this PR, so when the release is done and you all have bandwidth for this, ping me and we can figure out the problem together. I'll pause any update on this in the meantime, as because the pre-commit hook itself is failing, I cannot push any updates at all.

Thanks for your response and follow-up!

Co-authored-by: Mike McCready <[email protected]>
@jennifer-shehane
Copy link
Member

I have the conflicts fixed in my branch, but I need to get these eslint fixes in first because the repo is in a weird place without that. d9550ad

@jennifer-shehane
Copy link
Member

K, I've got a cleaner merge on this PR now

@YJDoc2
Copy link
Contributor Author

YJDoc2 commented Mar 31, 2025

Hey @jennifer-shehane I have updated the call of getPath I had introduced to pass the param correctly, so that ts lint does not error on it anymore. Also fixed another lint by updating the type in the branch. Apart from that as I mentioned before, the lints which are failing in this branch are also failing in the develop branch.

Another thing to mention, the e2e tests I had added were passing when I added them, however now they are failing with ts related errors in the auth module. Do you know anything about it? The exact error is -

Cannot use import statement outside a module
/......../cypress/packages/server/lib/modes/index.ts:1
import { setCtx } from '@packages/data-context'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1385:21)
/....../cypress/packages/server/lib/makeDataContext.ts:1
import { DataContext, getCtx, clearCtx, setCtx } from '@packages/data-context'
/......../cypress/packages/server/lib/cloud/auth.ts:222
  .catch((err: Error) => {
             ^

Thanks :)

@jennifer-shehane jennifer-shehane self-requested a review April 1, 2025 15:00
@jennifer-shehane
Copy link
Member

@YJDoc2 We won't have time to dedicate to updating this PR at the moment as we're focused on other things. We'll likely need to close it if the issues can't be resolved.

@YJDoc2
Copy link
Contributor Author

YJDoc2 commented Apr 17, 2025

We'll likely need to close it if the issues can't be resolved.

Ok, I needed some help with the auth error in test ; but if you don't have available time to look at this, give me maybe till this weekend, I'll try to see if I can do something.

Apart from that, there is nothing blocking for this, right?

@YJDoc2
Copy link
Contributor Author

YJDoc2 commented Apr 17, 2025

Hey, is there any issue with snapshot builing on develop branch? I tried to clean the workspace and re-install everything, but the snapshot generation is failing . There is no specific error but the last step in log is metadata generation. Because snapshot generation is failing, I cannot run the tests to fix them. Please let me know if there is any know issue with snapshot generation .

@AtofStryker
Copy link
Contributor

@YJDoc2 going to make a note to take a look at this tomorrow

@AtofStryker
Copy link
Contributor

Hi @YJDoc2. Looks like mksnapshot wasn't happy with trying to due type imports in the same place as actual imports (I had to turn the error debug logs on to see it)
Screenshot 2025-04-18 at 12 15 04 PM

I broke this out into a separate line, updated the branch with develop, and moved the changelog to the next release. Let me know if you are still running into issues!

@YJDoc2
Copy link
Contributor Author

YJDoc2 commented Apr 18, 2025

@AtofStryker , thanks a lot of the fixes, they worked like a charm! Snapshot generation and my tests are both working now. Thanks a lot :)

@jennifer-shehane , so as of the latest commit,

  • yarn check-ts --concurrency=1 is passing without any error on my system
  • two tests I have added in the pr for testing the changes in this PR are passing

Apart from that, anything else I need to do? let me know. Thanks :)

if (!options.videosFolder) throw new Error('Missing videoFolder for recording')

function videoPath (suffix: string) {
return path.join(options.videosFolder, options.spec.relativeToCommonRoot + suffix)
async function videoPath (suffix: string, ext: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might read a bit easier when invoked if the suffix was an optional argument and the last argument of the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed it, so that the suffix is second arg, with a default value, so if nothing is passed it takes '' as default value. That said I'm not sure if this is better or not from before, so can you check once? I have added it as a separate commit, so can be directly reverted if not useful - 07577ed

@AtofStryker AtofStryker self-requested a review April 28, 2025 15:34
Copy link
Contributor

@AtofStryker AtofStryker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this @YJDoc2 !

@jennifer-shehane jennifer-shehane dismissed their stale review April 28, 2025 19:24

dismissing previous review

@jennifer-shehane jennifer-shehane merged commit e8a7c3f into cypress-io:develop Apr 29, 2025
71 checks passed
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 6, 2025

Released in 14.3.3.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v14.3.3, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trashAssetsBeforeRuns=false keeps all versions of screenshots but not of videos
6 participants