You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
while integrating Cypress version 12.15.0 some of our tests failed with PayloadTooLargeError: request entity too large. The problematic test cases write files around 200 - 300 kb. Cypress UI shows the error message cy.writeFile() must only be invoked from the spec or support file
We're aware of the "must only be invoked from the spec file or support file" issue and are looking into it now. Until a fix is identified, tested, and released you can temporarily downgrade to Cypress v12.14.0 which does not exhibit this issue.
Hi @bdimitrovski , sorry you're still having issues. We addressed an issue that was causing this error in 12.16.0 but it appears you've identified one or more edge cases we missed. Are you able to share a reproduction case we can use to troubleshoot?
Here's the repro code https://github.com/bdimitrovski/writefile-cy-issue, however, when I used the exact same function as in my real project, I could not get it to fail, it normally populates the file using cy.writeFile.
Here's the repro code bdimitrovski/writefile-cy-issue, however, when I used the exact same function as in my real project, I could not get it to fail, it normally populates the file using cy.writeFile.
Is there anything else I could be missing?
@bdimitrovski It's tricky to say, since that's the information we'd be trying to use the reproduction to suss out. It could be something different with how the project is structured, as in which file the function that calls cy.writeFile is defined. It could a difference in how the spec code is calling it. It could be useful if you posted your cypress.config.js or as much of it as you can.
There's two known issues that cause this error right now (and are in the process of being fixed), so I would first check to see if your project code is encountering it because of one of these:
The command is called with an extra argument that isn't part of its API, as in cy.writeFile('file.txt', 'contents', 'utf-8', { log: false }, { flag: 'w' }). In that case, the { flag: 'w' } object should be part of the { log: false } object.
The command is called with a trailing undefined argument. This usually happens when one of the arguments is a variable, like:
Here's the repro code bdimitrovski/writefile-cy-issue, however, when I used the exact same function as in my real project, I could not get it to fail, it normally populates the file using cy.writeFile.
Is there anything else I could be missing?
@bdimitrovski It's tricky to say, since that's the information we'd be trying to use the reproduction to suss out. It could be something different with how the project is structured, as in which file the function that calls cy.writeFile is defined. It could a difference in how the spec code is calling it. It could be useful if you posted your cypress.config.js or as much of it as you can.
There's two known issues that cause this error right now (and are in the process of being fixed), so I would first check to see if your project code is encountering it because of one of these:
The command is called with an extra argument that isn't part of its API, as in cy.writeFile('file.txt', 'contents', 'utf-8', { log: false }, { flag: 'w' }). In that case, the { flag: 'w' } object should be part of the { log: false } object.
The command is called with a trailing undefined argument. This usually happens when one of the arguments is a variable, like:
We're aware of the "must only be invoked from the spec file or support file" issue and are looking into it now. Until a fix is identified, tested, and released you can temporarily downgrade to Cypress v12.14.0 which does not exhibit this issue.
Can I please know the way to downgrade the version? TIA
npx cypress run --spec ./docs/commands/files.md,./docs/recipes/collect-headings.md
Running: commands/files.md (1 of 2)
Files
✓ cy.fixture() - load a fixture (767ms)
- cy.fixture() or require - load a fixture
✓ cy.readFile() - read file contents (75ms)
1) cy.writeFile() - write to a file
2) cy.writeFile() - write combined JSON object
3) cy.writeFile() - write combined JSON array
2 passing (3s)
1 pending
3 failing
1) Files
cy.writeFile() - write to a file:
CypressError: `cy.writeFile()` must only be invoked from the spec file or support file.
at <unknown> (http://localhost:65471/__cypress/runner/cypress_runner.js:146497:87)
at tryCatcher (http://localhost:65471/__cypress/runner/cypress_runner.js:18744:23)
at Promise._settlePromiseFromHandler (http://localhost:65471/__cypress/runner/cypress_runner.js:16679:31)
at Promise._settlePromise (http://localhost:65471/__cypress/runner/cypress_runner.js:16736:18)
at Promise._settlePromise0 (http://localhost:65471/__cypress/runner/cypress_runner.js:16781:10)
at Promise._settlePromises (http://localhost:65471/__cypress/runner/cypress_runner.js:16857:18)
at _drainQueueStep (http://localhost:65471/__cypress/runner/cypress_runner.js:13451:12)
at _drainQueue (http://localhost:65471/__cypress/runner/cypress_runner.js:13444:9)
at ../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:65471/__cypress/runner/cypress_runner.js:13460:5)
at Async.drainQueues (http://localhost:65471/__cypress/runner/cypress_runner.js:13330:14)
From Your Spec Code:
at Context.eval (http://localhost:65471/__cypress/tests?p=docs/commands/files.md)
Activity
dubzzz commentedon Jun 21, 2023
I encounter exactly the same issue when bumping to 12.15.0 on Node 18.
ddnexus commentedon Jun 21, 2023
Same error with version 12.15.0 (working fine with 12.14.0) but a different origin, probably related to the size of the snapshot file:
[-]cy.writeFiles [/-][+]cy.writeFiles runs into errors[/+]gabor-szallas commentedon Jun 21, 2023
Same error, but with cy.readFile() after updating to 12.15.0
cy.readFile() must only be invoked from the spec file or support file.mike-plummer commentedon Jun 21, 2023
We're aware of the "must only be invoked from the spec file or support file" issue and are looking into it now. Until a fix is identified, tested, and released you can temporarily downgrade to Cypress v12.14.0 which does not exhibit this issue.
mike-plummer commentedon Jun 21, 2023
This is a duplicate of #27099 which has a slightly more targeted description of the issue so I will close this in favor of that one
arundavid1987 commentedon Jun 22, 2023
mike-plummer commentedon Jun 26, 2023
Cypress v12.16.0 has just been released with a fix for the issue with cy.task, apologies for the oversight on that bug.
Thanks for using Cypress, everyone!
bdimitrovski commentedon Jun 27, 2023
This is still not resolved, as we are also getting the same error:
The bespoke code resides in a custom class, which implements the
cy.writeFile()function like so:cy.writeFile('cypress/support/data/paymentOrders/groupOrders.json', data);Is there a workaround for this, or is downgrading to 12.14.0 the only option?
mike-plummer commentedon Jun 27, 2023
Hi @bdimitrovski , sorry you're still having issues. We addressed an issue that was causing this error in 12.16.0 but it appears you've identified one or more edge cases we missed. Are you able to share a reproduction case we can use to troubleshoot?
bdimitrovski commentedon Jun 27, 2023
Hi @mike-plummer ,
Thanks for the quick reply.
Here's the repro code https://github.com/bdimitrovski/writefile-cy-issue, however, when I used the exact same function as in my real project, I could not get it to fail, it normally populates the file using
cy.writeFile.Is there anything else I could be missing?
elGatoMantocko commentedon Jun 27, 2023
Still able to reproduce #27099 via
cypress-localstorage-commands.#27099 (comment)
chrisbreiding commentedon Jun 28, 2023
@elGatoMantocko Thanks for the report. That will be helpful for debugging.
chrisbreiding commentedon Jun 28, 2023
@bdimitrovski It's tricky to say, since that's the information we'd be trying to use the reproduction to suss out. It could be something different with how the project is structured, as in which file the function that calls
cy.writeFileis defined. It could a difference in how the spec code is calling it. It could be useful if you posted yourcypress.config.jsor as much of it as you can.There's two known issues that cause this error right now (and are in the process of being fixed), so I would first check to see if your project code is encountering it because of one of these:
cy.writeFile('file.txt', 'contents', 'utf-8', { log: false }, { flag: 'w' }). In that case, the{ flag: 'w' }object should be part of the{ log: false }object.undefinedargument. This usually happens when one of the arguments is a variable, like:Jacek-fstack commentedon Jun 30, 2023
I have the same issue - only showing up in headless mode
example:
inside of the spec file
bdimitrovski commentedon Jun 30, 2023
@chrisbreiding thanks for looking into this - here' a part of my
cypress.config.jsfile:I do not see anything outstanding here that could cause issues with
cy.writeFile()inside some custom class though.rashmiranjanbhoi commentedon Jul 3, 2023
I have the same issue - only showing up in headless mode in Cypress version 12.16.0
Note :- This is inconsistent; occasionally it succeeds, occasionally it fails.
bimanpathirage commentedon Jul 5, 2023
Can I please know the way to downgrade the version? TIA
MikeMcC399 commentedon Jul 5, 2023
@bimanpathirage
If you are using npm, then simply
For Yarn
bahmutov commentedon Jul 6, 2023
Reproducible example (still fails with 12.17.0) in bahmutov/cypress-examples#174
Can be seen in branch
12.16chrisbreiding commentedon Jul 7, 2023
Thanks for the repro, @bahmutov! That's a new edge case and being able to reproduce it will help a lot in debugging it.
cypress-bot commentedon Jul 20, 2023
Released in
12.17.2.This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.17.2, please open a new issue.