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

feat: Retain fileName when working with aliased fixtures and files #19820

Merged
merged 2 commits into from
Jan 25, 2022

Conversation

BlueWinds
Copy link
Contributor

@BlueWinds BlueWinds commented Jan 21, 2022

User facing changelog

selectFile() now retains the filename of files ready from disk when working with aliases.

Additional details

cy.fixture('example.json', { encoding: null }).as('exampleFile')
cy.get('input[type="file"]').selectFile('@exampleFile')

The input will have a filename of 'example.json', with the mimeType inferred from that. The filename and mimetype can still be specified manually.

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • [N/A] Have API changes been updated in the type definitions?
  • [N/A] Have new configuration options been added to the cypress.schema.json?

@BlueWinds BlueWinds requested a review from a team as a code owner January 21, 2022 18:32
@BlueWinds BlueWinds requested review from jennifer-shehane and removed request for a team January 21, 2022 18:32
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 21, 2022

Thanks for taking the time to open a PR!

@BlueWinds BlueWinds changed the title Retain fileName when working with aliased fixtures and files feat: Retain fileName when working with aliased fixtures and files Jan 21, 2022
@BlueWinds BlueWinds requested review from AtofStryker, cowboy and tbiethman and removed request for jennifer-shehane January 21, 2022 18:33
})
})

it('allows users to override the inferred filenames and mimetypes', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would make a really great example in the docs! (I don't know if you were going to do that or not)

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 is fairly similar to one of the existing examples:

https://github.com/cypress-io/cypress-documentation/blob/a07bac295906cdadff5241cc907603eded52c545/content/api/commands/selectfile.md#selecting-a-file-with-custom-filename-mimetype-and-lastmodified

For the docs examples, I tried to break them up a bit more, demonstrate one feature at a time; one example shows how to use an alias, another how to use a path, another haw to override fileName and mimeType. I could do one big "all the features at once" example though, if that seems like it would be helpful.

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 don't really have any examples around 'how to work with file inputs (eg, input.files[1].name, input.files[0].type) though, which might be what you're referring to? It wouldn't be bad to have - that's not Cypress functionality, it's just how browsers work, but no reason not to include a couple of example lines to help people get started.

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually really liked the combination of things, including doing a multiple-select with files specified inline, especially with one of those being an alias with overrides. It seemed like the "perfect storm" of API interactions :D

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't even thinking about the DOM API side of things, just the .selectFile() API here.

cowboy
cowboy previously approved these changes Jan 21, 2022
Copy link
Contributor

@cowboy cowboy left a comment

Choose a reason for hiding this comment

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

I'm not super familiar with the underpinnings, but the tests LGTM

@cypress
Copy link

cypress bot commented Jan 21, 2022



Test summary

19145 0 218 0Flakiness 1


Run details

Project cypress
Status Passed
Commit f63807b
Started Jan 24, 2022 10:57 PM
Ended Jan 24, 2022 11:09 PM
Duration 11:30 💡
OS Linux Debian - 10.10
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

cypress/integration/commands/net_stubbing_spec.ts Flakiness
1 network stubbing > waiting and aliasing > can timeout waiting on a single request using "alias.request"

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

AtofStryker
AtofStryker previously approved these changes Jan 21, 2022
@@ -78,6 +79,9 @@ export default (Commands, Cypress, cy) => {
contents = Buffer.from(contents)
}

// Add the filename as a symbol, in case we need it later (such as when storing an alias)
state('current').attributes.fileName = basename(filePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

The Command class has a getter/setter for attributes that you could use: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cypress/command.ts#L15

The attributes property is initialized by the constructor though, so I don't think it's absolutely necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed over.

tbiethman
tbiethman previously approved these changes Jan 22, 2022
@BlueWinds
Copy link
Contributor Author

Only change since three green checks were minor formatting changes, all tests still passed.

tgriesser added a commit that referenced this pull request Jan 28, 2022
* develop:
  fix: correct reference branch / commitSha in performance-reporter (#19941)
  test: Honeycomb system-test reporter (#19855)
  fix(deps): update dependency engine.io to v5.2.1 [security]
  feat: Retain fileName when working with aliased fixtures and files (#19820)
  Update release-process.md
  Update release-process.md
  Update release-process.md
  Update release-process.md
  Update release-process.md
  Update release-process.md
  Phrasing
  Updating release guide with findings from 9.3.0 release snafu
  add link to the video how to report Cypress bug
tgriesser added a commit that referenced this pull request Jan 31, 2022
* 10.0-release: (25 commits)
  fix(unify): improve dev server config ergonomics (#19957)
  feat: add spec pattern modal (#19801)
  fix: Windows e2e project scaffolding issues (#19938)
  feat: update @cypress/schematic to use proper e2e config for 10.0.0 (#19827)
  fix: correctly migrate projects with custom integration folder (#19929)
  fix: component spec creation with spec pattern (#19862)
  fix: missed committing yarn.lock after merge conflict
  fix: correct reference branch / commitSha in performance-reporter (#19941)
  feat: update navbar UI per Figma (#19926)
  fix: seed examples files when no e2e directory is created (#19768)
  chore: remove windy lightBlue warning
  test: component test updates (#19925)
  feat: Focus browser from select browser screen and on dashboard login (#19842)
  test: Honeycomb system-test reporter (#19855)
  fix(deps): update dependency engine.io to v5.2.1 [security]
  feat: Retain fileName when working with aliased fixtures and files (#19820)
  Update release-process.md
  Update release-process.md
  Update release-process.md
  Update release-process.md
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The .selectFile command does not work from an aliased fixture
4 participants