Skip to content

Commit c0c408c

Browse files
committed
chore(scripts/website): change "getTests" to be sync
as per review comment
1 parent 93fb4e8 commit c0c408c

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

scripts/website.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,26 @@ const ignoredTestFiles = [
7070
* Load all test file contents with acquit
7171
* @returns {Object[]} acquit ast array
7272
*/
73-
async function getTests() {
74-
const promiseArray = [];
75-
76-
for (const file of additionalTestFiles) {
77-
const filePath = path.join(testPath, file);
78-
promiseArray.push(fs.promises.readFile(filePath).then(v => ({value: v.toString(), path: filePath})));
79-
}
80-
73+
function getTests() {
8174
const testDocs = path.resolve(testPath, 'docs');
75+
const filesToScan = [
76+
...additionalTestFiles.map(v => path.join(testPath, v)),
77+
...fs.readdirSync(testDocs).filter(v => !ignoredTestFiles.includes(v)).map(v => path.join(testDocs, v))
78+
];
8279

83-
for (const file of await fs.promises.readdir(testDocs)) {
84-
if (ignoredTestFiles.includes(file)) {
85-
continue;
86-
}
80+
const retArray = [];
8781

88-
const filePath = path.join(testDocs, file);
89-
promiseArray.push(fs.promises.readFile(filePath).then(v => ({value: v.toString(), path: filePath})));
90-
}
91-
92-
return (await Promise.all(promiseArray)).flatMap(v => {
82+
for (const file of filesToScan) {
9383
try {
94-
return acquit.parse(v.value);
84+
retArray.push(acquit.parse(fs.readFileSync(file).toString()));
9585
} catch (err) {
9686
// add a file path to a acquit error, for better debugging
97-
err.filePath = v.path;
87+
err.filePath = file;
9888
throw err;
9989
}
100-
})
90+
}
91+
92+
return retArray.flat();
10193
}
10294

10395
/**
@@ -376,7 +368,7 @@ async function pugify(filename, options, isReload = false) {
376368
let contents = fs.readFileSync(path.resolve(cwd, inputFile)).toString();
377369

378370
if (options.acquit) {
379-
contents = transform(contents, await getTests());
371+
contents = transform(contents, getTests());
380372

381373
contents = contents.replaceAll(/^```acquit$/gmi, "```javascript");
382374
}

0 commit comments

Comments
 (0)