treest
v0.2.3
Published
Real-automatic testing.
Downloads
57
Readme
treest
Real-automatic testing.
Concept
Look at folder __fixtures__
. We have 4 modules: module1
, module2
, module3
and ClassA
. Every module has own exports, like, functions or classes.
We want to have the unit tests for all of it.
BUT, we don't want to write it. Ok, Treest can do this instead of us!
Just call any function or method of class, which call some another function and Treest will be log (save to files) all calls, sub-calls and sub-sub-calls (so, Treest is TREE's teSTing).
Next time, when we start an executing of this function, Treest will compare the old and the new result (with same arguments) and throw error, if they will be different.
Restrictions
Treest logged the arguments and results of all functions, so, it imposes some restrictions. Shortly, Treest can work only with serializable objects.
Treest supports all primitive js-types: boolean, plain-object, array, string, number, null, undefined.
Treest supports object, created by class or prototype. For passing by reference, Treest used a method toJSON of class for saving a state of object (really, Treest just used JSON.stringify).
Treest don't support the anonymouses functions, i know, it is big problem, but you can use property of class, like this:
class A {
public method1 = () => {
// this.anotherMethod(); this exists in context
};
}
function b(func: ()=>void){
func();
}
const a = new A();
b(a.method1);
Install
npm install treest --save
or
yarn add treest
Usage
import { Treest } from "treest";
const treest = new Treest();
const module1 = treest.require("./module1"); // require js-module with export-function `hello`
module1.hello("world"); // call function, log all sub-calls and write it to __treest__/%modulename%.json
//look at folder __treest__
API
interface ITreestConfig {
mode?: string;
mocks?: { [index: string]: () => any };
ignoreMockModules?: string[];
reporter?: typeof console;
knownClasses?: Array<{
class: any;
name: string;
}>;
realRequire?: typeof require;
}
Test
npm install
npm test