corde
Version:
A simple library for Discord bot tests
104 lines (83 loc) • 2.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.testCollector = void 0;
const data_structures_1 = require("../data-structures");
class TestCollector {
constructor() {
this.isInsideGroupClausure = false;
this.isInsideTestClausure = false;
this.groups = [];
this.beforeEachFunctions = new data_structures_1.Queue();
this.afterAllFunctions = new data_structures_1.Queue();
this.beforeStartFunctions = new data_structures_1.Queue();
this.afterEachFunctions = new data_structures_1.Queue();
this.testClousureFunction = new data_structures_1.Queue();
this.groupClousureFunction = new data_structures_1.Queue();
this.tests = [];
this.assertions = [];
this.isolatedFunctions = [];
this.testsFunctions = [];
}
static getInstance() {
if (!TestCollector._instance) {
TestCollector._instance = new TestCollector();
}
return TestCollector._instance;
}
addTestFunction(testFunction) {
if (testFunction) {
if (this.isInsideGroupClausure || this.isInsideTestClausure) {
this.testsFunctions.push(testFunction);
} else {
this.isolatedFunctions.push(testFunction);
}
}
}
isInsideTestClausureFunctions() {
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);
}
async executeGroupClojure() {
var _this$groupClousureFu;
return await ((_this$groupClousureFu = this.groupClousureFunction) === null ||
_this$groupClousureFu === void 0
? void 0
: _this$groupClousureFu.executeWithCatchCollectAsync());
}
addToTestClousure(fn) {
this.testClousureFunction.enqueue(fn);
}
async executeTestClojure() {
var _this$testClousureFun;
return await ((_this$testClousureFun = this.testClousureFunction) === null ||
_this$testClousureFun === void 0
? void 0
: _this$testClousureFun.executeWithCatchCollectAsync());
}
}
const testCollector = TestCollector.getInstance();
exports.testCollector = testCollector;