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

ab-test-middleware

v0.1.8-alpha

Published

An express middleware that manages multiple distributions for A/B/N testing purposes.

Downloads

4

Readme

ab-test-middleware

A middleware that provides an easy way to serve multiple distributions in order to run A/B/N tests.

NOTE: The middleware expects a set of production ready distributions to be built prior to using it on an app.

Usage (the TL;DR version)

Assuming your distributions are built already and available in your build folder. I suggest using navikt/ab-test/actions/build@v1 if you're running your deployments by means of GitHub Actions. The build folder should be created with the following structure:

build/
 ├── release-v1.0.0
 ├── new-design
 ├── ...
 └── login-button-placement
const express = require('express');
const { createAbTestMiddleware } = require('ab-test-middleware');

const app = express();

/**
* A function to assign a test group to an inconming request.
* @param {string} distName Distribution name sent the middleware in order 
* to know whether to assign that particular distribution to the request or not. 
* A cookie will be set in the response if the function returns a true value.  
* @returns {boolean} Boolean value that determines if the user is to be assigned 
* to the distribution's test group. 
*/
const testGroupToggleInterpreter = (distName) => {
    let enabled = false;
    // Write your logic here. Alternately make use of a feature toggle mechanism here.    
    return enabled;
}

/**
* A function that checks whether distributions are enabled and should be servable.
* @param {string} distName Distribution name sent the middleware in order to know
* whether that particular distribution is enabled or not. Disabled distributions
*  will not be served and lead to the re-assignation of a request to a different distribution.  
* @returns {boolean} Boolean value that determines if the distribution is enabled and servable. 
*/
const distributionToggleInterpreter = (distName) => {
    let enabled = false;
    // Write your logic here. Alternately make use of a feature toggle mechanism here.    
    return enabled;
}

app.use(createAbTestMiddleware({
  defaultDist: 'release-v1.0.0',            // name of the distribution (default: 'master')
  distFolder: 'build',                      // name of the distribution folder (default: 'dist') 
  cookieName: 'distributionName',           // name of the cookie to be set on test group assignation (default: 'testGroup')
  entryFile: 'landing-page.html',           // name of the entry file for your distribution (default: 'index.html')
  ingresses: ['/'],                         // array containing application ingresses (default: ['/'])
  randomizeTestGroupDistribution: true,     // whether to randomize the test group assignation (default: false)
  testGroupToggleInterpreter: testGroupToggleInterpreter,
  distributionToggleInterpreter: distributionToggleInterpreter,
}));

app.listen(3000);

Note:

If the randomizeTestGroupDistribution flag is omitted or set to false, it will result in an alphabetically ordered loop when assigning test groups to requests in the middleware. It is highly recommended to set this flag to true in cases where the testGroupToggleInterpreter does not account for randomization or does not count on a persistent distribution assignation tracking mechanism such as a feature toggle service.