tests: create TestRunner

This commit is contained in:
Peter Fajdiga
2024-09-20 21:38:34 +02:00
parent 279333dd1d
commit b3f581c386
6 changed files with 35 additions and 8 deletions

View File

@@ -1,5 +1,4 @@
{
runLog.length = 0;
tests.register("Maximization", 100, () => {
const workspaceMock = initMocks();
const config = getDefaultConfig();
const world = new World(config);
@@ -34,4 +33,4 @@
kwinClient.setMaximize(false, false);
assertRect(kwinClient.frameGeometry, columnLeftX, columnTopY, 300, columnHeight);
}
});

1
src/tests/main.ts Normal file
View File

@@ -0,0 +1 @@
tests.run();

View File

@@ -4,6 +4,7 @@
"../lib/**/*",
"./utils/**/*",
"./units/**/*",
"./flows/**/*"
"./flows/**/*",
"./main.ts"
]
}

View File

@@ -1,4 +1,4 @@
{
tests.register("WindowRuleEnforcer", 1, () => {
const testCases = [
{tiledByDefault: true, resourceClass: "unknown", caption: "anything", shouldTile: true},
{tiledByDefault: false, resourceClass: "unknown", caption: "anything", shouldTile: false},
@@ -33,4 +33,4 @@
caption: caption,
}
}
}
});

View File

@@ -0,0 +1,28 @@
class TestRunner {
private readonly tests: TestRunner.Test[] = [];
public register(name: string, count: number, f: () => void) {
this.tests.push({ name: name, count: count, f: f });
}
public run() {
for (const test of this.tests) {
console.log("Running test " + test.name);
for (let i = 0; i < test.count; i++) {
runLog.length = 0;
test.f();
}
}
}
}
namespace TestRunner {
export type Test = {
name: string,
count: number,
f: () => void,
}
}
const runLog: string[] = [];
const tests = new TestRunner();

View File

@@ -1,5 +1,3 @@
const runLog: string[] = [];
function assert(assertion: boolean, message?: string, skip: number = 0) {
if (assertion) {
return;