Created
October 29, 2018 15:29
-
-
Save Underwaterr/451d244b879e9fb8be93e9ab1dcd7a5d to your computer and use it in GitHub Desktop.
Get multiple asynchronous JS modules and execute them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let requireGlob = require('require-glob') | |
let tests = await requireGlob(['api/**/test.js'], { | |
// Custom reducer returns flat array of functions | |
reducer: (options, moduleExports, module)=> { | |
// 'moduleExports' starts as an object, convert to array | |
if(!Array.isArray(moduleExports)) moduleExports = [] | |
moduleExports.push(module.exports) | |
return moduleExports | |
} | |
}) | |
// Execute all tests sequentially | |
for (test of tests) await test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment