Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
flush-cache
Advanced tools
Flushes the internal node cache, useful (and recommended) when testing apps
Flushes the internal node cache, useful (and recommended) when testing apps.
The node cache itself is useful and often needed, but when it comes to test you don't want to cache your modules which you are testing. This forces you to write isolated tests, which is a good thing.
We'll install and save flush-cache so we can use it locally for our tests:
npm i flush-cache --save-dev
or, if you use yarn:
yarn add flush-cache --dev
Require flush-cache and invoke the function to clear the whole cache.
something.js
console.log('such logs, much wows!')
test.js
const flush = require('flush-cache')
require('./something') // such logs, much wows!
flush()
// completely uncached & fresh object here:
require('./something') // such logs, much wows!
flush-cache deletes every require cache object, so when you require modules recursively, their cache gets flushed too.
You should add the flush method in a beforeEach
in a describe
or in a separate test file when you want to flush the cache in every single it
.
const flush = require('flush-cache')
beforeEach(flush)
beforeEach(function () {
this.myObject = require('...')
})
// or put both methods in a single method
beforeEach(function () {
flush()
this.myObject = require('...')
})
it('should test my object', function () {
// this.myObject is now a fresh object in every single test case!
})
You should add the flush method in a beforeEach
.
import test from 'ava'
import flush from 'flush-cache'
test.beforeEach(flush)
test.beforeEach(t => {
t.context.myObject = require('...')
})
test('first', t => {
// t.context.myObject is now a fresh object in every single test case!
})
Most modules expect the require
command to always be cached, so some modules
may break. If you detect modules which break this module, create an issue or a
PR.
Current require caches which are ignored:
FAQs
Flushes the internal node cache, useful (and recommended) when testing apps
We found that flush-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.