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

nightmare-gremlins

v1.0.2

Published

Monkey testing via Gremlins.js for Nightmare.js

Downloads

8

Readme

Nightmare Gremlins

Gremlin.js actions for Nightmare.js to allow for monkey testing

Running Gremlins in Nightmare

Introduction

Nightmare Gremlins is an action and collection of tasks for Nightmare.js that allows for monkey testing via the Electron app.

There are two ways to use this npm:

  1. Singular action that extends the Nightmare prototype via Nightmare.action

  2. Series of individual tasks to be consumed by a Nightmare instance via nightmare.use.

Singular Action

The Nightmare prototype can be extended by using the Nightmare.action method:

import Nightmare from 'nightmare';
import gremlins from 'nightmare-gremlins';

Nightmare.action('gremlins', gremlins);
const nightmare = Nightmare();

const gremlinOptions = {
  seed: Date.now(),
  unleash: {
    nb: 10000,
  },
  wait: {
    maxErrors: 100,
    maxTime: 10 * 1000,
  },
};

nightmare
  .goto('https://google.com')
  .gremlins(gremlinOptions) // Run gremlins on the page
  .then((errors) => { console.log('Page errors:\n', errors); });

Series of tasks

Alternatively, Nightmare Gremlins also exposes a series of individual functions that can be used on an instance of Nightmare for custom composing via .use:

import Nightmare from 'nightmare';
import * as gremlins from 'nightmare-gremlins';

Nightmare.action('gremlins', gremlins);
const nightmare = Nightmare();

const gremlinOptions = {
  seed: Date.now(),
  unleash: {
    nb: 10000,
  },
  wait: {
    maxErrors: 100,
    maxTime: 10 * 1000,
  },
};

const errors = [];

nightmare
  .use(gremlins.recordErrors(errors))
  .use(gremlins.injectGremlins())
  .use(gremlins.createHorde())
  .use(gremlins.seedHorde(gremlinOptions.seed))
  .use(gremlins.unleashHorde(gremlinOptions.unleash))
  .use(gremlins.waitForGremlins(errors, gremlinOptions.wait))
  .then((errors) => { console.log('Page errors:\n', errors); });

By using a series of tasks, it is possible to add individual steps or functionality:

...

const errors = [];

nightmare
  .use(gremlins.recordErrors(errors))
  .use(gremlins.injectGremlins())
  .evaluate((seed) => {
    const horde = window.gremlins.createHorde();
    horde.seed(seed);
    horde.unleash();
  }, Date.now())
  .use(gremlins.waitForGremlins(errors, gremlinOptions.wait))
  .then(() => { console.log('Page errors:\n', errors); });

Available Actions

Nightmare Gremlins exposes the following tasks (with arguments and defaults):

  • recordErrors(Array - []) - adds a listener to the page that will look for all errors and push the error message and stack onto the array passed in
  • injectGremlins - injects a specially modified version of the gremlins.js script that supports keyboard entry on Electron
  • createHorde - runs a script on the page that creates a horde under the window.horde namespace
  • seedHorde(Number|String - Date.now()) - seeds the horde with a specific number to allow for behavior replication
  • unleashHorde(Object - {}) - runs a script on the page that unleashes the horde with the options argument having been JSON serialized and deserialized to be passed to the browser
  • waitForGremlins(Object - {maxTime: 10000, maxErrors: 100}) - a waiting function that looks for 1 of 2 conditions to be met: time passed is longer than maxTime or the number of errors recorded is greater than maxErrors

Bonus Action

Nightmare Gremlins includes an additional "super task", that is the same as the action used to extend the Nightmare prototype, but intended to be used on an instance instead:

import Nightmare from 'nightmare';
import {unleashGremlins} from 'nightmare-gremlins';

const nightmare = Nightmare();

const gremlinOptions = {
  seed: Date.now(),
  unleash: {
    nb: 10000,
  },
  wait: {
    maxErrors: 100,
    maxTime: 10 * 1000,
  },
};

nightmare
  .use(unleashGremlins(gremlinOptions))
  .then((errors) => { console.log('Page errors:\n', errors); });