Coder Social home page Coder Social logo

mummy's Introduction

mummy

Build Status

Tools for using Zombie.js with Hapi.

npm install mummy

Overview

mummy is a browser extension for the Zombie.js headless browser testing framework that allows automatic binding of Browser instances to Hapi servers.

var Browser = require("zombie");
var Mummy   = require("mummy");
var browser;

Browser.extend(new Mummy(server));
browser = new Browser();

browser.visit("/")
.then(function () {
	. . .
});

Extending the Browser API

Zombie provides an extension API that allows all new Browser objects to be augmented with additional functionality. Using this approach, mummy will cause all Browser objects to direct their requests to the wrapped Hapi server. Only requests with URLs matching the hostname and port of one of the connections on the server will be injected. All other requests will be processed normally.

Wrapping a Single Browser

Alternatively, mummy can wrap a single Browser instance as follows:

var Browser = require("zombie");
var Mummy   = require("mummy");

var browser = new Browser();
Mummy.embalm(server, browser);

Event Loop Management

Zombie does not continually evaluate the browser event loop. Rather, it runs the event loop in relatively short bursts at keep times to drive browser functionality. In many cases this is fine. However, sometimes it is useful for test cases to queue events after the initial page load or separate from a user interaction (i.e. browser.pressButton(...)). In these cases it is useful to run the event loop for the entire duration of the test. This can be done with something like the following:

describe("an async interaction", function () {
	before(function() {
		browser.runner.start();
		browser.window.doSomethingInTheFuture();
	});

	after(function () {
		browser.runner.stop();
	});

	it("eventually does something", ...);
});

Raw HTTP Requests

mummy also provides the ability to make "raw" HTTP requests to wrapped servers. This can be useful for testing REST APIs. For example:

var browser = new Browser();

browser.http({ method : "GET", url : "/" }).then(function (response) {
	expect(response.statusCode).to.equal(200);
});

API

Mummy(server)

  • server -- a Hapi Server instance to create a Browser extension for.

Returns a Browser extension suitable for passing to Zombie's Browser.extend().

Mummy.embalm(server, browser)

  • server -- a Hapi Server instance to inject requests into.
  • browser -- a Browser instance to augment with request redirection.

Returns the original Browser instance after it has been augmented to redirect requests to the server.

browser.credentials.set(credentials)

  • credentials -- an object containing simulated authentication information

Update the browser state to bypass the normal authentication strategies when requests are sent to Hapi. See the Hapi documentation for more details.

browser.credentials.clear()

Clear any browser credentials. This will cause normal authentication flows to be used for requests sent to Hapi.

browser.runner.start()

Causes Zombie to continually execute the event loop until manually stopped. This is useful for test suites that schedule events after the initial page load. Returns a promise that is resolved when the event loop has stopped.

browser.runner.stop()

Stops the event loop when it has been started with browser.runner.start().

browser.http(options, [callback])

  • options -- an object representing the request.
  • callback -- Optional a callback function receiving arguments of the form (error, response) depending on if the response is successful. If not provided, a promise is returned.

The options hash can include the following:

  • method -- the HTTP request method. Defaults to "GET".
  • url -- the path or URL to request. Defaults to "/".
  • headers -- an object defining request headers.

Performs a "raw" HTTP request. The server.inject() method from Hapi is used for requests to wrapped servers while Request is used for requests to URLs not belonging to wrapped servers. Additional options are supported for both (see the respective docs for details).

mummy's People

Contributors

jagoda avatar

Stargazers

PaulZeng avatar Nelson avatar Tyler Cross avatar

Watchers

James Cloos avatar

mummy's Issues

Only match localhost requests

Version 0.1 has all requests being intercepted and injected. Requests to hosts other than localhost (set as the browser default site) should not be injected.

Extend Browser with manifest

Would be convenient to be able to extend the Browser interface using a pack manifest. This is useful if writing a full test suite against a single application.

Pack support

Support injection into a pack of servers. This likely requires needing to resolve the server to inject into based on a host and/or port.

Pack starts multiple times

Creating multiple browsers from the same pack causes the pack start-up simulation to run multiple times.

Compose server from manifest file

Should be able to compose a server if mummy.embalm() is given a file path instead of a server object. Should allow optionally setting the relativeTo path for plugin loading (should default to the parent directory of the manifest?).

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.