Skip to content

Commit f0fa22d

Browse files
chrisbreidingemilyrohrboughmjhenkeslmiller1990jaffrepaul
authored
10.9.0 Release (#4747)
Co-authored-by: Emily Rohrbough <[email protected]> Co-authored-by: Chris Breiding <[email protected]> Co-authored-by: Matt Henkes <[email protected]> Co-authored-by: Lachlan Miller <[email protected]> Co-authored-by: Paul Jaffre <[email protected]> Co-authored-by: Adam Murray <[email protected]> Co-authored-by: Adam Murray <[email protected]> Co-authored-by: Ryan Duffy <[email protected]>
1 parent b9570c3 commit f0fa22d

File tree

10 files changed

+387
-55
lines changed

10 files changed

+387
-55
lines changed
10.7 KB
Loading

content/_changelogs/10.8.0.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ _Released 9/13/2022_
1010
[`playwright-webkit`](https://www.npmjs.com/package/playwright-webkit). For
1111
more details, read
1212
[our blog post](https://www.cypress.io/blog/2022/09/13/cypress-10-8-experimental-run-tests-in-webkit).
13-
Addressed [#17336](https://github.com/cypress-io/cypress/issues/6422).
13+
Addresses [#6422](https://github.com/cypress-io/cypress/issues/6422).
1414

1515
**Performance:**
1616

@@ -36,7 +36,7 @@ _Released 9/13/2022_
3636
- Fixed a bug where projects using Node.js 16.17+ and 18.6+ with ES Modules and
3737
TypeScript were not working with Cypress. Fixes
3838
[#22795](https://github.com/cypress-io/cypress/issues/22795),
39-
[#23393](https://github.com/cypress-io/cypress/issues/23393) and
39+
[#23393](https://github.com/cypress-io/cypress/issues/23393), and
4040
[#23552](https://github.com/cypress-io/cypress/issues/23552).
4141
- When searching for specs we now normalize OS-specific path separators so that
4242
Windows users can use back- and forward-slashes. Fixes
@@ -58,7 +58,7 @@ _Released 9/13/2022_
5858
[#23357](https://github.com/cypress-io/cypress/issues/23357).
5959
- Fixed a regression introduced in Cypress [10.0.0](#10-0-0) where Cypress was
6060
incompatible with Chrome v64 - v70. Fixes
61-
[#23509](https://github.com/cypress-io/cypress/issues/23644).
61+
[#23509](https://github.com/cypress-io/cypress/issues/23509).
6262
- Fixes an issue where outdated organization and project information could be
6363
shown in dialogs when connecting a project to the Cypress Dashboard. Fixes
6464
[#23538](https://github.com/cypress-io/cypress/issues/23538).

content/_changelogs/10.9.0.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## 10.9.0
2+
3+
_Released 9/27/2022_
4+
5+
**Features:**
6+
7+
- Added support for requiring dependencies within the
8+
[`cy.origin()`](/api/commands/origin) callback. See the
9+
[`Cypress.require()`](/api/cypress-api/require) and
10+
[`cy.origin()`](/api/commands/origin#Dependencies-Sharing-Code) docs for more
11+
information.
12+
- Added support for visiting cross-origin pages outside of a
13+
[`cy.origin()`](/api/commands/origin) callback. See the
14+
[`cy.origin()`](/api/commands/origin#Alternative-navigation) and
15+
[`cy.visit()`](/api/commands/visit#Visiting-cross-origin-sites) docs for more
16+
information and caveats. Addresses
17+
[#21485](https://github.com/cypress-io/cypress/issues/21485),
18+
[#22282](https://github.com/cypress-io/cypress/issues/22282),
19+
[#21300](https://github.com/cypress-io/cypress/issues/21300), and
20+
[#23236](https://github.com/cypress-io/cypress/issues/23236).
21+
- Added support for re-using session data cached by
22+
[`cy.session()`](/api/commands/session) across specs via the
23+
`cacheAcrossSpecs` option. Addresses
24+
[#17710](https://github.com/cypress-io/cypress/issues/17710).
25+
- Added support for advanced dev server configuration via an async function that
26+
can optionally modify the dev server config. Addresses
27+
[#23302](https://github.com/cypress-io/cypress/issues/23302).
28+
- Launch options returned from the
29+
[`before:browser:launch`](/api/plugins/browser-launch-api) event can now
30+
include an `env` key that can be used to pass environment variables to the
31+
browser when it is launched. Addressed by
32+
[#23624](https://github.com/cypress-io/cypress/pull/23624).
33+
- Component tests that fail now display a code frame of the source location of
34+
the error within the Cypress reporter. Addresses
35+
[#21720](https://github.com/cypress-io/cypress/issues/21720).
36+
37+
**Bugfixes:**
38+
39+
- The spec results printed stdout after a test run now show the path to the spec
40+
and not just the file name. Fixes
41+
[#22304](https://github.com/cypress-io/cypress/issues/22304).
42+
- The viewport dropdown in the Cypress App now displays the correct text. Fixes
43+
[#23789](https://github.com/cypress-io/cypress/issues/23789).
44+
- Compile errors are now surfaced in the command log during tests for Angular
45+
and Next projects. Fixes
46+
[#23219](https://github.com/cypress-io/cypress/issues/23219).
47+
- The error "Automatic publicPath is not supported in this browser" will no
48+
longer be displayed when using Webpack 5 and dynamic imports. Fixes
49+
[#18435](https://github.com/cypress-io/cypress/issues/18435).
50+
- The correct source control link is now sent to the Cypress Dashboard for
51+
failed specs when the cypress config file is not the project root. Fixes
52+
[#22971](https://github.com/cypress-io/cypress/issues/22971).
53+
- The error "Invalid left-hand-side in assignment" will no longer be thrown when
54+
the `experimentalModifyObstructiveThirdPartyCode` flag is enabled. Fixes
55+
[#23647](https://github.com/cypress-io/cypress/issues/23647).
56+
- `it.skip` now functions correctly in Angular component tests. Fixes
57+
[#23409](https://github.com/cypress-io/cypress/issues/23409).
58+
- The `tsConfig` build option is now respected for Angular component tests.
59+
Fixes [#23673](https://github.com/cypress-io/cypress/issues/23673).
60+
- Configuring a custom browser no longer logs a warning when trying to use that
61+
browser. Addressed in
62+
[#23446](https://github.com/cypress-io/cypress/pull/23446).
63+
64+
**Misc:**
65+
66+
- Improved the accessibility of a few components within the Cypress Launchpad
67+
and App. Addressed in
68+
[#23745](https://github.com/cypress-io/cypress/pull/23745).
69+
- Improved the UI of the Sessions instrument panel in the Cypress reporter.
70+
Addresses [#21400](https://github.com/cypress-io/cypress/issues/21400).

content/_data/sidebar.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,10 @@
985985
"title": "platform",
986986
"slug": "platform"
987987
},
988+
{
989+
"title": "require",
990+
"slug": "require"
991+
},
988992
{
989993
"title": "session",
990994
"slug": "session"

content/api/commands/origin.md

Lines changed: 140 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ Enabling this flag does the following:
3333
- It supersedes
3434
the [`Cypress.Cookies.preserveOnce()`](/api/cypress-api/cookies#Preserve-Once) and
3535
[`Cypress.Cookies.defaults()`](/api/cypress-api/cookies#Defaults) methods.
36-
- Cross-origin requests will no longer fail immediately, but instead, time out
37-
based on [`pageLoadTimeout`](/guides/references/configuration#Timeouts).
38-
- Tests will no longer wait on page loads before moving on to the next test.
36+
- Cross-origin requests will now succeed, however, to interact with a
37+
cross-origin page you must use a `cy.origin` block.
3938

4039
Because the page is cleared before each
4140
test, [`cy.visit()`](/api/commands/visit) must be explicitly called in each test
@@ -91,10 +90,11 @@ cy.get('h1').contains('My cool site under test')
9190

9291
```js
9392
const hits = getHits()
94-
// cy.visit() should be inside cy.origin() callback
9593
cy.visit('https://www.acme.com/history/founder')
94+
// to interact with cross-origin content, move this inside cy.origin() callback
95+
cy.get('h1').contains('About our Founder, Marvin Acme')
9696
cy.origin('https://www.acme.com', () => {
97-
// Fails because origin was visited before cy.origin() block
97+
cy.visit('/history/founder')
9898
cy.get('h1').contains('About our Founder, Marvin Acme')
9999
// Fails because hits is not passed in via args
100100
cy.get('#hitcounter').contains(hits)
@@ -214,9 +214,10 @@ cy.origin('https://www.acme.com', () => {
214214

215215
### Navigating to secondary origin with cy.visit
216216

217-
When navigating to a secondary origin using `cy.visit()`, it is essential to
218-
trigger the navigation **after** entering the origin callback, otherwise a
219-
cross-origin error will be thrown.
217+
When navigating to a secondary origin using `cy.visit()`, you can either
218+
navigate prior to or after the `cy.origin` block. Errors are no longer thrown on
219+
cross-origin navigation, but instead when commands interact with a cross-origin
220+
page.
220221

221222
```js
222223
// Do things in primary origin...
@@ -233,11 +234,42 @@ and the protocol defaults to `https`. When `cy.visit()` is called with the path
233234
`/history/founder`, the three are concatenated to make
234235
`https://www.acme.com/history/founder`.
235236

237+
#### Alternative navigation
238+
239+
```js
240+
// Do things in primary origin...
241+
242+
cy.visit('https://www.acme.com/history/founder')
243+
244+
// The cy.origin block is required to interact with the cross-origin page.
245+
cy.origin('www.acme.com', () => {
246+
cy.get('h1').contains('About our Founder, Marvin Acme')
247+
})
248+
```
249+
250+
Here the cross-origin page is visited prior to the `cy.origin` block, but any
251+
interactions with the window are performed within the block which can
252+
communicate with the cross-origin page
253+
254+
#### <Icon name="exclamation-triangle" color="red"></Icon> Incorrect Usage
255+
256+
```js
257+
// Do things in primary origin...
258+
259+
cy.visit('https://www.acme.com/history/founder')
260+
261+
// This command will fail, it's executed on localhost but the application is at acme.com
262+
cy.get('h1').contains('About our Founder, Marvin Acme')
263+
```
264+
265+
Here `cy.get('h1')` fails because we are trying to interact with a cross-origin
266+
page outside of the cy.origin block, due to 'same-origin' restrictions, the
267+
'localhost' javascript context can't communicate with 'acme.com'.
268+
236269
### Navigating to secondary origin with UI
237270

238-
When navigating to a secondary origin by clicking a link or button in the
239-
primary origin, it is essential to trigger the navigation _before_ entering the
240-
origin callback, otherwise a cross-origin error will be thrown.
271+
Navigating to a secondary origin by clicking a link or button in the primary
272+
origin is supported.
241273

242274
```js
243275
// Button in primary origin goes to https://www.acme.com
@@ -290,7 +322,7 @@ do this with `cy.origin()`.
290322

291323
```js
292324
Cypress.Commands.add('login', (username, password) => {
293-
// Remember to pass in dependencies via `args`
325+
// Remember to pass in arguments via `args`
294326
const args = { username, password }
295327
cy.origin('my-auth.com', { args }, ({ username, password }) => {
296328
// Go to https://auth-provider.com/login
@@ -473,49 +505,120 @@ of
473505
[restrictions on the data which may be passed](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#things_that_dont_work_with_structured_clone)
474506
into the callback.
475507

476-
### Callback restrictions
508+
### Dependencies / Sharing Code
477509

478-
Because of the way in which the callback is transmitted and executed, there are
479-
certain limitations on what code may be run inside it. In particular, the
480-
following Cypress commands will throw errors if used in the callback:
510+
It is not possible to use
511+
[CommonJS `require()`](https://nodejs.org/en/knowledge/getting-started/what-is-require/)
512+
or
513+
[dynamic ES module `import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports)
514+
within the callback. However, [`Cypress.require()`](/api/cypress-api/require)
515+
can be utilized to include [npm](https://www.npmjs.com/) packages and other
516+
files. It is functionally the same as using
517+
[CommonJS `require()`](https://nodejs.org/en/knowledge/getting-started/what-is-require/)
518+
in browser-targeted code.
481519

482-
- `cy.origin()`
483-
- [`cy.intercept()`](/api/commands/intercept)
484-
- [`cy.session()`](/api/commands/session)
485-
- [`cy.server()`](/api/commands/server)
486-
- [`cy.route()`](/api/commands/route)
487-
- [`Cypress.Cookies.preserveOnce()`](/api/cypress-api/cookies)
520+
```js
521+
cy.origin('somesite.com', () => {
522+
const _ = Cypress.require('lodash')
523+
const utils = Cypress.require('../support/utils')
488524

489-
It is also currently not possible to use
490-
[`require()`](https://nodejs.org/en/knowledge/getting-started/what-is-require/)
491-
or
492-
[dynamic `import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports)
493-
within the callback. Because of this limitation, it cannot use
494-
[npm](https://www.npmjs.com/) packages or other third-party libraries inside the
495-
callback, as there is no mechanism to reference them. This functionality will be
496-
provided in a future version of Cypress.
525+
// ... use lodash and utils ...
526+
})
527+
```
528+
529+
`Cypress.require()` can be used to share custom commands between tests run in
530+
primary and secondary origins. We recommend this pattern for setting up your
531+
[support file](/guides/core-concepts/writing-and-organizing-tests#Support-file)
532+
and setting up custom commands to run within the `cy.origin()` callback:
533+
534+
`cypress/support/commands.js`:
535+
536+
```js
537+
Cypress.Commands.add('clickLink', (label) => {
538+
cy.get('a').contains(label).click()
539+
})
540+
```
541+
542+
`cypress/support/e2e.js`:
543+
544+
```js
545+
// makes custom commands available to all Cypress tests in this spec,
546+
// outside of cy.origin() callbacks
547+
import './commands'
548+
549+
// code we only want run per test, so it shouldn't be run as part of
550+
// the execution of cy.origin() as well
551+
beforeEach(() => {
552+
// ... code to run before each test ...
553+
})
554+
```
555+
556+
`cypress/e2e/spec.cy.js`:
557+
558+
```js
559+
before(() => {
560+
// makes custom commands available to all subsequent cy.origin('somesite.com')
561+
// calls in this spec. put it in your support file to make them available to
562+
// all specs
563+
cy.origin('somesite.com', () => {
564+
Cypress.require('../support/commands')
565+
})
566+
})
567+
568+
it('tests somesite.com', () => {
569+
cy.origin('somesite.com', () => {
570+
cy.visit('/page')
571+
cy.clickLink('Click Me')
572+
})
573+
})
574+
```
497575

498-
While third-party packages are strictly unavailable, it is possible to reuse
499-
your **own** code between `cy.origin()` callbacks. The workaround is to create a
500-
custom Cypress command within the secondary origin in a `before` block:
576+
The JavaScript execution context is persisted between `cy.origin()` callbacks
577+
that share the same origin. This can be utilized to share code between
578+
successive `cy.origin()` calls.
501579

502580
```js
503581
before(() => {
504582
cy.origin('somesite.com', () => {
505-
Cypress.Commands.add('clickLink', (label) => {
506-
cy.get('a').contains(label).click()
507-
})
583+
// makes commands defined in this file available to all callbacks
584+
// for somesite.com
585+
Cypress.require('../support/commands')
508586
})
509587
})
510588

511-
it('clicks the secondary origin link', () => {
589+
it('uses cy.origin() + custom command', () => {
512590
cy.origin('somesite.com', () => {
513591
cy.visit('/page')
514592
cy.clickLink('Click Me')
515593
})
516594
})
595+
596+
it('also uses cy.origin() + custom command', () => {
597+
cy.origin('somesite.com', () => {
598+
cy.visit('/page')
599+
cy.clickLink('Click Me')
600+
})
601+
602+
cy.origin('differentsite.com', () => {
603+
// WARNING: cy.clickLink() will not be available because it is a
604+
// different origin
605+
})
606+
})
517607
```
518608

609+
### Callback restrictions
610+
611+
Because of the way in which the callback is transmitted and executed, there are
612+
certain limitations on what code may be run inside it. In particular, the
613+
following Cypress commands will throw errors if used in the callback:
614+
615+
- `cy.origin()`
616+
- [`cy.intercept()`](/api/commands/intercept)
617+
- [`cy.session()`](/api/commands/session)
618+
- [`cy.server()`](/api/commands/server)
619+
- [`cy.route()`](/api/commands/route)
620+
- [`Cypress.Cookies.preserveOnce()`](/api/cypress-api/cookies)
621+
519622
### Other limitations
520623

521624
There are other testing scenarios which are not currently covered by

0 commit comments

Comments
 (0)