webstudio/server/test/services/stack_service_test.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-09-11 19:49:45 +03:00
import { rmSync } from "fs";
2023-10-26 17:44:54 +03:00
import { StackService } from "../../src/core/services/stack_service";
2023-12-03 16:20:52 +03:00
import { delay } from "../../src/core/helpers/delay";
2023-10-26 17:44:54 +03:00
import { assert, dirname__ } from "../test";
2023-11-10 12:06:40 +03:00
import { mockSimplePipeline } from "../model/mock_pipelines";
2023-11-14 20:44:06 +03:00
import { readDirRecursive } from "../../src/core/repository/fs";
2023-09-11 19:49:45 +03:00
abstract class IStackServiceTest {
abstract test(): Promise<boolean>;
}
class SimpleTestStackServiceTest extends StackService implements IStackServiceTest {
2023-09-11 19:49:45 +03:00
constructor() {
2023-11-10 12:06:40 +03:00
super(mockSimplePipeline, dirname__ + "/context/");
2023-09-11 19:49:45 +03:00
}
async test(): Promise<boolean> {
await this.call();
const testResult = readDirRecursive(this.path).equals(["1.txt", "test.txt"], true);
2023-09-11 19:49:45 +03:00
await delay(100);
rmSync(this.path + "example/", { recursive: true });
return testResult;
}
}
export class StackServiceTest {
dirName: string;
constructor(dirName: string) {
this.dirName = dirName;
}
public async test() {
const tests = [new SimpleTestStackServiceTest()];
for await (const el of tests) {
assert((await el.test()) === true, el.constructor.name);
await delay(3000);
}
}
}