0.2.2 • Published 4 years ago
inline-test v0.2.2
inline-test
- In server run test
Install
npm:
$ npm install --save inline-test
Env
inline-test
run at process.env.e2e
is true:
e2e=1 yarn start
or in index.js, set process.env.e2e
:
process.env.e2e = 1;
API
inlineTest(index:number, message:string, (it, cache) => any);
it
type it = (message: string, target: any) => { equal: (value) => target, check:(fn:(value:any, deepEqual:Function)=>boolean) };
import inlineTest from "inline-test";
inlineTest(2, "Test login", (it) => {
const testA = () => {
throw "dog";
};
it("Test throw", testA()).equal("dog"); // pass
const testB = () => {
return new Promise((res) => {
setTimeout(() => {
res("cat");
}, 100);
});
};
it("Test Promise", testB()).check((v) => v === "cat"); // pass
});
cache
type cache = { [key: string]: any };
cache is global in some inlineTest();
import inlineTest from "inline-test";
inlineTest(2, "Test login", (it, cache) => {
console.log(cache); // {}
});
Example
import inlineTest from "inline-test";
inlineTest(1, "Test Sign", async (it, cache) => {
const token = await it(
"Test fetch"
fetch("http://localhost:3000/sign/?username=abc&password=123")
).check(v=>v.code === 200);
// save token in cache
cache.token = token;
});
inlineTest(2, "Test login", (it, cache) => {
await it(
"Test use token"
fetch(
"http://localhost:3000/login/?username=abc&token=" + cache.token
),
{ code: 200, message: "logined" },
).check(v=> v.code === 200 );
});
inlineTest.start();