-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
refactor: extract artifact upload process from lib/modes/record.js #29240
Conversation
- streamlines the main uploadArtifact fn - extracts artifact specific logic to artifact classes - fully defines types for upload processing and reporting
5f4c57d
to
d67c503
Compare
specAccess?: ReturnType<AppCaptureProtocolInterface['getDbMetadata']> | ||
} | void> { | ||
} | undefined> { | ||
if (!this._protocol || !filePath || !this._db) { |
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 codepath will probably go away with improved error messaging - should never get to this point from upload_artifacts if there is no capture artifact to upload
const rp = require('@cypress/request-promise') | ||
const { fs } = require('../../util/fs') | ||
|
||
export const sendFile = (filePath: string, uploadUrl: string) => { |
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.
The only major change for this file other than renaming & moving was to change the export to a named export, rather than an assigned export object
// Potential todos: Refactor to named exports, refactor away from `this.` in exports, | ||
// move individual exports to their own files & convert this to barrelfile | ||
|
||
export default { |
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.
Since being able to export types was fairly important here, the main export had to change. Since several methods on this export reference other exported methods via this
, this is only an intermediary step. Extracting these methods to their own files is out of scope for this refactor.
This export changing had the knock-on effect of requiring downstream JS consumers to change their require to ('/api').default
.
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.
should we make issues for the todo comments here for the future?
…throw if errors are encountered
6 flaky tests on run #54881 ↗︎
Details:
top-nav.cy.ts • 1 flaky test • app-e2e
scaffold-component-testing.cy.ts • 1 flaky test • launchpad-e2e
commands/net_stubbing.cy.ts • 3 flaky tests • 5x-driver-webkit
|
…accessor in protocol fatal error report
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.
A few minor tweaks, but overall this looks good. A nice shift for part of the code base in the right direction.
@@ -58,6 +58,7 @@ export interface CypressRequestOptions extends OptionsWithUrl { | |||
cacheable?: boolean | |||
} | |||
|
|||
// TODO: migrate to fetch from @cypress/request |
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.
Do we have an issue for this?
// Potential todos: Refactor to named exports, refactor away from `this.` in exports, | ||
// move individual exports to their own files & convert this to barrelfile | ||
|
||
export default { |
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.
should we make issues for the todo comments here for the future?
} | ||
|
||
export interface IArtifact { | ||
reportKey: 'video' | 'screenshots' | 'protocol' |
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.
we could refactor this to an enum and reference the enum strings in Artifact
constructor but I don't think its necessary. For readability though I would love if the reportkey enum strings were in the same order here as in the Artifact class
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.
If only ts enums were actually typesafe - I may convert to a more typesafe object with keyof type
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.
probs the object with typesafefy vs an actual ts enum is better
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Additional details
Previously, almost all of artifact uploading logic was handled in a single js file.
This refactor to gain the benefits of Typescript, within the server package:
./modes/record.js
to./cloud/artifacts/upload_artifacts.ts
./util/print-run.ts
IArtifact
, defined in./cloud/artifacts/artifact.ts
ArtifactUploadResult
, defined in./cloud/artifacts/artifact.ts
)cloud/api/index.ts
from CommonJS style to ES6 style, to accommodate exported types. This necessitated changing therequire
declaration in several JS files to reference.default
.Previously, this section of code was only tested via system tests. This PR does not reduce test coverage, and prepares this section of code for unit testing in the future.
Steps to test
Run cypress in record mode, in a project with test replay enabled.
How has the user experience changed?
It should not change.
PR Tasks
cypress-documentation
?type definitions
?