|
| 1 | +const path = require("path"); |
| 2 | +const idefs = require("./idefs"); |
| 3 | +const Promise = require("nodegit-promise"); |
| 4 | +const promisify = require("promisify-node"); |
| 5 | +const fse = promisify(require("fs-extra")); |
| 6 | +const testFilesPath = path.resolve(__dirname, "../test/tests"); |
| 7 | +const missingFileIgnores = require("./missing-tests-ignore"); |
| 8 | + |
| 9 | +var output = {}; |
| 10 | + |
| 11 | +function findMissingTest(idef) { |
| 12 | + var testFilePath = path.join(testFilesPath, idef.filename + ".js"); |
| 13 | + var result = {}; |
| 14 | + |
| 15 | + return fse.readFile(testFilePath, "utf8") |
| 16 | + .then(function(file) { |
| 17 | + var fieldsResult = []; |
| 18 | + var functionsResult = []; |
| 19 | + var fieldIgnores = (missingFileIgnores[idef.filename] || {}).fields; |
| 20 | + var functionIgnores = (missingFileIgnores[idef.filename] || {}).functions; |
| 21 | + |
| 22 | + fieldIgnores = fieldIgnores || []; |
| 23 | + functionIgnores = functionIgnores || []; |
| 24 | + file = file || ""; |
| 25 | + |
| 26 | + idef.fields.forEach(function(field) { |
| 27 | + if (file.indexOf(field.jsFunctionName) < 0 |
| 28 | + && fieldIgnores.indexOf(field.jsFunctionName < 0)) { |
| 29 | + fieldsResult.push(field.jsFunctionName); |
| 30 | + } |
| 31 | + }); |
| 32 | + |
| 33 | + result.fields = fieldsResult; |
| 34 | + |
| 35 | + idef.functions.forEach(function(fn) { |
| 36 | + if (file.indexOf(fn.jsFunctionName) < 0 |
| 37 | + && functionIgnores.indexOf(fn.jsFunctionName) < 0) { |
| 38 | + functionsResult.push(fn.jsFunctionName); |
| 39 | + } |
| 40 | + }); |
| 41 | + |
| 42 | + result.functions = functionsResult; |
| 43 | + }, |
| 44 | + function() { |
| 45 | + result.testFileMissing = false; |
| 46 | + result.testFilePath = testFilePath; |
| 47 | + }).then(function() { |
| 48 | + output[idef.filename] = result; |
| 49 | + }); |
| 50 | +}; |
| 51 | + |
| 52 | +var promises = []; |
| 53 | + |
| 54 | +idefs.forEach(function(idef) { |
| 55 | + promises.push(findMissingTest(idef)); |
| 56 | +}); |
| 57 | + |
| 58 | +Promise.all(promises) |
| 59 | +.then(function() { |
| 60 | + fse.writeFileSync(path.join(__dirname, "missing-tests.json"), |
| 61 | + JSON.stringify(output, null, 2)); |
| 62 | +}, function(fail) { |
| 63 | + console.log(fail); |
| 64 | +}); |
0 commit comments