1.0.2 • Published 5 years ago

@gustavnikolaj/scientist v1.0.2

Weekly downloads
3
License
ISC
Repository
-
Last release
5 years ago

Scientist!

npm version

A javascript library for carefully refactoring critical paths. Inspired by github/scientist.

$ npm install @gustavnikolaj/scientist

Quick start

const scientist = require("scientist");

function controlImplementationAdd2(x) {
  // This is the existing code path. The return value from this function will
  // be the one that is returned to the caller.

  return x + 2;
}

function experimentImplementationAdd2(x) {
  // This is your new experiment that you want to test

  return x * 2;
}

// By default the function returned from calling scientist will write output to
// stdout / stderr using console. You can provide a console-compatible object
// as an optional third argument: scientist(x, y, myConsole);
const add2 = scientist(controlImplementationAdd2, experimentImplementationAdd2);

add2(2);
// Passed: Both functions returned the same. { args: [ 2 ],
//                                             control: { return: 4 },
//                                             experiment: { return: 4 } }

add2(4);
// Failed: Experiment returned different value. { args: [ 4 ],
//                                                control: { return: 6 },
//                                                experiment: { return: 8 } }

More control

You can handle reporting yourself by using a lower level interface.

const { Experiment } = require("./");

function myScientist(
  controlImplementation,
  experimentImplementation,
  logger = console
) {
  const experiment = new Experiment(
    experimentImplementation,
    controlImplementation
  );

  experiment.handleReport = report => {
    // Do whatever you want with the report. This function is called whenever
    // your experiment has run.
  };

  return (...args) => experiment.run(...args);
}
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago