corde
Version:
A simple library for Discord bot tests
48 lines (38 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.test = void 0;
const testCollector_1 = require("../common/testCollector");
const utils_1 = require("../utils");
const test = (expectationDescription, assertion, timeout) => {
const _internalTest = async () => {
testCollector_1.testCollector.isInsideTestClausure = true;
if (assertion) {
await assertion();
const testName = await (0, utils_1.resolveName)(expectationDescription);
if (
testCollector_1.testCollector.testsFunctions &&
testCollector_1.testCollector.testsFunctions.length
) {
testCollector_1.testCollector.tests.push({
name: testName,
testsFunctions: testCollector_1.testCollector.cloneTestFunctions(),
});
}
}
testCollector_1.testCollector.testsFunctions = [];
testCollector_1.testCollector.isInsideTestClausure = false;
};
if (timeout) {
testCollector_1.testCollector.addToGroupClousure(async () => {
await (0, utils_1.executePromiseWithTimeout)(async (resolve) => {
await _internalTest();
resolve();
}, timeout);
});
} else {
testCollector_1.testCollector.addToTestClousure(async () => await _internalTest());
}
};
exports.test = test;