@qaflag/core
Version:
Base requirements for the QA Flag library
100 lines • 3.33 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.Context = void 0;
const values_1 = require("../value/values");
const kv_store_1 = require("../models/kv-store");
const string_1 = require("../utils/string");
class Context {
constructor(scenario) {
this.scenario = scenario;
this.store = new kv_store_1.KvStore();
this.testCaseCount = 0;
}
get persona() {
return this.scenario.persona;
}
get logger() {
return this.scenario.logger;
}
debug(messages) {
this.logger.debug(messages);
}
info(messages) {
this.logger.info(messages);
}
heading(messages) {
this.logger.heading(messages);
}
fail(content) {
this.logger.fail(content);
}
pass(content) {
this.logger.pass(content);
}
case(a, b) {
return __awaiter(this, void 0, void 0, function* () {
this.testCaseCount++;
const testCase = (typeof a == 'string' ? b : a) || (() => { });
const title = (() => {
if (typeof a === 'string')
return a;
if (b === null || b === void 0 ? void 0 : b.name)
return (0, string_1.titleize)(b.name);
if (typeof a !== 'string' && (a === null || a === void 0 ? void 0 : a.name))
return (0, string_1.titleize)(a.name);
return `Test Case #${this.testCaseCount}`;
})();
if (!this.logger.lastLineIsBreak()) {
this.logger.lineBreak();
}
this.logger.heading(title);
const result = yield testCase.call(this.scenario.suite, this);
this.logger.lineBreak();
return result;
});
}
set(key, value) {
return this.store.set(key, value);
}
get(key) {
return this.store.get(key);
}
push(key, value) {
return this.store.push(key, value);
}
stringValue(input, name) {
return new values_1.StringValue(input, {
name,
context: this,
});
}
numericValue(input, name) {
return new values_1.NumericValue(input, {
name,
context: this,
});
}
booleanValue(input, name) {
return new values_1.BooleanValue(input, {
name,
context: this,
});
}
arrayValue(input, name) {
return new values_1.ArrayValue(input, {
name,
context: this,
});
}
}
exports.Context = Context;
//# sourceMappingURL=context.abstract.js.map