japa
Version:
Lean test runner for Node.js
56 lines (55 loc) • 1.26 kB
JavaScript
/**
* @module SlimRunner
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Loader = void 0;
/*
* japa
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Loads files using the glob patterns.
*
* @class Loader
*/
class Loader {
/**
* Define the glob for the files
*/
files(glob) {
this._glob = glob;
}
/**
* Define a custom filter function to filter files
*/
filter(cb) {
this._filterFn = cb;
}
/**
* Returns an array of sorted files based on the glob
* pattern.
*/
async loadFiles() {
if (!this._glob) {
return [];
}
const fg = await import('fast-glob');
let filesPaths = await fg.default(this._glob, {
absolute: true,
onlyFiles: false,
});
/**
* If filterFn is defined, then filter the files
*/
if (typeof (this._filterFn) === 'function') {
filesPaths = filesPaths.filter((file) => this._filterFn(file));
}
return filesPaths.sort();
}
}
exports.Loader = Loader;
;