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

wallaby-worker-manager

v0.1.6

Published

Manage setup of wallaby workers

Downloads

5

Readme

Wallaby Worker Manager

Simple script that makes it easy to perform a task upon initialization of a wallaby worker, and run a separate task on every subsequent run of a Wallaby worker.

How it works

In order to speed up test runs Wallaby can be configured to spawn multiple worker processes.

This can have unintended consequences on your tests if, for example, the tests run against a database.

In this case, tests running in one worker will impact tests running at the same time in a separate worker and provide inconsistent results.

In order to isolate your test workers, you may want to perform some specific setup and cleanup on a worker by worker basis.

This can be done in the wallaby.config.js file, by using the wallaby.workerId variable.

While this is helpful it can get messy trying to keep track of your worker setup and cleanup actions. This package is designed to make that easier.

Usage

Install npm install wallaby-worker-manager

Create a worker class in your project (code shown written in Typescript)

import { GenericWorker } from 'wallaby-worker-manager';

export class Worker extends GenericWorker {

  public async onInit()  {

    // Run any asychronous actions here that should take place when the Wallaby Worker is initialized
    // For example, create a new database server
    // You can access the wallaby variables with `this.wallaby`

  }

  public async onEach() {

    // Run any asynchronous actions here that should take place every time this Wallaby Worker starts a test run
    // For example, close any active/idle connections to the database server, truncate the data and run the migration script
    // You can access the wallaby variables with `this.wallaby`

  }

}

Update your wallaby.config.js

  setup: function(wallaby) {

    // Since this is a typescript project we are going to load our worker class from the projectCacheDir
    // where wallaby has compiled it into js

    var worker = require(wallaby.projectCacheDir + '/src/wallaby-worker.js'); // path to your Worker class

    // requeire this library
    var workerManager = require('wallaby-worker-manager');
    
    // initialize the worker manager by passing in the `wallaby` parameter, and the reference to your worker class.
    workerManager.Setup(wallaby, worker.Worker);

  },

Notes

The onInit function will run the first time Wallaby spawns a worker then it will run the onEach function. From then on, only the onEach function will run in response to code changes.

Keep in mind, that onEach runs before a group of tests runs, not before each individual test. You still need to take care of resetting your data using the beforeEach method of your testing framework of choice.

For example, lets say you make a code change and Wallaby decides it needs to re-run three tests based on that change. The onEach method will run once and then the three tests will run.

Within the onInit and onEach functions you can access the wallaby variable from the setup function with this.wallaby.

This is helpful for altering your configuration on a worker by worker basis. For example, you could use this.wallaby.workerId in order to have each worker spawn a docker postgres database attached to different ports.

From within your application code you can use the global variable global['_wallabyWorker'] to access the instance of the worker class created for this worker.