-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatherTests.ts
56 lines (43 loc) · 1.38 KB
/
gatherTests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { appendFile, readdir, writeFile } from "fs/promises";
class testGatherer {
rootDir: string;
constructor(rootDir: string) {
this.rootDir = rootDir;
}
async _readImports(path: string) {
const items = await readdir(path, { withFileTypes: true });
const files = items
.filter((dirent) => dirent.isFile())
.map((dirent) => dirent.name);
const dirs = items.filter((dirent) => dirent.isDirectory());
if (files) {
const relativePath = path.replace(`cypress/${this.rootDir}/`, "./");
files.forEach((file) => this.appendImport(`${relativePath}/${file}`));
}
if (!dirs.length) return;
const newPath = `${path}/${dirs[0].name}`;
await this._readImports(newPath);
}
async appendImport(path: string) {
if (!path.endsWith("all.cy.ts")) {
appendFile(`./cypress/${this.rootDir}/all.cy.ts`, `import "${path}"\n`);
}
}
async gather() {
// create all.cy.ts for integration and e2e tests
this._writeFile("integration", "all");
this._writeFile("e2e", "all");
const path = `cypress/${this.rootDir}`;
this._readImports(path);
}
async _writeFile(folder: "e2e" | "integration", file: string) {
try {
await writeFile(`cypress/${folder}/${file}.cy.ts`, "");
} catch (error) {
console.log(error);
}
}
}
const gatherer = new testGatherer("integration");
gatherer.gather();
export {};