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

Update cy.origin dependencies / remove Cypress.require() #4789

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions content/_data/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -985,10 +985,6 @@
"title": "platform",
"slug": "platform"
},
{
"title": "require",
"slug": "require"
},
{
"title": "session",
"slug": "session"
Expand Down
38 changes: 24 additions & 14 deletions content/api/commands/origin.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,27 +507,37 @@ into the callback.

### Dependencies / Sharing Code

It is not possible to use
[ES module dynamic `import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports)
and/or
[CommonJS `require()`](https://nodejs.org/en/knowledge/getting-started/what-is-require/)
or
[dynamic ES module `import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports)
within the callback. However, [`Cypress.require()`](/api/cypress-api/require)
can be utilized to include [npm](https://www.npmjs.com/) packages and other
files. It is functionally the same as using
[CommonJS `require()`](https://nodejs.org/en/knowledge/getting-started/what-is-require/)
in browser-targeted code.
can be used within the callback to include [npm](https://www.npmjs.com/)
packages and other files.

If you utilize a custom preprocessor, note that this feature requires the latest
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest calling out the actual version, e.g. requires version 5.14.0 or greater

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'm more inclined to do that here than in the code, since it can be changed at will if something goes wrong with the package release. It should get released once the code PR is in develop, so I'll update this with the version then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 42354f2

chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved
version of
[`@cypress/webpack-preprocessor`](https://github.com/cypress-io/cypress/tree/master/npm/webpack-preprocessor)
to work.

```js
// ES modules
cy.origin('somesite.com', async () => {
const _ = await import('lodash')
const utils = await import('../support/utils')

// ... use lodash and utils ...
})

// CommonJS
cy.origin('somesite.com', () => {
const _ = Cypress.require('lodash')
const utils = Cypress.require('../support/utils')
const _ = require('lodash')
const utils = require('../support/utils')

// ... use lodash and utils ...
})
```

`Cypress.require()` can be used to share custom commands between tests run in
primary and secondary origins. We recommend this pattern for setting up your
This makes it possible to share custom commands between tests run in primary and
secondary origins. We recommend this pattern for setting up your
[support file](/guides/core-concepts/writing-and-organizing-tests#Support-file)
and setting up custom commands to run within the `cy.origin()` callback:

Expand Down Expand Up @@ -561,7 +571,7 @@ before(() => {
// calls in this spec. put it in your support file to make them available to
// all specs
cy.origin('somesite.com', () => {
Cypress.require('../support/commands')
require('../support/commands')
})
})

Expand All @@ -582,7 +592,7 @@ before(() => {
cy.origin('somesite.com', () => {
// makes commands defined in this file available to all callbacks
// for somesite.com
Cypress.require('../support/commands')
require('../support/commands')
})
})

Expand Down
77 changes: 0 additions & 77 deletions content/api/cypress-api/require.md

This file was deleted.

1 change: 0 additions & 1 deletion cypress/fixtures/sidebar-overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"/api/cypress-api/iscy": "Cypress.isCy",
"/api/cypress-api/cypress-log": "Cypress.log",
"/api/cypress-api/platform": "Cypress.platform",
"/api/cypress-api/require": "Cypress.require",
"/api/cypress-api/spec": "Cypress.spec",
"/api/cypress-api/session": "Cypress.session",
"/api/cypress-api/testing-type": "Cypress.testingType",
Expand Down