Skip to content

Instantly share code, notes, and snippets.

@Underwaterr
Created October 29, 2018 15:29
Show Gist options
  • Save Underwaterr/451d244b879e9fb8be93e9ab1dcd7a5d to your computer and use it in GitHub Desktop.
Save Underwaterr/451d244b879e9fb8be93e9ab1dcd7a5d to your computer and use it in GitHub Desktop.
Get multiple asynchronous JS modules and execute them
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