35 lines
1.7 KiB
TypeScript
Executable file
35 lines
1.7 KiB
TypeScript
Executable file
import * as fs from 'fs';
|
|
const text = fs.readFileSync('C:/ScriptoriumAI/scriptoriumai-ui/src/__tests__/Runboard.telemetry-lockstep-parity.test.tsx', 'utf8');
|
|
|
|
const testMatches = [];
|
|
const regex = /^\s*it\(['"]([^'"]+)['"],\s*(?:async\s)?\(\)\s*=>\s*\{/gm;
|
|
let match;
|
|
while ((match = regex.exec(text)) !== null) {
|
|
testMatches.push({ index: match.index, length: match[0].length, name: match[1] });
|
|
}
|
|
|
|
console.log('Found', testMatches.length, 'it blocks.');
|
|
const tailIdx = text.lastIndexOf('})'); // closes the describe
|
|
console.log('Tail starts at:', tailIdx);
|
|
|
|
const prefix = text.substring(0, testMatches[0].index);
|
|
const suffix = text.substring(tailIdx);
|
|
|
|
const batchSize = Math.ceil(testMatches.length / 4);
|
|
|
|
for (let i = 0; i < 4; i++) {
|
|
const chunkMatches = testMatches.slice(i * batchSize, (i + 1) * batchSize);
|
|
if (!chunkMatches.length) continue;
|
|
|
|
const start = chunkMatches[0].index;
|
|
const end = i === 3 ? tailIdx : chunkMatches[chunkMatches.length - 1].index + (testMatches[(i+1)*batchSize] ? (testMatches[(i+1)*batchSize].index - chunkMatches[chunkMatches.length-1].index) : tailIdx - chunkMatches[chunkMatches.length-1].index);
|
|
const sliceEnd = i === 3 || !testMatches[(i+1)*batchSize] ? tailIdx : testMatches[(i+1)*batchSize].index;
|
|
|
|
const body = text.substring(start, sliceEnd);
|
|
fs.writeFileSync(C:/ScriptoriumAI/scriptoriumai-ui/src/__tests__/Runboard.telemetry-lockstep-parity.part + (i+1) + .test.tsx, prefix + body + suffix);
|
|
console.log(Wrote part + (i+1) + with + chunkMatches.length + tests.);
|
|
}
|
|
|
|
// Remove original if successful
|
|
fs.unlinkSync('C:/ScriptoriumAI/scriptoriumai-ui/src/__tests__/Runboard.telemetry-lockstep-parity.test.tsx');
|
|
console.log('Original massive file removed.');
|