{"_id":"cypress-promise","_rev":"5-258283fa4c12027725c9120bc760aab5","name":"cypress-promise","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"cypress-promise","version":"1.0.0","description":"Convert a Cypress chain into a promise for use with async/await","main":"index.js","scripts":{"test":"cypress run"},"repository":{"type":"git","url":"git+https://github.com/NicholasBoll/cypress-promise.git"},"keywords":["cypress","promise","async","await"],"author":{"name":"Nicholas Boll"},"license":"MIT","bugs":{"url":"https://github.com/NicholasBoll/cypress-promise/issues"},"homepage":"https://github.com/NicholasBoll/cypress-promise#readme","devDependencies":{"babel-polyfill":"^6.26.0","cypress":"^2.1.0"},"gitHead":"2ed5cf7e29ed088cebc85509d1291e14fd14941c","_id":"cypress-promise@1.0.0","_npmVersion":"5.7.1","_nodeVersion":"9.4.0","_npmUser":{"name":"nicholasboll","email":"nicholas.boll@gmail.com"},"dist":{"integrity":"sha512-LMm0RWP+KPAF2VBa27q5PJ6urXQP2REK61rqsfCPwJ4o+0aQqDfZ/4ZQU0lsQ5H/22lCPjpihfHPhlygPf9b4g==","shasum":"ebaee0fc1352e4f776dc8bd81d8243e95b1fe53b","tarball":"https://registry.npmjs.org/cypress-promise/-/cypress-promise-1.0.0.tgz","fileCount":13,"unpackedSize":46706,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDgcy+lViUG5ZzM/vWlueE7NGaOehI9fSIDwIyNCWwhzwIgEgx+aEiyyBddgNhJ+GFuLcGcT1B6cNSJ81xsfUal5bQ="}]},"maintainers":[{"name":"nicholasboll","email":"nicholas.boll@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cypress-promise_1.0.0_1522556498173_0.5525183186079963"},"_hasShrinkwrap":false},"1.0.1":{"name":"cypress-promise","version":"1.0.1","description":"Convert a Cypress chain into a promise for use with async/await","main":"index.js","scripts":{"test":"cypress run"},"repository":{"type":"git","url":"git+https://github.com/NicholasBoll/cypress-promise.git"},"keywords":["cypress","promise","async","await"],"files":["index.js","index.d.ts","register.js","register.d.ts"],"author":{"name":"Nicholas Boll"},"license":"MIT","bugs":{"url":"https://github.com/NicholasBoll/cypress-promise/issues"},"homepage":"https://github.com/NicholasBoll/cypress-promise#readme","devDependencies":{"babel-polyfill":"^6.26.0","cypress":"^2.1.0"},"gitHead":"e6a0d76b006c85b84cc5537e22768c37cdfa3b68","_id":"cypress-promise@1.0.1","_npmVersion":"5.7.1","_nodeVersion":"9.4.0","_npmUser":{"name":"nicholasboll","email":"nicholas.boll@gmail.com"},"dist":{"integrity":"sha512-eV48fmXtdW/CpMCsleX9pCohVFsN8KWwyCYcKH439u3G2eR3o8+DWDuqnf29BdlujssrIT5c+ZpIJ54pZbgogQ==","shasum":"74361351eed48e24a40f6b372573ded9508d6378","tarball":"https://registry.npmjs.org/cypress-promise/-/cypress-promise-1.0.1.tgz","fileCount":6,"unpackedSize":7383,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCiIkjWuGPcBG6eqoRWv5RtbXSR96+NdBlFWgsIArotwgIhAJaEImdshkkIdx6pFpbe5g9UockE8YBXxb06DA6I07f7"}]},"maintainers":[{"name":"nicholasboll","email":"nicholas.boll@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cypress-promise_1.0.1_1522556742630_0.7785299335310061"},"_hasShrinkwrap":false},"1.0.2":{"name":"cypress-promise","version":"1.0.2","description":"Convert a Cypress chain into a promise for use with async/await","main":"index.js","scripts":{"test":"cypress run"},"repository":{"type":"git","url":"git+https://github.com/NicholasBoll/cypress-promise.git"},"keywords":["cypress","promise","async","await"],"files":["index.js","index.d.ts","register.js","register.d.ts"],"author":{"name":"Nicholas Boll"},"license":"MIT","bugs":{"url":"https://github.com/NicholasBoll/cypress-promise/issues"},"homepage":"https://github.com/NicholasBoll/cypress-promise#readme","devDependencies":{"babel-polyfill":"^6.26.0","cypress":"^2.1.0"},"gitHead":"5038d708597ca1ecc45b961dd4ecd70d6b82ece4","_id":"cypress-promise@1.0.2","_npmVersion":"5.7.1","_nodeVersion":"9.4.0","_npmUser":{"name":"nicholasboll","email":"nicholas.boll@gmail.com"},"dist":{"integrity":"sha512-+F10DLa2O/NjPmWtHBq2p73lA6YpkJMJKQHgcMJpVax7tYAB8suP+k7ExYzQ4JornPR1CYpyk3Nd9LvHPnmKOg==","shasum":"68833e896ef665c32191cb028604605015f17c7d","tarball":"https://registry.npmjs.org/cypress-promise/-/cypress-promise-1.0.2.tgz","fileCount":6,"unpackedSize":7069,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGo6T40lTsygC/7bUAWmISBDZ9iRrckwn85psyABNalUAiEApRmyr/oe0GRPuL1CutJpMzT8aHE8CzU+JQB+wXVLy7g="}]},"maintainers":[{"name":"nicholasboll","email":"nicholas.boll@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cypress-promise_1.0.2_1522644856936_0.4499529407358194"},"_hasShrinkwrap":false},"1.1.0":{"name":"cypress-promise","version":"1.1.0","description":"Convert a Cypress chain into a promise for use with async/await","main":"index.js","scripts":{"test":"cypress run"},"repository":{"type":"git","url":"git+https://github.com/NicholasBoll/cypress-promise.git"},"keywords":["cypress","promise","async","await"],"author":{"name":"Nicholas Boll"},"license":"MIT","bugs":{"url":"https://github.com/NicholasBoll/cypress-promise/issues"},"homepage":"https://github.com/NicholasBoll/cypress-promise#readme","devDependencies":{"babel-polyfill":"^6.26.0","cypress":"^4.0.0"},"gitHead":"c0d3f867cf65ce4c68c705bd4ea05bb350835427","_id":"cypress-promise@1.1.0","_nodeVersion":"10.16.3","_npmVersion":"6.9.0","_npmUser":{"name":"nicholasboll","email":"nicholas.boll@gmail.com"},"dist":{"integrity":"sha512-DhIf5PJ/a0iY+Yii6n7Rbwq+9TJxU4pupXYzf9mZd8nPG0AzQrj9i+pqINv4xbI2EV1p+PKW3maCkR7oPG4GrA==","shasum":"f2d66965945fe198431aaf692d5157cea9d47b25","tarball":"https://registry.npmjs.org/cypress-promise/-/cypress-promise-1.1.0.tgz","fileCount":6,"unpackedSize":7274,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeQbBtCRA9TVsSAnZWagAAVCMP+gJ2f/QIug/ekglhgNn1\ndJWkwOLYSoDvow/RiypVSXIGiiDKsZRBSjtwOP9a0SH4VlYJp1EXbzaJpXg5\nrAKuwCrP6iA1XjKK5mlAI7UYI6PDx/0MhvJwK6Yu6Bm0rsJ+e7SpojlWvK+W\n4OM4tqUB0EqyZtZ7fqZ9EHd+jYjPRY1XAqrlpiiHlCF7/p/lEEHwoXyM/lu8\nL5DHJ142dxggPg5ruBLqdgEc+uT5hqYj6CrA7q9JR7bS98Wv7GxfkpNBcYMv\npvjjXhgW0u8mXFyeIrNgnZxuEOL0Jlo1PWJnafQCFhnMAQvzHfSQjp4JPs6l\nGph8RwY3rg7EyW+UUV+ZFWqOu8wirilGXLHTQtM6GuknLHYk9xC8G8TeCW2H\n8K26Lbk6d/rZ88KTaMem5S+D7/VbbyVO0nRYAA0Prc9/6MBl0IY8oEiOTcQz\nuY/nf7tRI9h5be2yND+cBJwCAyxnIsNUaDmlHUewrl2skSd2bNj6GXgCUR/P\noa6Ii3fhUTjJU20ewltaFw0KqbRgbq8AVn6kLemMyNYyDJJPTL+a8vhv8XfR\nE960uxO6oRNYmxV4XGq+Z7eDObe4nl6ivkyj69Lq665pAD+zXSBUG5/gev9B\nuMwZz+llG2GD34DQfFW/q9F+kUY+tqql1siq9h2RRf9AYMwr3cYO7t9/37qD\nnKds\r\n=hKBD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCdw3PUMAR6UDNhsTG672B43nPugjvS3ZSZItPJy+xhowIhAJRkdeBl9g4zISt+nBpO8i8nkriiZ1XC3ZmJMb0pKrFu"}]},"maintainers":[{"name":"nicholasboll","email":"nicholas.boll@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cypress-promise_1.1.0_1581363309341_0.9001770994567584"},"_hasShrinkwrap":false}},"time":{"created":"2018-04-01T04:21:38.173Z","1.0.0":"2018-04-01T04:21:38.291Z","modified":"2022-04-28T02:38:53.816Z","1.0.1":"2018-04-01T04:25:42.743Z","1.0.2":"2018-04-02T04:54:17.042Z","1.1.0":"2020-02-10T19:35:09.531Z"},"maintainers":[{"name":"nicholasboll","email":"nicholas.boll@gmail.com"}],"description":"Convert a Cypress chain into a promise for use with async/await","homepage":"https://github.com/NicholasBoll/cypress-promise#readme","keywords":["cypress","promise","async","await"],"repository":{"type":"git","url":"git+https://github.com/NicholasBoll/cypress-promise.git"},"author":{"name":"Nicholas Boll"},"bugs":{"url":"https://github.com/NicholasBoll/cypress-promise/issues"},"license":"MIT","readme":"# Cypress Promise\n\nThis library promises to convert a Cypress chain into a real promise, which is required to use `async`/`await` in a Cypress test. This library is experimental and doesn't work inside a `before` or `beforeEach` block.\n\n```ts\nimport promisify from 'cypress-promise'\n\nit('should run tests with async/await', async () => {\n  const foo = await promisify(cy.wrap('foo'))\n  const bar = await promisify(cy.wrap('bar'))\n\n  expect(foo).to.equal('foo')\n  expect(bar).to.equal('bar')\n})\n```\n\nAn alternative it to use the 'register' polyfill to add `promisify` method to all Cypress chains. This requires `import 'cypress-promise/register'` in your `cypress/support/index` file:\n\n```ts\nit('should run tests with async/await', async () => {\n  const foo = await cy.wrap('foo').promisify()\n  const bar = await cy.wrap('bar').promisify()\n\n  expect(foo).to.equal('foo')\n  expect(bar).to.equal('bar')\n}\n```\n\nWithout this library and the `promisify` function/method, the expectation of `bar` would fail with `expected undefined to equal 'bar'`\n\n## Why use this library?\nThe question about how to use async/await in Cypress test comes up from time to time in the gitter chat as well as in [GitHub Issue #1417](https://github.com/cypress-io/cypress/issues/1417). Sometimes you needs a value out of a chain and using `.then` just increases the nesting level, decreasing readability:\n\n```ts\ncy.get('.mySelector')\n  .then($el => $el.text())\n  .then(text => {\n    // do some more commands using this text\n    cy.get('.someOtherSelector')\n      .then($el => $el.text())\n      .should('equal', text)\n```\n\n[Aliases](https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html) don't help much in this case - we still have to nest. Ideally you'd want to write the following:\n\n```ts\nconst text = await cy.get('.mySelector').then($el => $el.text())\n\n// do some more commands using this text\ncy.get('.someOtherSelector')\n  .then($el => $el.text())\n  .should('equal', text)\n```\n\nSince [Commands are not Promises](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Not-Promises), that code won't work. This library uses aliases and Cypress life-cycle events to force Cypress to play nicely with Promises:\n\n```ts\nimport promisify from 'cypress-promise'\n\nconst text = await promisify(cy\n  .get('.mySelector')\n  .then($el => $el.text())\n)\n\n// do some more commands using this text\ncy.get('.someOtherSelector')\n  .then($el => $el.text())\n  .should('equal', text)\n```\n\n## Best Practices\nCypress chains are powerful and declarative. [Custom Commands](https://medium.com/@NicholasBoll/cypress-io-scaling-e2e-testing-with-custom-commands-6b72b902aab) can be used to chain functions together that read like a series of steps without much extra syntax. Most Cypress commands work on elements and `await`ing them means all you can really do is `cy.wrap` them again. Only use `await` for non-element subjects that need to be used as inputs for other commands.\n\n```ts\n// very bad\nconst body = await promisify(cy.get('body'))\nbody.click() // This will use jQuery's click instead of Cypress's click, losing the power of Cypress\n\n// bad\nconst el = await promisify(cy.get('.someSelector'))\n// later\ncy.wrap(el).click()\n\n// good - use alias for elements. It makes sense and works with Type definitions\ncy.get('.someSelector').as('someElement')\n// later\ncy.get('@someElement').click()\n\n// good - use awaited promises for values to be used in chains\nconst text = await promisify(cy\n  .get('.someSelector')\n  .then(el => el.text())\n)\ncy.get('.someInput').type(text)\n```\n\n## Caveats\n* `.promisify()` doesn't currently work inside `before` or `beforeEach` blocks. This is tracked by #1\n* Cypress throws a warning about using Promises - on every use.\n* `promisify()` is extra syntax - it can be easy to forget to call it.\n* `.promisify()` will end the chain and return a Promise instead of a Chain, meaning you cannot chain further off of this method. When you think about it, this makes perfect sense, but could trip people up.\n* You can't run Cypress commands inside a Promise's `.then` or `.catch`. Cypress will throw an error. I'm not sure it would make sense even if Cypress allowed it.\n\n## Installation\n```\nnpm install cypress-promise -D\n```\n\nIf you get errors like \"regeneratorRuntime is not defined.\", you'll have to install `babel-polyfill` and add `import 'babel-polyfill'` to your `cypress/support/index`.\n\nIf you want to use the `cy.promisify()`, you'll have to add the following to your `cypress/support/index` file:\n\n```ts\nimport 'cypress-promise/register'\n```\n\n","readmeFilename":"README.md"}