Giter VIP home page Giter VIP logo

pact's Introduction

Pact

Build Status

A collection of Vows macros for easy HTTP server testing.

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.

pact's People

Contributors

reid avatar rgrove avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.