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

mummy

v3.0.2

Published

Tools for using Zombie.js with Hapi.

Downloads

47

Readme

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).