-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpretest.js
87 lines (74 loc) · 3.51 KB
/
pretest.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const fs = require('fs').promises;
const path = require('path');
const fieldsTestFolderPath = '../cedar-test-artifacts/artifacts/fields';
const elementsTestFolderPath = '../cedar-test-artifacts/artifacts/elements';
const templatesTestFolderPath = '../cedar-test-artifacts/artifacts/templates';
const instancesTestFolderPath = '../cedar-test-artifacts/artifacts/instances';
const ceeSuiteTestFolderPath = '../cedar-test-artifacts/artifacts/cee-suite';
async function generateTestCases() {
let fieldTestNumbers = [];
let elementTestNumbers = [];
let templateTestNumbers = [];
let instanceTestNumbers = [];
let ceeSuiteTestMap = {};
const subfoldersInFields = await fs.readdir(fieldsTestFolderPath, { withFileTypes: true });
for (const dirent of subfoldersInFields) {
if (dirent.isDirectory()) {
fieldTestNumbers.push(parseInt(dirent.name, 10));
}
}
const subfoldersInElements = await fs.readdir(elementsTestFolderPath, { withFileTypes: true });
for (const dirent of subfoldersInElements) {
if (dirent.isDirectory()) {
elementTestNumbers.push(parseInt(dirent.name, 10));
}
}
const subfoldersInTemplates = await fs.readdir(templatesTestFolderPath, { withFileTypes: true });
for (const dirent of subfoldersInTemplates) {
if (dirent.isDirectory()) {
templateTestNumbers.push(parseInt(dirent.name, 10));
}
}
const subfoldersInInstances = await fs.readdir(instancesTestFolderPath, { withFileTypes: true });
for (const dirent of subfoldersInInstances) {
if (dirent.isDirectory()) {
instanceTestNumbers.push(parseInt(dirent.name, 10));
}
}
const subfoldersInCEESuite = await fs.readdir(ceeSuiteTestFolderPath, { withFileTypes: true });
for (const dirent of subfoldersInCEESuite) {
if (dirent.isDirectory()) {
const dirName = dirent.name;
const map = {
template: false,
instance: false,
};
const subfolderPath = path.join(ceeSuiteTestFolderPath, dirName);
const filesInSubfolder = await fs.readdir(subfolderPath);
const expectedTemplateFile = `template-${dirName}.json`;
const expectedInstanceFile = `instance-${dirName}.json`;
map.template = filesInSubfolder.includes(expectedTemplateFile);
map.instance = filesInSubfolder.includes(expectedInstanceFile);
ceeSuiteTestMap[parseInt(dirName, 10)] = map;
}
}
function numberArrayToString(arr) {
return '[\n ' + arr.map((item) => `${item}`).join(',\n ') + ',\n]';
}
let ceeJsonString = JSON.stringify(ceeSuiteTestMap, null, 2);
ceeJsonString = ceeJsonString.replace(/\"/g, "'");
ceeJsonString = ceeJsonString.replace(/\'template\'/g, 'template');
ceeJsonString = ceeJsonString.replace(/\'instance\'/g, 'instance');
ceeJsonString = ceeJsonString.replace(/true\n/g, 'true,\n');
ceeJsonString = ceeJsonString.replace(/false\n/g, 'false,\n');
ceeJsonString = ceeJsonString.replace(/\}\n/g, '},\n');
// Use the arrayToString function for each test case type
const content =
`export const fieldTestNumbers: number[] = ${numberArrayToString(fieldTestNumbers)};\n` +
`export const elementTestNumbers: number[] = ${numberArrayToString(elementTestNumbers)};\n` +
`export const templateTestNumbers: number[] = ${numberArrayToString(templateTestNumbers)};\n` +
`export const instanceTestNumbers: number[] = ${numberArrayToString(instanceTestNumbers)};\n` +
`export const ceeSuiteTestMap = ${ceeJsonString};\n`;
await fs.writeFile('itest/resources/generatedTestCases.ts', content, { encoding: 'utf8' });
}
generateTestCases();