-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Open
YJDoc2
wants to merge
25
commits into
cypress-io:develop
Choose a base branch
from
YJDoc2:issue-8280
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+291
−143
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
fd492ce
fix: use getPath to prevent video file overwrite
YJDoc2 49e69f1
chore: update changelog
YJDoc2 1709884
test: add system e2e for the retain videos fix
YJDoc2 b7a2224
Merge branch 'develop' into issue-8280
YJDoc2 3a3ce9a
Merge branch 'develop' into issue-8280
jennifer-shehane 4415974
Update cli/CHANGELOG.md
jennifer-shehane d7272b3
merge develop
jennifer-shehane 17a2507
Update types for screenshots to be in util/fs
jennifer-shehane 436569a
Fix changelog entry placement
jennifer-shehane 166da24
fix extension type
jennifer-shehane 8c11c07
more types fixes
jennifer-shehane 9b98960
Merge branch 'develop' into issue-8280
jennifer-shehane 77574d0
Merge branch 'develop' into issue-8280
YJDoc2 a16222b
Merge branch 'develop' into issue-8280
YJDoc2 70daf1d
fix: add required field in getPath call to satisfy ts
YJDoc2 d65ce4c
fix: sync Data interface from develop branch
YJDoc2 a3af41a
fix: update SavedDetails type to better definition
YJDoc2 732d02f
Merge branch 'develop' into issue-8280
jennifer-shehane 2665e62
Merge branch 'develop' into issue-8280
jennifer-shehane 29936c5
Merge branch 'develop' into issue-8280
YJDoc2 1eb8195
Merge branch 'develop' of github.com:cypress-io/cypress into issue-8280
AtofStryker 1ed0dc8
update changelog
AtofStryker 7f513cd
break out type import into unique line to allow mksnapshot to work
AtofStryker 2c64ce5
Merge branch 'develop' into issue-8280
YJDoc2 fe946d0
Merge branch 'develop' into issue-8280
AtofStryker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,7 +13,7 @@ import Reporter from '../reporter' | |||||
import browserUtils from '../browsers' | ||||||
import { openProject } from '../open_project' | ||||||
import * as videoCapture from '../video_capture' | ||||||
import { fs } from '../util/fs' | ||||||
import { fs, getPath } from '../util/fs' | ||||||
import runEvents from '../plugins/run_events' | ||||||
import env from '../util/env' | ||||||
import trash from '../util/trash' | ||||||
|
@@ -23,6 +23,7 @@ import chromePolicyCheck from '../util/chrome_policy_check' | |||||
import type { SpecWithRelativeRoot, SpecFile, TestingType, OpenProjectLaunchOpts, FoundBrowser, BrowserVideoController, VideoRecording, ProcessOptions, ProtocolManagerShape, AutomationCommands } from '@packages/types' | ||||||
import type { Cfg, ProjectBase } from '../project-base' | ||||||
import type { Browser } from '../browsers/types' | ||||||
import type { Data } from '../util/fs' | ||||||
import * as printResults from '../util/print-run' | ||||||
import { telemetry } from '@packages/telemetry' | ||||||
import { CypressRunResult, createPublicBrowser, createPublicConfig, createPublicRunResults, createPublicSpec, createPublicSpecResults } from './results' | ||||||
|
@@ -224,15 +225,31 @@ async function trashAssets (config: Cfg) { | |||||
} | ||||||
} | ||||||
|
||||||
async function startVideoRecording (options: { previous?: VideoRecording, project: Project, spec: SpecWithRelativeRoot, videosFolder: string }): Promise<VideoRecording> { | ||||||
async function startVideoRecording (options: { previous?: VideoRecording, project: Project, spec: SpecWithRelativeRoot, videosFolder: string, overwrite: boolean }): Promise<VideoRecording> { | ||||||
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) { | ||||||
const specPath = options.spec.relativeToCommonRoot + suffix | ||||||
// tslint:disable-next-line | ||||||
const data: Data = { | ||||||
name: specPath, | ||||||
startTime: new Date(), // needed for ts-lint | ||||||
viewport: { | ||||||
width: 0, | ||||||
height: 0, | ||||||
}, | ||||||
specName: '', // this is optional, the getPath will pick up from specPath | ||||||
testFailure: false, // this is only applicable for screenshot, not for video | ||||||
testAttemptIndex: 0, | ||||||
titles: [], | ||||||
} | ||||||
|
||||||
// getPath returns a Promise!!! | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return await getPath(data, ext, options.videosFolder, options.overwrite) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the function is async, we can just return the promise instead of awaiting it
Suggested change
|
||||||
} | ||||||
|
||||||
const videoName = videoPath('.mp4') | ||||||
const compressedVideoName = videoPath('-compressed.mp4') | ||||||
const videoName = await videoPath('', 'mp4') | ||||||
const compressedVideoName = await videoPath('-compressed', 'mp4') | ||||||
|
||||||
const outputDir = path.dirname(videoName) | ||||||
|
||||||
|
@@ -333,6 +350,13 @@ async function compressRecording (options: { quiet: boolean, videoCompression: n | |||||
if (options.videoCompression === false || options.videoCompression === 0) { | ||||||
debug('skipping compression') | ||||||
|
||||||
// the getSafePath used to get the compressedVideoName creates the file | ||||||
// in order to check if the path is safe or not. So here, if the compressed | ||||||
// file exists, we remove it as compression is not enabled | ||||||
if (fs.existsSync(options.processOptions.compressedVideoName)) { | ||||||
await fs.remove(options.processOptions.compressedVideoName) | ||||||
} | ||||||
|
||||||
return | ||||||
} | ||||||
|
||||||
|
@@ -949,7 +973,7 @@ async function runSpec (config, spec: SpecWithRelativeRoot, options: { project: | |||||
async function getVideoRecording () { | ||||||
if (!options.video) return undefined | ||||||
|
||||||
const opts = { project, spec, videosFolder: options.videosFolder } | ||||||
const opts = { project, spec, videosFolder: options.videosFolder, overwrite: options.config.trashAssetsBeforeRuns } | ||||||
|
||||||
telemetry.startSpan({ name: 'video:capture' }) | ||||||
|
||||||
|
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.