Skip to content

Commit e121dd1

Browse files
authored
Merge pull request #453 from javierbrea/release
Release v2.2.0
2 parents 39a2f2e + 7e510b3 commit e121dd1

File tree

168 files changed

+44631
-6366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+44631
-6366
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/test-e2e/app/build
2+
/test-e2e/cypress-9/cypress/integration
3+
/test-e2e/cypress-9-no-plugin/cypress/integration

.github/workflows/check-package-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
uses: martinbeentjes/[email protected]
2828
- name: Check Changelog version
2929
id: changelog_reader
30-
uses: mindsers/changelog-reader-action@v2.0.0
30+
uses: mindsers/changelog-reader-action@v2.1.1
3131
with:
3232
version: ${{ steps.package-version.outputs.current-version }}
3333
path: ./CHANGELOG.md

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
### Removed
1212
### BREAKING CHANGES
1313

14+
## [2.2.0] - 2022-07-26
15+
16+
### Added
17+
- feat(#401): Support preserving localStorage across spec files. Node events must be installed to support this feature.
18+
19+
### Changed
20+
- docs: Update docs with installation method in Cypress v10. Add notes about installing it in prior versions.
21+
- chore(deps): Update devDependencies
22+
- test(e2e): Add E2E tests using different Cypress versions
23+
1424
## [2.1.0] - 2022-06-02
1525

1626
### Changed

README.md

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
# Cypress localStorage commands
88

9-
Extends Cypress' cy commands with localStorage methods. Allows preserving localStorage between tests and disabling localStorage.
9+
Extends Cypress' cy commands with localStorage methods. Allows preserving localStorage between tests and spec files, and disabling localStorage.
1010

1111
## The problems
1212

1313
* You want to preserve localStorage between Cypress tests.
14+
* You want to preserve localStorage between Cypress spec files.
1415
* You want to disable localStorage to check error handling.
1516

1617
## This solution
1718

18-
This solution allows you to use all browser localStorage methods through Cypress commands, and preserve it between tests. It also allows to simulate that localStorage is disabled in the browser.
19+
This solution allows you to use all browser localStorage methods through Cypress commands, and preserve it between tests and spec files. It also allows to simulate that localStorage is disabled in the browser.
1920

2021
## Installation
2122

@@ -25,58 +26,102 @@ This module is distributed via npm which is bundled with node and should be inst
2526
npm i --save-dev cypress-localstorage-commands
2627
```
2728

28-
## Usage
29+
### Installing commands
30+
31+
`cypress-localstorage-commands` extends Cypress' cy commands.
32+
33+
At the top of your Cypress' support file (usually `cypress/support/e2e.js` for `e2e` testing type):
34+
35+
```javascript
36+
import "cypress-localstorage-commands";
37+
```
2938

30-
`cypress-localstorage-commands` extends Cypress' cy command.
39+
Read [Cypress configuration docs](https://docs.cypress.io/guides/references/configuration) for further info.
3140

32-
Add this line to your project's `cypress/support/commands.js`:
41+
<details>
42+
<summary><strong>Installing commands in Cypress <10.0</strong></summary>
43+
44+
Add this line to your project's `cypress/support/index.js`:
3345

3446
```js
3547
import "cypress-localstorage-commands"
3648
```
3749

38-
You can now use all next commands:
50+
</details>
51+
52+
### Installing Node events
53+
54+
__⚠ In order to support preserving localStorage across Cypress spec files, the plugin's Node events must be installed also.__ Otherwise, localStorage will be preserved only across tests in the same spec file.
55+
56+
In the `cypress.config.js` file:
57+
58+
```javascript
59+
module.exports = {
60+
e2e: {
61+
setupNodeEvents(on, config) {
62+
require("cypress-localstorage-commands/plugin")(on, config);
63+
return config;
64+
},
65+
},
66+
};
67+
```
68+
69+
<details>
70+
<summary><strong>Installing Node events in Cypress <10.0</strong></summary>
71+
72+
In the `cypress/plugins/index.js` file:
73+
74+
```javascript
75+
module.exports = (on, config) => {
76+
require("cypress-localstorage-commands/plugin")(on, config);
77+
return config;
78+
};
79+
```
80+
81+
</details>
82+
83+
## Usage
3984

4085
### Commands
4186

42-
##### `cy.saveLocalStorage([snapshotName])`
87+
#### `cy.saveLocalStorage([snapshotName])`
4388

4489
Saves current localStorage values into an internal "snapshot".
4590

4691
* `snapshotName` _(String)_: Optionally, a `snapshotName` can be provided, and then data from localStorage will be saved into a snapshot with that name. So, multiple snapshots can be stored.
4792

48-
##### `cy.restoreLocalStorage([snapshotName])`
93+
#### `cy.restoreLocalStorage([snapshotName])`
4994

5095
Restores localStorage to previously "snapshot" saved values. __
5196

5297
* `snapshotName` _(String)_: Optional. If provided, the localStorage will be restored using data from that specific snapshot.
5398

54-
##### `cy.clearLocalStorageSnapshot([snapshotName])`
99+
#### `cy.clearLocalStorageSnapshot([snapshotName])`
55100

56101
Clears localStorage "snapshot" values, so previously saved values are cleaned.
57102

58103
* `snapshotName` _(String)_: Optional. If provided, only data from that specific snapshot will be cleared.
59104

60-
##### `cy.getLocalStorage(item)`
105+
#### `cy.getLocalStorage(item)`
61106

62107
Gets localStorage item. Equivalent to `localStorage.getItem` in browser.
63108

64109
* `item` _(String)_: Item to get from `localStorage`.
65110

66-
##### `cy.setLocalStorage(item, value)`
111+
#### `cy.setLocalStorage(item, value)`
67112

68113
Sets localStorage item. Equivalent to `localStorage.setItem` in browser.
69114

70115
* `item` _(String)_: Item to set value.
71116
* `value` _(String)_: Value to be set.
72117

73-
##### `cy.removeLocalStorage(item)`
118+
#### `cy.removeLocalStorage(item)`
74119

75120
Removes localStorage item. Equivalent to `localStorage.removeItem` in browser.
76121

77122
* `item` _(String)_: Item to be removed.
78123

79-
##### `cy.disableLocalStorage(options)`
124+
#### `cy.disableLocalStorage(options)`
80125

81126
Disables localStorage. It produces localStorage methods to throw errors.
82127

@@ -87,6 +132,8 @@ Disables localStorage. It produces localStorage methods to throw errors.
87132

88133
Use `cy.saveLocalStorage()` to save a snapshot of current `localStorage` at the end of one test, and use the `cy.restoreLocalStorage()` command to restore it at the beginning of another one. _The usage of `beforeEach` and `afterEach` is recommended for this purpose._
89134

135+
> ⚠ When the [plugin's Node events are installed](#installing-node-events), the `cy.restoreLocalStorage()` command will be able to restore the localStorage snapshots saved in other spec files. Otherwise, snapshots are completely cleared between spec files.
136+
90137
### Examples
91138

92139
#### Cookies button example
@@ -125,7 +172,7 @@ describe("Accept cookies button", () => {
125172
});
126173
```
127174

128-
> Note the usage of `beforeEach` and `afterEach` for preserving `localStorage` between all tests. Also `cy.clearLocalStorageSnapshot` is used in the `before` statement to avoid possible conflicts with other test files preserving localStorage.
175+
> Note the usage of `beforeEach` and `afterEach` for preserving `localStorage` between all tests. Also `cy.clearLocalStorageSnapshot` is used in the `before` statement to avoid possible conflicts with other spec files preserving localStorage.
129176
130177
#### localStorage assertions
131178

0 commit comments

Comments
 (0)