@averagehelper/corde
Version:
A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)
55 lines (54 loc) • 2.44 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.group = void 0;
const testCollector_1 = require("../common/testCollector");
/**
* Represents a group of tests.
*
* @example
*
* group('main commands', () => {
* test('Hello command must return... hello!!', () => {
* expect('hello').toReturn('hello!!');
* });
* });
*
* @param name Name of the group
* @param action Tests related to this group
* @since 1.0
*/
function group(name, action) {
testCollector_1.testCollector.addToGroupClousure(() => __awaiter(this, void 0, void 0, function* () {
testCollector_1.testCollector.hasGroup = true;
if (action) {
yield action();
yield testCollector_1.testCollector.executeTestClojure();
// In case of expect() be added in test clausure
// that is contained in action()
if (testCollector_1.testCollector.tests && testCollector_1.testCollector.tests.length > 0) {
testCollector_1.testCollector.groups.push({
name,
tests: testCollector_1.testCollector.tests.map((test) => test),
});
}
// Case expect() be added inside the group clausure
if (testCollector_1.testCollector.hasTestFunctions()) {
const testsCloned = testCollector_1.testCollector.cloneTestFunctions();
testCollector_1.testCollector.groups.push({ name, tests: [{ testsFunctions: testsCloned }] });
testCollector_1.testCollector.clearTestFunctions();
}
}
testCollector_1.testCollector.tests = [];
testCollector_1.testCollector.hasGroup = false;
}));
}
exports.group = group;