Tiny helper to search and exec js files by glob pattern
https://github.com/antongolub/glob-runner.git
yarn add glob-runner -D
import { run } from 'glob-runner'
await run({
pattern: 'src/test/**/*.it.js', // pattern to load
cwd: '/foo/bar', // process dir process.cwd()
cb: () => {}, // handler noop
nodeVersion: '20.0.0', // required nodejs process.version
parallel: true, // run in parallel false
silent: true, // suppress logs false
glob: fg, // glob API provider fast-glob
})
// Skipped /gh/glob-runner/src/test/js/index.cjs.it.js. v16.7.0 does not satisfy ^12.20.0
// Loading /gh/glob-runner/src/test/js/index.mjs.it.js...
// Done
glob-runner src/test/**/*.it.js
# Loading /gh/glob-runner/src/test/js/index.mjs.it.js...
# Done
// node-engine ^12.20.0 || ^14.13.1 || >=16.0.0
If current the runtime does not match the pattern, invocation will be skipped.
This feature might be useful for writing integration tests for several Node.js versions.
For example, require API with node: prefix needs v16.0.0+,
so your script may look like:
// node-engine >=16.0.0
const {read} = require('node:fs')
read('/foo/bar')