@hayspec/runner
Version:
Tests runner for Hayspec framework.
61 lines • 2.34 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Runner = void 0;
const spec_1 = require("@hayspec/spec");
const glob = require("fast-glob");
class Runner {
constructor(options) {
this.onlyEnabled = false;
this.results = [];
this.options = Object.assign({ cwd: process.cwd(), deep: Infinity, dot: false }, options);
}
require(...patterns) {
return __awaiter(this, void 0, void 0, function* () {
const options = Object.assign({ absolute: true }, this.options);
const files = yield glob(patterns, options);
files.forEach((file) => {
const spec = this.loadSpec(file);
if (!spec) {
return;
}
else if (spec.spec.hasOnly() && !this.onlyEnabled) {
this.onlyEnabled = true;
this.results = [];
}
if (this.onlyEnabled && spec.spec.hasOnly()) {
this.results.push(spec);
}
else if (!this.onlyEnabled) {
this.results.push(spec);
}
});
});
}
clear() {
this.results = [];
return this;
}
loadSpec(file) {
const spec = require(file);
if (spec instanceof spec_1.Spec) {
return { file, spec };
}
else if (spec.default instanceof spec_1.Spec) {
return { file, spec: spec.default };
}
else {
return null;
}
}
}
exports.Runner = Runner;
//# sourceMappingURL=runner.js.map