npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flush-cache

v1.0.1

Published

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

Downloads

31,641

Readme

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

install

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

common

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.

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

gotchas

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:

  • deasync