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

pact

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pact

Vows macros for easy HTTP server testing.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
decreased by-19.34%
Maintainers
0
Weekly downloads
 
Created
Source

Pact

A collection of Vows macros for easy HTTP server testing.

Tastes great with Express and Connect.

Works with Node.js v0.2.5 and later.

Documentation

http://reid.github.com/pact/

Installation

npm i pact

Example

// Pact works with http.Server instances.
// This includes express.Server, connect.Server, etc.
// This method returns a new express.Server:
var createServer = require("../lib/app").createServer;

require("vows").describe("HTTP Server").addBatch({
    "A server in development" : {
        // Start a server for testing with httpify
        // Give it a new http.Server
        topic : httpify(createServer()),
        "when /foo is requested" : {
            topic : request(), // knows the URL from context name
            "should fail" : code(400) // check status code
        }
        "when /foo?bar=baz is requested" : {
            topic : request(),
            "should succeed" : code(200),
            "should return response time header" : function (topic) {
                // header names are lowercased for easy testing
                assert.include(topic.headers, "x-response-time");
            },
            "should be correct size" : function (topic) {
                // response is available as topic.body
                assert.equal(topic.body.length, 11);
            }
        },
        "when making a bogus request" : {
            // you can always specify your own URL
            // POST requests work as well
            topic : request({
                url : "/bogus",
                method : "POST",
                body : "quux=0"
            }),
            "should fail" : code(404)
        }
    },
    "A server in production" : {
        topic : function () {
            // Example: wrap httpify for testing
            // with a new environment
            var oldEnv = process.env.NODE_ENV;
            process.env.NODE_ENV = "production";
            var server = app.createServer();
            httpify(server).apply(this);
            process.env.NODE_ENV = oldEnv;
        },
        "when / is requested" : {
            topic : request(),
            "should fail" : code(404)
        }
    }
}).export(module);

Run self-tests

Requires Vows.

make test

About

Authored by Reid Burke, copyright Yahoo! Inc., and provided under the BSD license. See LICENSE file.

History

Pact is used at Yahoo! for testing Node.js servers. It's based on the embedded Vows macros from the YUI Labs Yeti project.

Bugs

Submit bugs and pull requests to Pact on GitHub.

Keywords

FAQs

Package last updated on 29 Mar 2011

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