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 🙏

© 2026 – Pkg Stats / Ryan Hefner

freemock

v0.0.5

Published

Easy Mock for Node.js

Readme

freemock Easy Mock for Node.js , Mocha Compatibility , istanbul Compatibility

Install

npm install freemock

Example

var freemock = require('freemock');
freemock.start()
var mockObj = freemock.getMock(mod);
mockObj.setMethod({
    "method1":{
        willReturn:1,//假象方法将返回的值
        willCallback:function(){},//假象方法将执行的回调
        expectArgs:[1,2],//假象方法预期的参数
        willThrow:new Error(),//假象方法会返回的异常
        runTime:1//假象方法会被执行的次数
    },
    "method2":{
        willReturn:1,//假象方法将返回的值
        willCallback:function(){},//假象方法将执行的回调
        expectArgs:[1,2],//假象方法预期的参数
        willThrow:new Error(),//假象方法会返回的异常
        runTime:1//假象方法会被执行的次数
    },
    ...
})
freemock.end();

with Mocha

example - test.js

var freemock = require('freemock');
before(function() {})
after(function() {})
beforeEach(function() {
	freemock.start();
});
afterEach(function() {
	freemock.end();
});

describe("test", function() {
	describe("test hello", function() {
		it("flag exist", function() {
			var hello = require('./../hello');
			var result = hello.hello(true);
		});
		it("flag not exist", function() {
			var mock_util = freemock.getMock('./shit');
			mock_util.setMethod({
				util: {
					expectArgs: [function(){}],
					willReturn: 1
				}
			})
			var hello = require('./../hello');
			hello.hello();
		})
	})
})

with Mocha and istanbul

example

run.js
var Mocha = require('mocha');
var mocha = new Mocha;
mocha.addFile(__dirname+'/test/hello.test.js')
mocha.run();
test.js
var freemock = require('freemock');
freemock.setIgnore(['./util'])//加上这个方法,让istanbul不检测这个模块
before(function() {})
after(function() {})
beforeEach(function() {
	freemock.start();
});
afterEach(function() {
	freemock.end();
});
describe("test", function() {
	describe("test hello", function() {
		it("flag exist", function() {
			var hello = require('./../hello');
			var result = hello.hello(true);
		});
		it("flag not exist", function() {
			var mock_util = freemock.getMock('./util');
			mock_util.setMethod({
				util: {
					expectArgs: [1],
					willReturn: 1
				}
			})
			var hello = require('./../hello');
			hello.hello();
		})

	})
})

command: istanbul cover run.js

freemock.setMethod(options)

options:

  • willReturn //假象方法将返回的值
  • willCallback //假象方法将执行的回调
  • expectArgs //假象方法预期的参数
  • willThrow //假象方法会返回的异常
  • runTime //假象方法会被执行的次数