https://github.com/ymzuiku/inline-test
In Project Line Test
https://github.com/ymzuiku/inline-test
Last synced: about 2 months ago
JSON representation
In Project Line Test
- Host: GitHub
- URL: https://github.com/ymzuiku/inline-test
- Owner: ymzuiku
- License: mit
- Created: 2020-11-18T10:47:52.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-18T17:55:20.000Z (over 4 years ago)
- Last Synced: 2025-02-20T14:19:03.525Z (2 months ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# inline-test
- In server run test
## Install
npm:
```sh
$ npm install --save inline-test
```## Env
`inline-test` run at `process.env.e2e` is true:
```sh
e2e=1 yarn start
```or in index.js, set `process.env.e2e`:
```js
process.env.e2e = 1;
```## API
```ts
inlineTest(index:number, message:string, (it, cache) => any);
```### it
```ts
type it = (message: string, target: any) => { equal: (value) => target, check:(fn:(value:any, deepEqual:Function)=>boolean) };
``````ts
import inlineTest from "inline-test";inlineTest(2, "Test login", (it) => {
const testA = () => {
throw "dog";
};
it("Test throw", testA()).equal("dog"); // passconst testB = () => {
return new Promise((res) => {
setTimeout(() => {
res("cat");
}, 100);
});
};
it("Test Promise", testB()).check((v) => v === "cat"); // pass
});
```### cache
```ts
type cache = { [key: string]: any };
```cache is global in some inlineTest();
```ts
import inlineTest from "inline-test";inlineTest(2, "Test login", (it, cache) => {
console.log(cache); // {}
});
```## Example
```js
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();
```