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

fix: Fix issue with undefined or extra args passed to privileged commands #27157

Merged
merged 6 commits into from
Jun 28, 2023

Conversation

chrisbreiding
Copy link
Contributor

@chrisbreiding chrisbreiding commented Jun 28, 2023

Additional details

Fixes the following two issues that erroneously cause the <command> must only be invoked from the spec file or support file error:

  1. Command is called with an extra argument that isn't part of its API.

    cy.task('someTask', 'arg', { log: false }, { timeout: 10000 })

Privileged command arguments are collected on invocation generically, with no knowledge of how many arguments are valid. However, each command implementation would only send known arguments when it's run, making the argument comparison falsely fail. The solution is for the implementations to send all arguments, even if they're not used by the command.

  1. Command is called with a trailing undefined argument. This usually happens when one of the arguments is a variable.

    function writeFile (options) {
      cy.writeFile('file.txt', 'contents', options)
    }
    
    writeFile()

This was a bug in how trailing undefined arguments were being trimmed. Before, they were trimmed after being serialized, which never worked since any undefined values became strings. There was an issue with the test for that case. The implementation has been fixed and the test has been improved.

PR Tasks

@chrisbreiding chrisbreiding changed the title fix: Fix issue with undefined/extra args passed to privileged commands fix: Fix issue with undefined or extra args passed to privileged commands Jun 28, 2023
})

it('handles extra, unexpected arguments', () => {
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// @ts-ignore
// @ts-expect-error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. I always forget to use that instead of ts-ignore. Addressed in 45a6abc

@cypress
Copy link

cypress bot commented Jun 28, 2023

Passing run #48344 ↗︎

0 214 20 0 Flakiness 0

Details:

fix test
Project: cypress Commit: 1054b33328
Status: Passed Duration: 10:03 💡
Started: Jun 28, 2023 3:22 PM Ended: Jun 28, 2023 3:32 PM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@chrisbreiding chrisbreiding merged commit eea99ae into develop Jun 28, 2023
@chrisbreiding chrisbreiding deleted the issue-27097-privileged-command-issues branch June 28, 2023 15:45
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 6, 2023

Released in 12.17.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jul 6, 2023
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.

Resurfacing of command 'must only be invoked from the spec file or support file.'
3 participants