-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-files.mjs
51 lines (38 loc) · 1.2 KB
/
generate-files.mjs
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
import * as fs from "node:fs";
import { resolve } from "node:path";
const TEST_COUNT = parseInt(process.env.TEST_COUNT || 5000);
const LOG_WIDTH = parseInt(process.env.LOG_WIDTH || 10);
console.log("Generating files", { TEST_COUNT, LOG_WIDTH });
const testDir = new URL("fixtures/tests", import.meta.url).pathname;
const someText = "Hello world "
.repeat(LOG_WIDTH)
.slice(0, LOG_WIDTH - 3)
.concat("...");
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true });
}
fs.mkdirSync(testDir, { recursive: true });
for (const i of toList(TEST_COUNT)) {
const index = 1 + i;
const filename = resolve(testDir, `test-${index}.test.ts`);
const contents = `import { describe, test } from "vitest";
describe("test set ${index} - ${someText}", (file) => {
test("test #1 - ${someText}", () => {
console.log('${someText}');
});
test("test #2 - ${someText}", () => {
console.log('${someText}');
});
test("test #3 - ${someText}", () => {
console.log('${someText}');
});
test("test #4 - ${someText}", () => {
console.log('${someText}');
});
});
`;
fs.writeFileSync(filename, contents, "utf-8");
}
function toList(count) {
return Array.from(Array(count).fill(0).keys());
}