Skip to content

Commit 6509854

Browse files
authored
Merge pull request #385 from javierbrea/release
Release v1.7.0
2 parents 15fc2f5 + 9256e5b commit 6509854

24 files changed

+44049
-14932
lines changed

.eslintrc.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
es6: true,
5+
},
6+
parserOptions: {
7+
ecmaVersion: 2018,
8+
},
9+
plugins: ["prettier", "jest", "no-only-tests", "mocha"],
10+
rules: {
11+
"prettier/prettier": [
12+
"error",
13+
{
14+
printWidth: 99,
15+
parser: "flow",
16+
},
17+
],
18+
"no-shadow": [2, { builtinGlobals: true, hoist: "all" }],
19+
"no-undef": "error",
20+
"no-unused-vars": ["error", { vars: "all", args: "after-used", ignoreRestSiblings: false }],
21+
"mocha/no-setup-in-describe": [0],
22+
"mocha/no-mocha-arrows": [0],
23+
"no-only-tests/no-only-tests": [2],
24+
"jest/expect-expect": [0],
25+
},
26+
extends: ["prettier", "plugin:jest/recommended", "plugin:mocha/recommended"],
27+
overrides: [
28+
{
29+
files: ["test-e2e/**/integration/*.js"],
30+
rules: {
31+
"jest/valid-expect": [0],
32+
"jest/valid-expect-in-promise": [0],
33+
},
34+
},
35+
],
36+
root: true,
37+
};

.eslintrc.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
# NodeJS v17 still not supported in tests due to incompatibility with react-scripts
14-
node: ["12.22.7", "14.16.1", "15.14.0", "16.13.0"]
14+
node: ["12.22.7", "14.16.1", "16.13.0", "17.5.0"]
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v2
@@ -39,6 +39,8 @@ jobs:
3939
run: npm ci
4040
- name: Lint
4141
run: npm run lint
42+
- name: Check types
43+
run: npm run tsc
4244
- name: Test unit
4345
run: npm run test:unit
4446
- name: Test mutation

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# tests
1010
/coverage
11+
/dist
1112

1213
# misc
1314
.DS_Store

CHANGELOG.md

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

14+
## [1.7.0] - 2022-02-22
15+
16+
### Added
17+
- feat(#376): Support multiple snapshots allowing to define a name in save, restore and clear commands.
18+
- chore: Add command to check types. Run it in build workflow
19+
- chore: Add eslint plugins
20+
21+
### Removed
22+
- docs: Remove broken dependencies badge
23+
24+
### Changed
25+
- chore: Remove NodeJs v15 from tests workflow. Add NodeJs v17
26+
- chore(deps): Update devDependencies
27+
1428
## [1.6.1] - 2021-11-11
1529
### Changed
1630
- chore(#382): Use Cypress v9 in E2E tests

README.md

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Build status][build-image]][build-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Quality Gate][quality-gate-image]][quality-gate-url] [![Mutation testing status][mutation-image]][mutation-url]
22

