Skip to content
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

Merged
merged 26 commits into from
Apr 12, 2024

Conversation

cacieprins
Copy link
Contributor

@cacieprins cacieprins commented Apr 1, 2024

  • Closes

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:

  • Extracts upload logic from ./modes/record.js to ./cloud/artifacts/upload_artifacts.ts
  • Extracts stdout related logic to ./util/print-run.ts
  • Cleans up type definitions surrounding the necessary data for:
    • Uploading artifacts to Cypress Cloud (IArtifact, defined in ./cloud/artifacts/artifact.ts
    • Reporting artifact upload results to both stdout and Cypress Cloud (ArtifactUploadResult, defined in ./cloud/artifacts/artifact.ts)
  • Prepares this section of the codebase for unit testing
  • Changes the export of cloud/api/index.ts from CommonJS style to ES6 style, to accommodate exported types. This necessitated changing the require 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

- streamlines the main uploadArtifact fn
- extracts artifact specific logic to artifact classes
- fully defines types for upload processing and reporting
@cacieprins cacieprins force-pushed the cacie/refactor/artifact-upload-to-ts branch from 5f4c57d to d67c503 Compare April 1, 2024 14:13
@cacieprins cacieprins changed the title Cacie/refactor/artifact upload to ts refactor: extract artifact upload process from lib/modes/record.js Apr 1, 2024
specAccess?: ReturnType<AppCaptureProtocolInterface['getDbMetadata']>
} | void> {
} | undefined> {
if (!this._protocol || !filePath || !this._db) {
Copy link
Contributor Author

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) => {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

@cacieprins cacieprins Apr 1, 2024

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.

Copy link
Contributor

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?

@cacieprins cacieprins marked this pull request as ready for review April 2, 2024 14:18
Copy link

cypress bot commented Apr 2, 2024

6 flaky tests on run #54881 ↗︎

0 29135 1326 0 Flakiness 6

Details:

Merge branch 'develop' into cacie/refactor/artifact-upload-to-ts
Project: cypress Commit: b02fb6dc55
Status: Passed Duration: 18:31 💡
Started: Apr 10, 2024 9:21 PM Ended: Apr 10, 2024 9:40 PM
Flakiness  top-nav.cy.ts • 1 flaky test • app-e2e

View Output

Test Artifacts
... > dismisses the banner for a specified time Test Replay Screenshots
Flakiness  scaffold-component-testing.cy.ts • 1 flaky test • launchpad-e2e

View Output

Test Artifacts
scaffolding component testing > create-react-app > scaffolds component testing for Create React App v5 project Test Replay Screenshots
Flakiness  commands/net_stubbing.cy.ts • 3 flaky tests • 5x-driver-webkit

View Output

Test Artifacts
network stubbing > intercepting request > can delay and throttle a StaticResponse
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <a href="https://cloud.cypress.io/projects/ypt4pf/runs/54881/overview/82aef647-a9e3-4e23-9c0f-1150c75ec60e?reviewViewBy=FLAKY&utm_source=github&utm_medium=flaky&utm_campaign=view%20test">
        ... > with `resourceType` > can match a proxied image request by resourceType
      </a>
    </td>
    <td>
      
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <a href="https://cloud.cypress.io/projects/ypt4pf/runs/54881/overview/d1e84fa6-b3c6-45a0-b8b1-3bd016514aaf?reviewViewBy=FLAKY&utm_source=github&utm_medium=flaky&utm_campaign=view%20test">
        ... > stops waiting when an xhr request is canceled
      </a>
    </td>
    <td>
      
    </td>
  </tr></table>
Flakiness  commands/waiting.cy.js • 1 flaky test • 5x-driver-webkit

View Output

Test Artifacts
... > errors > throws waiting for the 3rd response
    </td>
  </tr></table>

Review all test suite changes for PR #29240 ↗︎

Copy link
Collaborator

@ryanthemanuel ryanthemanuel left a 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
Copy link
Contributor

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 {
Copy link
Contributor

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'
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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

@cacieprins cacieprins merged commit 79a267c into develop Apr 12, 2024
80 of 82 checks passed
@cacieprins cacieprins deleted the cacie/refactor/artifact-upload-to-ts branch April 12, 2024 13:20
@cacieprins cacieprins restored the cacie/refactor/artifact-upload-to-ts branch April 12, 2024 16:39
@cacieprins cacieprins deleted the cacie/refactor/artifact-upload-to-ts branch April 12, 2024 16:48
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 18, 2024

Released in 13.8.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Apr 18, 2024
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.

4 participants