UNPKG

@qaflag/core

Version:

Base requirements for the QA Flag library

132 lines 3.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestBase = void 0; const result_1 = require("./result"); class TestBase { constructor(input, mustShouldCould, opts, message) { var _a, _b, _c; this.input = input; this.mustShouldCould = mustShouldCould; this.message = message || [input.name, mustShouldCould]; this.opts = { isNot: (_a = opts === null || opts === void 0 ? void 0 : opts.isNot) !== null && _a !== void 0 ? _a : false, evalType: (_b = opts === null || opts === void 0 ? void 0 : opts.evalType) !== null && _b !== void 0 ? _b : 'standard', howMany: (_c = opts === null || opts === void 0 ? void 0 : opts.howMany) !== null && _c !== void 0 ? _c : 0, }; } get evalType() { return this.opts.evalType; } get isNot() { return this.opts.isNot; } result(pass, statement) { this.message.push(statement); const text = this.message.join(' '); if (this.needsResultOutput) { this.input.logger.log(pass ? 'pass' : this.isOptional ? 'optionalFail' : 'fail', { text }); if (!pass) { this.input.logger.log('info', { text: `Actual Value: ${this.input.string.$}`, }); } } return new result_1.TestResult(this, pass); } get needsResultOutput() { return this.mustShouldCould !== 'could'; } get isOptional() { return this.mustShouldCould !== 'must'; } get not() { this.opts.isNot = !this.opts.isNot; this.message.push('not'); return this; } get be() { this.message.push('be'); return this; } get match() { this.message.push('match'); return this; } get a() { this.message.push('a'); return this; } get an() { this.message.push('an'); return this; } get have() { this.message.push('have'); return this; } get all() { this.opts.evalType = 'every'; this.message.push('all'); return this; } get none() { this.opts.evalType = 'some'; this.opts.isNot = true; this.message.push('none'); return this; } get any() { this.opts.evalType = 'some'; this.message.push('any'); return this; } get some() { this.opts.evalType = 'some'; this.message.push('some'); return this; } only(count) { this.opts.evalType = 'only'; this.opts.howMany = count; this.message.push(`only ${count}`); return this; } just(count) { this.opts.evalType = 'only'; this.opts.howMany = count; this.message.push(`just ${count}`); return this; } atMost(count) { this.opts.evalType = 'atMost'; this.opts.howMany = count; this.message.push(`at most ${count}`); return this; } atLeast(count) { this.opts.evalType = 'atLeast'; this.opts.howMany = count; this.message.push(`at least ${count}`); return this; } noLessThan(count) { this.opts.evalType = 'atLeast'; this.opts.howMany = count; this.message.push(`no less than ${count}`); return this; } moreThan(count) { this.opts.evalType = 'atLeast'; this.opts.howMany = count + 1; this.message.push(`more than ${count}`); return this; } noMoreThan(count) { this.opts.evalType = 'atMost'; this.opts.howMany = count; this.message.push(`no more than ${count}`); return this; } } exports.TestBase = TestBase; //# sourceMappingURL=test-base.js.map