Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@this-dot/cypress-indexeddb
Advanced tools
A Cypress.io helper library for reading and manipulating data inside IndexedDB
Cypress IndexedDB helpers are a set of custom cypress commands that helps you handle indexedDB related operations in your Cypress tests.
It supports:
✅ Creating new IndexedDB databases and Object Stores
✅ Making CRUD operations on the above-mentioned stores
✅ Read data out of indexedDB and assert the results
Install the package:
npm install @this-dot/cypress-indexeddb
or
yarn add @this-dot/cypress-indexeddb
Import the plugin in your cypress/support/commands.js
or cypress/support/commands.ts
file:
import '@this-dot/cypress-indexeddb';
If you use typescript, set up typings in the same support
folder
cypress-indexeddb-namespace.ts
filedeclare namespace Cypress {
interface Chainable<Subject> {
clearIndexedDb(databaseName: string): void;
openIndexedDb(databaseName: string, version?: number): Chainable<IDBDatabase>;
getIndexedDb(databaseName: string): Chainable<IDBDatabase>;
createObjectStore(
storeName: string,
options?: IDBObjectStoreParameters
): Chainable<IDBObjectStore>;
getStore(storeName: string): Chainable<IDBObjectStore>;
createItem(key: string, value: unknown): Chainable<IDBObjectStore>;
readItem<T = unknown>(key: IDBValidKey | IDBKeyRange): Chainable<T>;
updateItem(key: string, value: unknown): Chainable<IDBObjectStore>;
deleteItem(key: string): Chainable<IDBObjectStore>;
addItem<T = unknown>(value: T): Chainable<IDBObjectStore>;
keys(): Chainable<IDBValidKey[]>;
entries<T = unknown>(): Chainable<T[]>;
}
}
In order to make your tests reliable, before every test it is recommended to clear the existing database. You can do it by using the cy.clearIndexedDb('databaseName')
command.
beforeEach(() => {
cy.clearIndexedDb('EXAMPLE_DATABASE');
// ...
cy.visit('/');
});
In order to create an object store, first, you need to initiate a database connection by calling the cy.openIndexedDb('databaseName')
command and use the as
chainer to store it with an alias.
cy.openIndexedDb('EXAMPLE_DATABASE').as('database');
The openIndexedDb
command supports providing a database version number optionally
cy.openIndexedDb('EXAMPLE_DATABASE', 12) // initiate with database version 12
.as('database');
You can access the aliased database with the getIndexedDb('@yourAlias')
command.
You can chain off the createObjectStore('storeName')
method from methods that yield an IDBDatabase
instance (openIndexedDb
or getIndexedDb
). You can use the as
chainer to save the store using an alias.
cy.getIndexedDb('@database').createObjectStore('example_store').as('exampleStore');
You can also pass an optional options parameter to configure your object store. For example, you can create an object store with autoIncrement
with the following command:
cy.getIndexedDb('@database')
.createObjectStore('example_autoincrement_store', { autoIncrement: true })
.as('exampleAutoincrementStore');
You can retrieve the saved object store using the cy.getStore('@exampleStore')
;
You can chain off CRUD operation methods from methods that yield an IDBObjectStore
instance (createObjectStore
or getStore
).
The createItem
, updateItem
and the deleteItem
methods yield the store, therefore, you can chain these methods to save multiple entries into the target Object Store.
cy.getStore('@exampleStore')
.createItem('example', { test: 'test' }) // creates the 'example' key and saves the second parameter as the value.
.updateItem('example', { test: 'replace' }) // updates the 'example' key's value with the second parameter.
.deleteItem('example') // deletes the 'example' key
.createItem('example2', ['testValue', 'testValue2'])
.createItem('example3', { exampleKey: 1337 });
The readItem
method yields the value of the provided key, or undefined if it does not exist. You can chain assertions from this method. If you use TypeScript, you can set the type of the returned value.
cy.getStore('@exampleStore').readItem<string[]>('example2').should('have.length', 2);
cy.getStore('@exampleStore')
.readItem<number>('example3')
.should('have.property', 'exampleKey', 1337);
When you need to manipulate or assert data stored in an Object Store, that was set up with { autoIncrement: true }
, you have the following commands at your disposal: addItem
, keys
and entries
.
The addItem
method stores the provided value into the Object Store at a new index
cy.getStore('@exampleAutoincrementStore').addItem('test').addItem({ test: 'object' }).addItem(1337);
The keys
method returns an IDBValidKey[]
. You can assert the results using the .should()
method.
cy.getStore('@exampleAutoincrementStore')
.keys()
.should('have.length', 3)
.and('deep.equal', [1, 2, 3]);
The entries
method returns all the values that are stored in order. You can assert the results using the .should()
method.
cy.getStore('@exampleAutoincrementStore')
.entries()
.should('have.length', 3)
.and('deep.equal', ['test', { test: 'object' }, 1337]);
Feel free to check our cypress tests in our git repository for some examples.
FAQs
A Cypress.io helper library for reading and manipulating data inside IndexedDB
The npm package @this-dot/cypress-indexeddb receives a total of 2,783 weekly downloads. As such, @this-dot/cypress-indexeddb popularity was classified as popular.
We found that @this-dot/cypress-indexeddb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.