Registry / testing / get-data-from-cache

get-data-from-cache

JSON →
library1.0.26jsnpmunverified

A Cypress plugin for caching data across tests, eliminating redundant API calls and improving test reliability. Current stable version is 1.0.26 (active development, frequent updates). Key differentiator: simple key-value cache within Cypress's task system, with TypeScript support. Compared to cy.fixtures or manual global variables, it provides a dedicated, typed cache mechanism with automatic cleanup between test suites.

npm install get-data-from-cache
INSTALL
IMPORT
SIG · GET-DATA-FROM-CACH
G
get-data-from-cache
testingjavascriptv1.0.26
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export (plugin function)
const cachePlugin = require('get-data-from-cache');
import cachePlugin from 'get-data-from-cache';
Cypress config files use CommonJS (require) by default; ESM imports may fail in Node <14 or without module type.
cy.task('putDataInCache')
cy.task('putDataInCache', { key: 'myKey', data: myData })
cy.task('putDataInCache', 'myKey', myData)
Second argument must be an object with `key` and `data` properties; plain strings will cause errors.
cy.task('getDataFromCache')
cy.task('getDataFromCache', 'myKey').then((data) => { ... })
cy.task('getDataFromCache', { key: 'myKey' })
Second argument is the key string directly, not an object. Returns empty string if key missing.

Configures the plugin in Cypress and demonstrates putting and getting data from cache across two tests.

// cypress.config.ts const { defineConfig } = require('cypress'); const cachePlugin = require('get-data-from-cache'); module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { cachePlugin(on, config); return config; } } }); // cypress/e2e/cacheExample.cy.ts describe('Cache Example', () => { it('stores and retrieves data', () => { cy.task('putDataInCache', { key: 'token', data: 'abc123' }); }); it('uses cached data', () => { cy.task('getDataFromCache', 'token').then((token) => { cy.request({ url: '/api/data', headers: { Authorization: `Bearer ${token}` } }); }); }); });
Debug
Known issues
breakingCypress version compatibility: only Cypress >=10.0.0 and <13.0.0 are supported. Version 13 introduced breaking changes.
fix
Use Cypress 10, 11, or 12. Check peerDependencies in package.json.
affects: <1.0.0
gotchaCache is cleared between test suites (describe blocks); data persists only within the same suite.
fix
Ensure put and get tasks are in the same describe block or use cy.writeFile/cy.readFile for suite-spanning data.
affects: all
gotchaThe getDataInCache task returns empty string for missing keys, not null or undefined.
fix
Check for empty string: `if (data !== '')` instead of truthiness checks.
affects: all
deprecatedCommonJS require is required in Cypress config; ESM import may fail.
fix
Use require() in cypress.config.js/ts until Cypress natively supports ESM config.
affects: all
Errors
Common errors & fixes
Error: The task 'putDataInCache' was not handled. Registered tasks are: ...
The cachePlugin was not called in setupNodeEvents.
fix
Add `cachePlugin(on, config);` inside `setupNodeEvents` in cypress.config.ts.
TypeError: cachePlugin is not a function
Importing the module incorrectly (e.g., using ES import without proper default import).
fix
Use `const cachePlugin = require('get-data-from-cache');` in CJS context.
AssertionError: expected '' to equal 'testuser'
Cache key was put in a different describe block or the cache was cleared between tests.
fix
Ensure put and get tasks are in the same describe block.
Upgrade
Version history
1.0.26latest on npm
Audit
Dependencies
cypressrequiredpeer dependency: requires Cypress >=10.0.0 <13.0.0
Agent activity
2 hits · last 30 days
node
2
Resources
get-data-from-cache — npm install get-data-from-cache · libregistry