Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flush-cache

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flush-cache

Flushes the internal node cache, useful (and recommended) when testing apps

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

flush-cache

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.

usage

common

Require flush-cache and invoke the function to clear the whole cache.

something.js

console.log('such logs, much wows!')

app.js

const flush = require('flush-cache')

require('./something') // such logs, much wows!

flush()

// completely uncached & fresh object here:
require('./something') // such logs, much wows!

examples

mocha

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!
})

ava

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!
})

Keywords

FAQs

Package last updated on 09 Jan 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc