-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-tests-edge-case.mjs
More file actions
49 lines (39 loc) · 1.22 KB
/
Copy pathgenerate-tests-edge-case.mjs
File metadata and controls
49 lines (39 loc) · 1.22 KB
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
import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { nanoid } from 'nanoid';
import { join } from 'path';
const specsDir = './edge-case-tests';
if (!existsSync(specsDir)) {
mkdirSync(specsDir);
}
const getContent = (i, waitTime) => `
import { test } from '@playwright/test';
test('spec ${i}', async () => {
await new Promise((resolve) => setTimeout(resolve, ${waitTime}));
});
`.trim();
const getRandomSpecName = () => nanoid(10);
function getRandomWaitTime(minMs = 30 * 1000, maxMs = 120 * 1000) {
return Math.floor(Math.random() * (maxMs - minMs + 1)) + minMs;
}
const results = [];
// 40 long specs: 110-120s
for (let i = 1; i <= 40; i++) {
const waitTime = getRandomWaitTime(110 * 1000, 120 * 1000);
results.push({
name: `a_${getRandomSpecName()}.spec.ts`,
waitTime,
});
}
// 40 short spec: 10-30s
for (let i = 1; i <= 40; i++) {
const waitTime = getRandomWaitTime(10 * 1000, 30 * 1000);
results.push({
name: `b_${getRandomSpecName()}.spec.ts`,
waitTime,
});
}
for (const { name, waitTime } of results) {
const filePath = join(specsDir, name);
writeFileSync(filePath, getContent(name, waitTime), 'utf-8');
}
console.log(`Generated ${results.length} spec files in ./tests`);