question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: .pipe command that is essentially a retryable .then

See original GitHub issue

Proposal: Command that is essentially a retryable .then

Example:

const getTable = id => cy.get(`[data-testid=${id}`)
const getColumnNames = $el => Array.from($el.find('[role=columnheader]')).map(el => el.innerText)

getTable('identifier')
  .then(getColumnNames) // The `should` doesn't cause this to re-evaluate
  .should('deep.equal', ['Column One', 'Column Two'])

The getTable will get an element given a test id and getColumnNames will get the text contents of a table’s column headers. If the table’s column headers aren’t statically known (maybe column order is a user preference), the assertion immediately fails.

I don’t think we want .then to retry. I think it is good that .then has strong guarantees that it will only be run once. It just makes composition of functions not quite fit.

There could be another command that does re-run if there is an assertion:

getTable('identifier')
  .pipe(getColumnNames) // The `should` would cause re-evaluation
  .should('deep.equal', ['Column One', 'Column Two'])

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
bahmutovcommented, Oct 23, 2018

You know - you work and then this guy comes in like it’s Christmas and just drops presents! Love it

Sent from my iPhone

On Oct 24, 2018, at 00:54, Nicholas Boll notifications@github.com wrote:

I’ve updated cypress-pipe after adding some nice features for debugging: https://github.com/NicholasBoll/cypress-pipe

Highlights:

Basically a drop-in for .then to chain helper functions together Adds helper function name to the command log to help map test code to command log output For functions containing Cypress commands Adds before and after DOM snapshots, similar to “action” style commands like cy.click() Adds Element highlights for before and after snapshots For pure functions (no Cypress commands) retries until there is no error if an element list is returned, it will retry until the list is not empty if .pipe is chained by a should, the assertion will retry until condition is met or times out adds a DOM snapshot if either passed in subject or returned value is an Element We’ve been using it for a while on our large SPA and it really helps compose functionality. It has helped both writing tests, but also debugging them when something goes wrong.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

0reactions
NicholasBollcommented, Nov 20, 2018

I will add a PR to the plugins and close this PR. pipe can be fully implemented in user space.

If later the Cypress team thinks it is valuable enough, pipe could be integrated into the core.

Thanks for the feedback!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Piping in Unix or Linux - GeeksforGeeks
Pipe is used to combine two or more commands, and in this, the output of one command acts as input to another command,...
Read more >
bash - How can I use a file in a command and redirect output ...
The reason why you can't do that: bash processes the redirections first, then executes the command. So by the time grep looks at...
Read more >
Assignment Two
In this example code, thePipe[0] is a file pointer (an index into the process's open file table) to the read end of the...
Read more >
How do I write a retry logic in script to keep retrying to run it ...
for i in 1 2 3 4 5; do command && break || sleep 15; done. Replace "command" with your command. This is...
Read more >
A proposal for a Linux SuperCommand set - Ubuntu Discourse
What I am proposing essentially is an extension of the existing Linux ... What if I created a superset of commands (now using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found