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();
const testGroupToggleInterpreter = (distName) => {
let enabled = false;
return enabled;
}
const distributionToggleInterpreter = (distName) => {
let enabled = false;
return enabled;
}
app.use(createAbTestMiddleware({
defaultDist: 'release-v1.0.0',
distFolder: 'build',
cookieName: 'distributionName',
entryFile: 'landing-page.html',
ingresses: ['/'],
randomizeTestGroupDistribution: true,
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.