import { rmSync } from "fs"; import * as fs from "fs"; import { StackService } from "../../src/core/services/stack_service"; import { delay } from "../../src/core/helper/delay"; import { assert, dirname__ } from "../test"; import { mockSimplePipeline } from "../model/mock_pipelines"; abstract class IStackServiceTest { abstract test(): Promise; } export function readDirRecursive(path: string, filesToDir: string[] = []) { const files = fs.readdirSync(path); files.forEach((file) => { let filePath = ""; if (path[path.length - 1] !== "/") { filePath = `${path}/${file}`; } else { filePath = `${path}${file}`; } const stats = fs.statSync(filePath); if (stats.isDirectory()) { readDirRecursive(filePath, filesToDir); } else { filesToDir.push(file); } }); return filesToDir; } class SimpleTestStackServiceTest extends StackService implements IStackServiceTest { constructor() { super(mockSimplePipeline, dirname__ + "/context/"); } async test(): Promise { await this.call(); const testResult = readDirRecursive(this.path).equals( ["1.txt", "test.txt"], true ); 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); } } }