3-
[![NPM dependencies][npm-dependencies-image]][npm-dependencies-url] [![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com) [![Last commit][last-commit-image]][last-commit-url] [![Last release][release-image]][release-url]
3+
[![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com) [![Last commit][last-commit-image]][last-commit-url] [![Last release][release-image]][release-url]
44

55
[![NPM downloads][npm-downloads-image]][npm-downloads-url] [![License][license-image]][license-url] [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjavierbrea%2Fcypress-localstorage-commands.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjavierbrea%2Fcypress-localstorage-commands?ref=badge_shield)
66

@@ -39,18 +39,24 @@ You can now use all next commands:
3939

4040
### Commands
4141

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

4444
Saves current localStorage values into an internal "snapshot".
4545

46-
##### `cy.restoreLocalStorage()`
46+
* `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.
4747

48-
Restores localStorage to previously "snapshot" saved values.
48+
##### `cy.restoreLocalStorage([snapshotName])`
4949

50-
##### `cy.clearLocalStorageSnapshot()`
50+
Restores localStorage to previously "snapshot" saved values. __
51+
52+
* `snapshotName` _(String)_: Optional. If provided, the localStorage will be restored using data from that specific snapshot.
53+
54+
##### `cy.clearLocalStorageSnapshot([snapshotName])`
5155

5256
Clears localStorage "snapshot" values, so previously saved values are cleaned.
5357

58+
* `snapshotName` _(String)_: Optional. If provided, only data from that specific snapshot will be cleared.
59+
5460
##### `cy.getLocalStorage(item)`
5561

5662
Gets localStorage item. Equivalent to `localStorage.getItem` in browser.
@@ -153,6 +159,44 @@ describe("localStorage cookies-accepted item", () => {
153159
});
154160
```
155161

162+
#### Named snapshots
163+
164+
Next example shows how named snapshots can be used to storage different states of `localStorage` and restore one or another depending of the test:
165+
166+
```js
167+
describe("Accept cookies button", () => {
168+
const COOKIES_BUTTON = "#accept-cookies";
169+
170+
before(() => {
171+
cy.clearLocalStorageSnapshot();
172+
});
173+
174+
it("should be visible", () => {
175+
cy.visit("/");
176+
cy.get(COOKIES_BUTTON).should("be.visible");
177+
cy.saveLocalStorage("cookies-not-accepted");
178+
});
179+
180+
it("should not exist after clicked", () => {
181+
cy.get(COOKIES_BUTTON).click();
182+
cy.get(COOKIES_BUTTON).should("not.exist");
183+
cy.saveLocalStorage("cookies-accepted");
184+
});
185+
186+
it("should be visible when cookies are not accepted", () => {
187+
cy.restoreLocalStorage("cookies-not-accepted");
188+
cy.visit("/");
189+
cy.get(COOKIES_BUTTON).should("be.visible");
190+
});
191+
192+
it("should not exist when cookies are accepted", () => {
193+
cy.restoreLocalStorage("cookies-accepted");
194+
cy.visit("/");
195+
cy.get(COOKIES_BUTTON).should("not.exist");
196+
});
197+
});
198+
```
199+
156200
### Disabling localStorage
157201

158202
Use `cy.disableLocalStorage()` to simulate that `localStorage` is disabled, producing that any invocation to `localStorage.setItem`, `localStorage.getItem`, `localStorage.removeItem` or `localStorage.clear` will throw an error. [As MDN docs recommend](https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem), _"developers should make sure to always catch possible exceptions from setItem()"_. This command allows to test that possible exceptions are handled correctly.
@@ -263,8 +307,6 @@ MIT, see [LICENSE](./LICENSE) for details.
263307
[license-url]: https://github.com/javierbrea/cypress-localstorage-commands/blob/master/LICENSE
264308
[npm-downloads-image]: https://img.shields.io/npm/dm/cypress-localstorage-commands.svg
265309
[npm-downloads-url]: https://www.npmjs.com/package/cypress-localstorage-commands
266-
[npm-dependencies-image]: https://img.shields.io/david/javierbrea/cypress-localstorage-commands.svg
267-
[npm-dependencies-url]: https://david-dm.org/javierbrea/cypress-localstorage-commands
268310
[quality-gate-image]: https://sonarcloud.io/api/project_badges/measure?project=javierbrea_cypress-localstorage-commands&metric=alert_status
269311
[quality-gate-url]: https://sonarcloud.io/dashboard?id=javierbrea_cypress-localstorage-commands
270312
[release-image]: https://img.shields.io/github/release-date/javierbrea/cypress-localstorage-commands.svg

index.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ declare namespace Cypress {
44
interface Chainable {
55
/**
66
* Command to save current localStorage values into an internal "snapshot"
7+
* @param {string} snapshotName - Name of the snapshot
78
* @example cy.saveLocalStorage()
89
*/
9-
saveLocalStorage(): Chainable<undefined>
10+
saveLocalStorage(snapshotName?: string): Chainable<undefined>
1011

1112
/**
1213
* Command to restore localStorage to previously "snapshot" saved values
14+
* @param {string} snapshotName - Name of the snapshot
1315
* @example cy.restoreLocalStorage()
1416
*/
15-
restoreLocalStorage(): Chainable<undefined>
17+
restoreLocalStorage(snapshotName?: string): Chainable<undefined>
1618

1719
/**
1820
* Command to clear localStorage "snapshot" values
21+
* @param {string} snapshotName - Name of the snapshot
1922
* @example cy.clearLocalStorageSnapshot()
2023
*/
21-
clearLocalStorageSnapshot(): Chainable<undefined>
24+
clearLocalStorageSnapshot(snapshotName?: string): Chainable<undefined>
2225

2326
/**
2427
* Command to get localStorage item value

0 commit comments

Comments
 (0)