@averagehelper/corde
Version:
A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)
84 lines (83 loc) • 2.98 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.testCollector = void 0;
const utils_1 = require("../utils");
/**
* Contain all information of data collected from files in runtime test
* collection.
*/
class TestCollector {
constructor() {
this.groups = [];
this.beforeEachFunctions = new utils_1.Queue();
this.afterAllFunctions = new utils_1.Queue();
this.beforeStartFunctions = new utils_1.Queue();
this.afterEachFunctions = new utils_1.Queue();
this.testClousureFunction = new utils_1.Queue();
this.groupClousureFunction = new utils_1.Queue();
this.tests = [];
this.assertions = [];
this.isolatedFunctions = [];
this.testsFunctions = [];
}
addTestFunction(testFunction) {
if (testFunction) {
if (this.hasGroup || this.hasTest) {
this.testsFunctions.push(testFunction);
}
else {
this.isolatedFunctions.push(testFunction);
}
}
}
hasTestFunctions() {
return this.testsFunctions && this.testsFunctions.length > 0;
}
hasIsolatedTestFunctions() {
return this.isolatedFunctions && this.isolatedFunctions.length > 0;
}
cloneTestFunctions() {
return this.testsFunctions.map((m) => m);
}
cloneIsolatedTestFunctions() {
return this.isolatedFunctions.map((m) => m);
}
clearTestFunctions() {
this.testsFunctions = [];
}
clearIsolatedTestFunctions() {
this.isolatedFunctions = [];
}
cleanAll() {
this.tests = [];
this.testsFunctions = [];
this.groups = [];
}
addToGroupClousure(fn) {
this.groupClousureFunction.enqueue(fn);
}
executeGroupClojure() {
return __awaiter(this, void 0, void 0, function* () {
yield this.groupClousureFunction.executeAsync();
});
}
addToTestClousure(fn) {
this.testClousureFunction.enqueue(fn);
}
executeTestClojure() {
return __awaiter(this, void 0, void 0, function* () {
yield this.testClousureFunction.executeAsync();
});
}
}
const testCollector = new TestCollector();
exports.testCollector = testCollector;