From ab901b31c76c1f46a0106ea67b8771da32ae4050 Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Fri, 2 Dec 2022 09:21:41 -0600 Subject: [PATCH 1/8] update test isolation docs & apply Product review suggestions --- content/_data/sidebar.json | 4 + content/api/commands/session.md | 41 +++--- .../guides/core-concepts/test-isolation.md | 124 ++++++++++++++++++ .../writing-and-organizing-tests.md | 122 +---------------- content/guides/references/configuration.md | 2 +- 5 files changed, 157 insertions(+), 136 deletions(-) create mode 100644 content/guides/core-concepts/test-isolation.md diff --git a/content/_data/sidebar.json b/content/_data/sidebar.json index b067fe1148..4ccf8388f1 100644 --- a/content/_data/sidebar.json +++ b/content/_data/sidebar.json @@ -197,6 +197,10 @@ "title": "Writing and Organizing Tests", "slug": "writing-and-organizing-tests" }, + { + "title": "Test Isolation", + "slug": "test-isolation" + }, { "title": "Retry-ability", "slug": "retry-ability" diff --git a/content/api/commands/session.md b/content/api/commands/session.md index 38980e31e1..3899c716db 100644 --- a/content/api/commands/session.md +++ b/content/api/commands/session.md @@ -12,8 +12,8 @@ tests. The `cy.session()` command will inherit the [`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) -mode value to determine whether or not the page is cleared when caching and -restoring the browser context. +value to determine whether or not the page is cleared when caching and restoring +the browser context. ## Syntax @@ -102,11 +102,11 @@ runs, Cypress will preserve all cookies, `sessionStorage`, and `localStorage`, so that subsequent calls to `cy.session()` with the same `id` will bypass `setup` and just restore the cached session data. -The page is cleared before `setup` when `testIsolation='on'` and is not cleared -when `testIsolation='off'`. +The page is cleared before `setup` when `testIsolation` is enabled and is not +cleared when `testIsolation` is disabled. Cookies, local storage and session storage in all domains are always cleared -before `setup` runs, regardless of the testIsolation configuration. +before `setup` runs, regardless of the `testIsolation` configuration. ** options** **_(Object)_** @@ -645,13 +645,13 @@ it('t3', () => { ### When the page and session data are cleared -### Test Isolation `on` +### Test Isolation Enabled The page is cleared and cookies, local storage and session storage (session -data) in all domains are cleared automatically when `cy.session()` runs and -`testIsolation` is `on`. This guarantees consistent behavior whether a session -is being created or restored and allows you to switch sessions without first -having to explicitly log out. +data) in all domains are cleared automatically when `cy.session()` runs and test +isolation is enabled with `testIsolation=true`, This guarantees consistent +behavior whether a session is being created or restored and allows you to switch +sessions without first having to explicitly log out. | | Page cleared (test) | Session data cleared | | -------------------------- | :---------------------------------------------: | :---------------------------------------------: | @@ -661,10 +661,10 @@ having to explicitly log out. [`cy.visit()`](/api/commands/visit) must be explicitly called afterwards to ensure the page to test is loaded. -### Test Isolation `off` +### Test Isolation Disabled -When `testIsolation` is `off`, the page will not clear, however, the session -data will clear when `cy.session()` runs. +When test isolation is disabled with `testIsolation=false`, the page will not +clear, however, the session data will clear when `cy.session()` runs. | | Page cleared (test) | Session data cleared | | -------------------------- | :-----------------: | :---------------------------------------------: | @@ -674,13 +674,13 @@ data will clear when `cy.session()` runs. [`cy.visit()`](/api/commands/visit) does not need to be called afterwards to ensure the page to test is loaded. -NOTE: Turning test isolation off may improve performance of end-to-end tests, +NOTE: Disabling test isolation may improve performance of end-to-end tests, however, previous tests could impact the browser state of the next test and cause inconsistency when using .only(). Be mindful to write isolated tests when -test isolation is off. +test isolation is disabled. -When test isolation is `off`, it is encouraged to setup your session in a before -hook or in the first test to ensure a clean setup. +When test isolation is disabled, it is encouraged to setup your session in a +before hook or in the first test to ensure a clean setup. ### Session caching @@ -823,9 +823,10 @@ generate random unique ids if an arbitrary name-space does not meet your needs. #### Why are all my Cypress commands failing after calling `cy.session()`? -When test isolation is `on`, ensure that you're calling -[`cy.visit()`](/api/commands/visit) after calling `cy.session()`, otherwise your -tests will be running on a blank page. +When +[`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation)is +enabled, ensure that you're calling [`cy.visit()`](/api/commands/visit) after +calling `cy.session()`, otherwise your tests will be running on a blank page. #### Why am I seeing `401` errors after calling `cy.session()`? diff --git a/content/guides/core-concepts/test-isolation.md b/content/guides/core-concepts/test-isolation.md new file mode 100644 index 0000000000..a121496c57 --- /dev/null +++ b/content/guides/core-concepts/test-isolation.md @@ -0,0 +1,124 @@ +--- +title: 'Test Isolation' +--- + + + +## What you'll learn + +- What is test isolation +- How it impacts E2E Testing vs Component Testing +- Test isolation trade-offs + + + +## What is Test Isolation? + + + + **Best Practice:** Tests should +always be able to be run independently from one another **and still pass**. + + + +As stated in our mission, we hold ourselves accountable to champion a testing +process that actually works, and have built Cypress to guide developers towards +writing independent tests from the start. + +We do this by cleaning up state _before_ each test to ensure that the operation +of one test does not affect another test later on. The goal for each test should +be to **reliably pass** whether run in isolation or consecutively with other +tests. Having tests that depend on the state of an earlier test can potentially +cause nondeterministic test failures which makes debugging challenging. + +Cypress will start each test with a clean test slate by restoring and clearing +all: + +- [aliases](/api/commands/as) +- [clock mocks](/api/commands/clock) +- [intercepts](/api/commands/intercept) +- [routes](/api/commands/route) +- [spies](/api/commands/spy) +- [stubs](/api/commands/stub) +- [viewport changes](/api/commands/viewport) + +In additional to a clean test slate, Cypress also believes in running tests in a +clean browser context such that the application or component under test behaves +consistently when ran. This behavior is described as `testIsolation`. + +The test isolation is a global configuration and can be overridden for +end-to-end testing at the `describe` level with the +[`testIsolation`](/guides/references/configuration#Global) option. + +## Test Isolation in End-to-End Testing + +Cypress supports the enabled or disabling test isolation in end-to-end testing +to describe if a suite of tests should run in a clean browser context or not. + +### Test Isolation Enabled + +When test isolation is enabled, Cypress resets the browser context _before_ each +test by: + +- clearing the dom state by visiting `about:blank` +- clearing [cookies](/api/cypress-api/cookies) in all domains +- clearing + [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) + in all domains +- clearing + [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) + in all domains + +Because the test starts in a fresh browser context, you must re-visit your +application and perform the series of interactions needed to build the dom and +browser state for each test. + +Additionally, the [`cy.session()`](/api/commands/session) command will inherent +this configuration and will clear the page and current browser context when +establishing a browser session. This is so tests can reliably pass when run +standalone or in a randomized order. + +### Test Isolation Disabled + +When test isolation is disabled, Cypress will not alter the browser context +before the test starts. The page does not clear between tests and cookies, local +storage and session storage will be available across tests in that suite. +Additionally, the [`cy.session()`](/api/commands/session) command will only +clear the current browser context when establishing the browser session - the +current page is not cleared. + +### Quick Comparison + +| testIsolation | beforeEach test | cy.session() | +| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ | +| `true` | - clears page by visiting `about:blank`
- clears cookies in all domains
- local storage in all domains
- session storage in all domains | - clears page by visiting `about:blank`
- clears cookies in all domains
- local storage in all domains
- session storage in all domains | +| `false` | does not alter the current browser context |
- clears cookies in all domains
- local storage in all domains
- session storage in all domains | + +## Test Isolation in Component Testing + +Cypress does not support configuring the test isolation behavior in component +testing. + +When running component tests, Cypress always resets the browser context _before_ +each test by: + +- unmounting the rendered component under test +- clearing [cookies](/api/cypress-api/cookies) in all domains +- clearing + [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) + in all domains +- clearing + [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) + in all domains + +## Test Isolation Trade-offs + +It is important to note that disabling test isolation may improve the overall +performance of end-to-end tests, however, it can also cause state to "leak" +between tests. This can make later tests dependent on the results of earlier +tests, and potentially cause misleading test failures. It is important to be +extremely mindful of how tests are written when using this mode, and ensure that +tests continue to run independently of one another. + +The best way to ensure your tests are independent is to add a `.only()` to your +test and verify it can run successfully without the test before it. diff --git a/content/guides/core-concepts/writing-and-organizing-tests.md b/content/guides/core-concepts/writing-and-organizing-tests.md index 24aa813734..8bbd74892e 100644 --- a/content/guides/core-concepts/writing-and-organizing-tests.md +++ b/content/guides/core-concepts/writing-and-organizing-tests.md @@ -564,34 +564,6 @@ it.skip('returns "fizz" when number is multiple of 3', () => { ### Test Isolation - - - -Experimental - -The concept of test isolation is currently experimental, and can be enabled by -setting the [`experimentalSessionAndOrigin`](/guides/references/experiments) -option to `true` in the Cypress config. - - - - - - **Best Practice:** Tests should -always be able to be run independently from one another **and still pass**. - - - -As stated in our mission, we hold ourselves accountable to champion a testing -process that actually works, and have built Cypress to guide developers towards -writing independent tests from the start. - -We do this by cleaning up state _before_ each test to ensure that the operation -of one test does not affect another test later on. The goal for each test should -be to **reliably pass** whether run in isolation or consecutively with other -tests. Having tests that depend on the state of an earlier test can potentially -cause nondeterministic test failures which makes debugging challenging. - Cypress will start each test with a clean test slate by restoring and clearing all: @@ -604,95 +576,15 @@ all: - [viewport changes](/api/commands/viewport) In additional to a clean test slate, Cypress also believes in running tests in a -clean browser context such that the application or component under test behaves -consistently when ran. This concept is described as `testIsolation`. - -The test isolation mode is a global configuration and can be overridden at the -`describe` level with the -[`testIsolation`](/guides/references/configuration#Global) option. - -#### End-to-end testing - -Cypress supports the following modes of test isolation in end-to-end testing to -describe if a suite of tests should run in a clean browser context or not: `on` -and `off`. - -###### On Mode - - - - -Experimental - -`on` mode is currently experimental and can be enabled by setting -the [`experimentalSessionAndOrigin`](/guides/references/experiments) flag -to `true` in the Cypress config. This is the default test isolation behavior -when using the `experimentalSessionAndOrigin` experiment. - - - -When in `on` mode, Cypress resets the browser context _before_ each test by: - -- clearing the dom state by visiting `about:blank` -- clearing [cookies](/api/cypress-api/cookies) in all domains -- clearing - [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) - in all domains -- clearing - [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) - in all domains - -Because the test starts in a fresh browser context, you must re-visit your -application and perform the series of interactions needed to build the dom and -browser state for each test. - -Additionally, the `cy.session()` command will inherent this mode and will clear -the page and current browser context when establishing a browser session. This -is so tests can reliably pass when run standalone or in a randomized order. - -###### Off Mode - - - - -Experimental - -`off` mode is currently experimental and can be enabled by setting -the [`experimentalSessionAndOrigin`](/guides/references/experiments) flag -to `true` in the Cypress config. - - - -When in `off` mode, Cypress will not alter the browser context before the test -starts. The page does not clear between tests and cookies, local storage and -session storage will be available across tests in that suite. Additionally, the -`cy.session()` command will only clear the current browser context when -establishing the browser session - the current page will not clear. - -It is important to note that turning test isolation `off` may improve the -overall performance of end-to-end tests, however, previous tests could be impact -the browser state. It is important to be extremely mindful of how test are -written when using this mode and ensure tests continue to run independent from -one other. - -###### Mode Comparison - -| testIsolation | beforeEach test | cy.session() | -| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ | -| `on` | - clears page by visiting `about:blank`
- clears cookies in all domains
- local storage in all domains
- session storage in all domains | - clears page by visiting `about:blank`
- clears cookies in all domains
- local storage in all domains
- session storage in all domains | -| `off` | does not alter the current browser context |
- clears cookies in all domains
- local storage in all domains
- session storage in all domains | - -##### Component testing - -Cypress only support testIsolation `on` in component testing. +clean test and browser context such that the application or component under test +behaves consistently when ran. This behavior is described as `testIsolation`. -When running component tests, the browser context will allow start in a clean -slate because Cypress will +The test isolation is a global configuration and can be overridden for +end-to-end testing at the `describe` level with the +[`testIsolation`](/guides/references/configuration#e2e) option. -- clear the page -- clear [cookies](/api/cypress-api/cookies) -- clear - [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) +To learn more about this behavior and the tradeoffs of disabling it, review our +[Test Isolation guide](/guides/core-concepts/test-isolation). ### Test Configuration diff --git a/content/guides/references/configuration.md b/content/guides/references/configuration.md index bce0d0d5a2..a8414b7c8c 100644 --- a/content/guides/references/configuration.md +++ b/content/guides/references/configuration.md @@ -208,7 +208,7 @@ object: | `specPattern` | `cypress/e2e/**/*.cy.{js,jsx,ts,tsx}` | A String or Array of glob patterns of the test files to load. | | `excludeSpecPattern` | `*.hot-update.js` | A String or Array of glob patterns used to ignore test files that would otherwise be shown in your list of tests. [Please read the notes on using this.](#excludeSpecPattern) | | `slowTestThreshold` | `10000` | Time, in milliseconds, to consider a test "slow" during `cypress run`. A slow test will display in orange text in the default reporter. | -| `testIsolation` | `on` | The [test isolation level](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) applied to ensure a clean slate between tests. Options are `on` or `off`. | +| `testIsolation` | `true` | Whether or not [test isolation](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) is enabled to ensure a clean browser context between tests. | | Option | Default | Description | | `experimentalRunAllSpecs` | `false` | Enables the "Run All Specs" UI feature, allowing the execution of multiple specs sequentially. | From c7a717eafdabca5f903bef68f83fe136af1035c3 Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Fri, 2 Dec 2022 15:46:00 -0600 Subject: [PATCH 2/8] update migration guide --- content/guides/references/migration-guide.md | 33 ++++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/content/guides/references/migration-guide.md b/content/guides/references/migration-guide.md index 32c89d05e2..f0e5ad08f3 100644 --- a/content/guides/references/migration-guide.md +++ b/content/guides/references/migration-guide.md @@ -13,10 +13,9 @@ The Session and Origin experiment has been released as General Availability free of issues in the majority of use cases. With releasing this as GA, the `experimentalSessionAndOrigin` flag has been removed, the [`cy.origin()`](<(/api/commands/origin)>) and -[`cy.session()`](/api/commands/session) commands are generally available and the -concept of +[`cy.session()`](/api/commands/session) commands are generally available and [Test Isolation](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) -has been introduced. +is enabled by default. ### Node.js 14+ support @@ -34,8 +33,8 @@ version supported to install Cypress is Node.js 14+. The [`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) -config option defaults to `on`. This means Cypress resets the browser context -_before_ each test by: +config option is enabled by default. This means Cypress resets the browser +context _before_ each test by: - clearing the dom state by visiting `about:blank` - clearing [cookies](/api/cypress-api/cookies) in all domains @@ -83,8 +82,8 @@ it('validates the change', () => { }) ``` -After migrating, when `testIsolation='on'`, this flow would need to be contained -within a single test. While the above practice has always been +After migrating and `testIsolation=true` by default, this flow would need to be +contained within a single test. While the above practice has always been [discouraged](/guides/references/best-practices#Having-tests-rely-on-the-state-of-previous-tests) we know some users have historically written tests this way, often to get around the `same-origin` restrictions. But with [`cy.origin()`](/api/commands/origin) @@ -124,27 +123,27 @@ application logins, while users also benefit from the test isolation guardrails to write independent, reliable and deterministic tests from the start. If for whatever reason you still need to persist the dom and browser context -between tests, you can set `testIsolation='off` on the root configuration or at -the suite-level. For example: +between tests, you can disable test isolation by setting `testIsolation=false` +on the root configuration or at the suite-level. For example: ```js -describe('workflow', { testIsolation: 'off' }, () => { +describe('workflow', { testIsolation: false }, () => { ... }) ``` -It is important to note that while turning test isolation `off` may improve the -overall performance of end-to-end tests, it can however cause state to "leak" -between tests. This can make later tests dependent on the results of earlier -tests, and potentially cause misleading test failures. It is important to be -extremely mindful of how tests are written when using this mode, and ensure that -tests continue to run independently of one another. +It is important to note that disabling test isolation may improve the overall +performance of end-to-end tests, it can cause state to "leak" between tests. +This can make later tests dependent on the results of earlier tests, and +potentially cause misleading test failures. It is important to be extremely +mindful of how tests are written when using this mode, and ensure that tests +continue to run independently of one another. For examplethe following tests are not independent nor deterministic: ```js -describe('workflow', { testIsolation: 'off' }, () => { +describe('workflow', { testIsolation: false }, () => { it('logs in', () => { cy.visit('my-app.com/log-in) cy.get('username').type('User1') From 02f93494f9bc1c4e45eec89748788dab62a95afb Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Mon, 5 Dec 2022 11:28:12 -0600 Subject: [PATCH 3/8] Update content/guides/references/migration-guide.md Co-authored-by: Chris Breiding --- content/guides/references/migration-guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/guides/references/migration-guide.md b/content/guides/references/migration-guide.md index f0e5ad08f3..e3299d745f 100644 --- a/content/guides/references/migration-guide.md +++ b/content/guides/references/migration-guide.md @@ -132,7 +132,7 @@ describe('workflow', { testIsolation: false }, () => { }) ``` -It is important to note that disabling test isolation may improve the overall +It is important to note that while disabling test isolation may improve the overall performance of end-to-end tests, it can cause state to "leak" between tests. This can make later tests dependent on the results of earlier tests, and potentially cause misleading test failures. It is important to be extremely From c43906e11d6f07caaf77087b50db7b7b1ef932f6 Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Mon, 5 Dec 2022 11:28:20 -0600 Subject: [PATCH 4/8] Update content/guides/references/migration-guide.md Co-authored-by: Matt Henkes --- content/guides/references/migration-guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/guides/references/migration-guide.md b/content/guides/references/migration-guide.md index e3299d745f..4f93a88887 100644 --- a/content/guides/references/migration-guide.md +++ b/content/guides/references/migration-guide.md @@ -82,7 +82,7 @@ it('validates the change', () => { }) ``` -After migrating and `testIsolation=true` by default, this flow would need to be +After migrating, when `testIsolation=true` by default, this flow would need to be contained within a single test. While the above practice has always been [discouraged](/guides/references/best-practices#Having-tests-rely-on-the-state-of-previous-tests) we know some users have historically written tests this way, often to get around From eb349e2c201c80e5fbc1e8c732cb97a9261d360e Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Mon, 5 Dec 2022 11:28:28 -0600 Subject: [PATCH 5/8] Update content/api/commands/session.md Co-authored-by: Bill Glesias --- content/api/commands/session.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/api/commands/session.md b/content/api/commands/session.md index 3899c716db..11e8933b63 100644 --- a/content/api/commands/session.md +++ b/content/api/commands/session.md @@ -824,7 +824,7 @@ generate random unique ids if an arbitrary name-space does not meet your needs. #### Why are all my Cypress commands failing after calling `cy.session()`? When -[`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation)is +[`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) is enabled, ensure that you're calling [`cy.visit()`](/api/commands/visit) after calling `cy.session()`, otherwise your tests will be running on a blank page. From 4555ee52be11581df4f791b0ca7c3333345515f4 Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Mon, 5 Dec 2022 11:28:37 -0600 Subject: [PATCH 6/8] Update content/guides/core-concepts/test-isolation.md Co-authored-by: Chris Breiding --- content/guides/core-concepts/test-isolation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/guides/core-concepts/test-isolation.md b/content/guides/core-concepts/test-isolation.md index a121496c57..cee7e7f4ae 100644 --- a/content/guides/core-concepts/test-isolation.md +++ b/content/guides/core-concepts/test-isolation.md @@ -52,7 +52,7 @@ end-to-end testing at the `describe` level with the ## Test Isolation in End-to-End Testing -Cypress supports the enabled or disabling test isolation in end-to-end testing +Cypress supports enabling or disabling test isolation in end-to-end testing to describe if a suite of tests should run in a clean browser context or not. ### Test Isolation Enabled From 2d60ec43059a44161cdd16758d0abdebeb0393ae Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Mon, 5 Dec 2022 11:28:44 -0600 Subject: [PATCH 7/8] Update content/guides/core-concepts/test-isolation.md Co-authored-by: Matt Henkes --- content/guides/core-concepts/test-isolation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/guides/core-concepts/test-isolation.md b/content/guides/core-concepts/test-isolation.md index cee7e7f4ae..9044706bb2 100644 --- a/content/guides/core-concepts/test-isolation.md +++ b/content/guides/core-concepts/test-isolation.md @@ -29,7 +29,7 @@ We do this by cleaning up state _before_ each test to ensure that the operation of one test does not affect another test later on. The goal for each test should be to **reliably pass** whether run in isolation or consecutively with other tests. Having tests that depend on the state of an earlier test can potentially -cause nondeterministic test failures which makes debugging challenging. +cause nondeterministic test failures which make debugging challenging. Cypress will start each test with a clean test slate by restoring and clearing all: From c65db60550993870d1fd92bb0f6f57907bbe328f Mon Sep 17 00:00:00 2001 From: Emily Rohrbough Date: Mon, 5 Dec 2022 12:17:56 -0600 Subject: [PATCH 8/8] fix markdown --- content/api/commands/session.md | 4 ++-- content/guides/core-concepts/test-isolation.md | 4 ++-- content/guides/references/migration-guide.md | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/content/api/commands/session.md b/content/api/commands/session.md index 11e8933b63..d2cb4312f0 100644 --- a/content/api/commands/session.md +++ b/content/api/commands/session.md @@ -824,8 +824,8 @@ generate random unique ids if an arbitrary name-space does not meet your needs. #### Why are all my Cypress commands failing after calling `cy.session()`? When -[`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) is -enabled, ensure that you're calling [`cy.visit()`](/api/commands/visit) after +[`testIsolation`](/guides/core-concepts/writing-and-organizing-tests#Test-Isolation) +is enabled, ensure that you're calling [`cy.visit()`](/api/commands/visit) after calling `cy.session()`, otherwise your tests will be running on a blank page. #### Why am I seeing `401` errors after calling `cy.session()`? diff --git a/content/guides/core-concepts/test-isolation.md b/content/guides/core-concepts/test-isolation.md index 9044706bb2..3f8150469b 100644 --- a/content/guides/core-concepts/test-isolation.md +++ b/content/guides/core-concepts/test-isolation.md @@ -52,8 +52,8 @@ end-to-end testing at the `describe` level with the ## Test Isolation in End-to-End Testing -Cypress supports enabling or disabling test isolation in end-to-end testing -to describe if a suite of tests should run in a clean browser context or not. +Cypress supports enabling or disabling test isolation in end-to-end testing to +describe if a suite of tests should run in a clean browser context or not. ### Test Isolation Enabled diff --git a/content/guides/references/migration-guide.md b/content/guides/references/migration-guide.md index 4f93a88887..de76751348 100644 --- a/content/guides/references/migration-guide.md +++ b/content/guides/references/migration-guide.md @@ -82,8 +82,8 @@ it('validates the change', () => { }) ``` -After migrating, when `testIsolation=true` by default, this flow would need to be -contained within a single test. While the above practice has always been +After migrating, when `testIsolation=true` by default, this flow would need to +be contained within a single test. While the above practice has always been [discouraged](/guides/references/best-practices#Having-tests-rely-on-the-state-of-previous-tests) we know some users have historically written tests this way, often to get around the `same-origin` restrictions. But with [`cy.origin()`](/api/commands/origin) @@ -132,9 +132,9 @@ describe('workflow', { testIsolation: false }, () => { }) ``` -It is important to note that while disabling test isolation may improve the overall -performance of end-to-end tests, it can cause state to "leak" between tests. -This can make later tests dependent on the results of earlier tests, and +It is important to note that while disabling test isolation may improve the +overall performance of end-to-end tests, it can cause state to "leak" between +tests. This can make later tests dependent on the results of earlier tests, and potentially cause misleading test failures. It is important to be extremely mindful of how tests are written when using this mode, and ensure that tests continue to run independently of one another.