Skip to content

Commit

Permalink
generate/scripts/generateMissingTests.js: async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
samuela committed Oct 17, 2021
1 parent 97138eb commit 1be71ef
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions generate/scripts/generateMissingTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const utils = require("./utils");
const testFilesPath = "../test/tests";
const missingFileIgnores = require("../input/ignored-missing-tests");

module.exports = function generateMissingTests() {
module.exports = async function generateMissingTests() {
var output = {};

function findMissingTest(idef) {
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
var testFilePath = path.join(testFilesPath, idef.filename + ".js");
var result = {};

Expand All @@ -17,54 +17,53 @@ module.exports = function generateMissingTests() {
var fieldsResult = [];
var functionsResult = [];
var fieldIgnores = (missingFileIgnores[idef.filename] || {}).fields;
var functionIgnores = (missingFileIgnores[idef.filename] || {}).functions;
var functionIgnores = (missingFileIgnores[idef.filename] || {})
.functions;

fieldIgnores = fieldIgnores || [];
functionIgnores = functionIgnores || [];
file = file || "";

idef.fields.forEach(function(field) {
if (file.indexOf(field.jsFunctionName) < 0
&& fieldIgnores.indexOf(field.jsFunctionName < 0)) {
fieldsResult.push(field.jsFunctionName);
}
idef.fields.forEach(function (field) {
if (
file.indexOf(field.jsFunctionName) < 0 &&
fieldIgnores.indexOf(field.jsFunctionName < 0)
) {
fieldsResult.push(field.jsFunctionName);
}
});

result.fields = fieldsResult;

idef.functions.forEach(function(fn) {
if (file.indexOf(fn.jsFunctionName) < 0
&& functionIgnores.indexOf(fn.jsFunctionName) < 0) {
functionsResult.push(fn.jsFunctionName);
}
idef.functions.forEach(function (fn) {
if (
file.indexOf(fn.jsFunctionName) < 0 &&
functionIgnores.indexOf(fn.jsFunctionName) < 0
) {
functionsResult.push(fn.jsFunctionName);
}
});

result.functions = functionsResult;
}
else {
} else {
result.testFileMissing = false;
result.testFilePath = testFilePath;
}

output[idef.filename] = result;
resolve();
});
};
}

const idefs = require("../output/idefs");
var promises = idefs.map(function(idef) {
return findMissingTest(idef);
});

Promise.all(promises).then(
function() {
utils.writeLocalFile("/output/missing-tests.json", output);
},
function(fail) {
console.error(fail);
}
);
var promises = idefs.map(findMissingTest);

try {
await Promise.all(promises);
utils.writeLocalFile("/output/missing-tests.json", output);
} catch (err) {
console.error(err);
}
};

if (require.main === module) {
Expand Down

0 comments on commit 1be71ef

Please sign in to comment.