change files structure
This commit is contained in:
parent
3210e72b22
commit
1ed6449ac6
30 changed files with 7 additions and 7 deletions
72
server/test/core/test_core.ts
Normal file
72
server/test/core/test_core.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import { delay } from "../../src/core/helper/delay.js";
|
||||
import { Result } from "../../src/core/helper/result";
|
||||
import { TypedEvent } from "../../src/core/helper/typed_event.js";
|
||||
|
||||
export class TestCore {
|
||||
allTests = 0;
|
||||
testErr = 0;
|
||||
testOk = 0;
|
||||
private static _instance: TestCore;
|
||||
|
||||
public static get instance() {
|
||||
return this._instance || (this._instance = new this());
|
||||
}
|
||||
|
||||
assert = (test: boolean, testName: string) => {
|
||||
this.allTests += 1;
|
||||
if (test) {
|
||||
console.log("\x1b[32m", "✅ - " + testName);
|
||||
this.testOk += 1;
|
||||
return;
|
||||
}
|
||||
this.testErr += 1;
|
||||
console.log("\x1b[31m", "❌ - " + testName);
|
||||
};
|
||||
|
||||
testResult = () => {
|
||||
console.log("\x1b[32m", "=============");
|
||||
|
||||
if (this.allTests - this.testOk === 0) {
|
||||
console.log(
|
||||
"\x1b[32m",
|
||||
`✅ All test success! ${this.allTests}/${this.testOk}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (this.testErr !== 0) {
|
||||
console.log("\x1b[31m", "❌ test error:" + String(this.testErr));
|
||||
console.log("\x1b[32m", `✅ test success! ${this.testOk}`);
|
||||
}
|
||||
};
|
||||
resultTest = async (
|
||||
eventClass: TypedEvent<Result<any, any>> | any,
|
||||
args: any,
|
||||
testName: string,
|
||||
isOk: boolean,
|
||||
delayTime = 1000
|
||||
) => {
|
||||
let testIsOk = false;
|
||||
eventClass.call(...args);
|
||||
const listener = eventClass.on(
|
||||
(e: {
|
||||
fold: (arg0: (_s: any) => void, arg1: (_e: any) => void) => void;
|
||||
}) => {
|
||||
e.fold(
|
||||
() => {
|
||||
if (isOk) {
|
||||
testIsOk = true;
|
||||
}
|
||||
},
|
||||
() => {
|
||||
if (!isOk) {
|
||||
testIsOk = true;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
await delay(delayTime);
|
||||
this.assert(testIsOk, testName);
|
||||
listener.dispose();
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue