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

http-test-double

v0.1.0

Published

From your unit tests, interactively program a real HTTP server with expected requests and responses. Ideal for testing a component that makes HTTP requests to the outside world.

Downloads

5

Readme

TypeScript

Starting a new project:

# Create a package.json file
npm init 

Then:

# Install dev tools and add them to package.json
npm install typescript --save-dev
npm install tsd --save-dev
# Install dev dependencies, and add them to the package.json
npm install mocha --save-dev
npm install chai --save-dev
# Download type definitions for the dev dependencies above
# This creates a `tsd.json` file and `typed` directory
node_modules/.bin/tsd query chai --save --action install
node_modules/.bin/tsd query node --save --action install
node_modules/.bin/tsd query mocha --save --action install
# Set up some files for the VisualStudio Code editor (so you get intellisense help)
cat << EOF > tsconfig.json
{
    "compilerOptions": {
        "target": "ES3",
        "module": "commonjs",
        "sourceMap": true
    }
}
EOF
mkdir .settings
cat << EOF > tasks.json
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process

// A task runner that calls the Typescipt compiler (tsc) and 
// Compiles a HelloWorld.ts program
{
    "version": "0.1.0",
    "command": "make",
    // Show the output window only if unrecognized errors occur. 
    "showOutput": "always",
    "isShellCommand": true,
    "args": ["test"],
    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}
EOF
cat << EOF > .settings/launch.json
{
    "version": "0.1.0",
    // List of configurations. Add new configurations or edit existing ones.  
    // ONLY "node" and "mono" are supported, change "type" to switch.
    "configurations": [
        {
            // Name of configuration; appears in the launch configuration drop down menu.
            "name": "Launch make",
            // Type of configuration. Possible values: "node", "mono".
            "type": "node",
            // Workspace relative or absolute path to the program.
            "program": "main.js",
            // Automatically stop program after launch.
            "stopOnEntry": true,
            // Command line arguments passed to the program.
            "args": [],
            // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
            "cwd": ".",
            // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
            "runtimeExecutable": null,
            // Environment variables passed to the program.
            "env": { }
        }, 
        {
            "name": "Attach",
            "type": "node",
            // TCP/IP address. Default is "localhost".
            "address": "localhost",
            // Port to attach to.
            "port": 5858
        }
    ]
}
EOF
# Create a main script
cat << EOF > main.ts
export function main() {
    return "Hello world!";
};
EOF
# Create a test directory
mkdir test
cat << EOF > test/test.ts
/// <reference path="../typings/mocha/mocha.d.ts" />
/// <reference path="../typings/chai/chai.d.ts" />

import chai = require('chai');
var expect = chai.expect;
import main = require('../main');

describe('User Model Unit Tests:', () => {
    describe('2 + 4', () => {
        it('should be 6', (done) => {
            expect(2+4).to.equals(6);
            done();
        });

        it('should not be 7', (done) => {
            expect(2+4).to.not.equals(7);
            done();
        });
    });
});
describe('Main', () => {
    it('should return greeting', (done) => {
        expect(main.main()).to.equals("Hello World!");
        done();
    });
});
EOF
# Set up some project files
cat << EOF > .gitignore
node_modules
./*.js
test/*.js
EOF
cat << EOF > README.md
TypeScript
==========
EOF
cat << EOF > Makefile
.PHONY: test
build:
	node_modules/.bin/tsc --module commonjs test/test.ts

test: | build
	mocha
EOF

At this point you can:

  • Make a build with make
  • Run the tests with make test

Making a Release

Install:

npm install

Build the .js files and run the tests:

make test

Update the package.json file then publish to npm: