cybernaut
Version:
Reliable, zero configuration end-to-end testing in BDD-style.
59 lines • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const description_1 = require("./description");
const step_1 = require("./step");
class Test {
constructor(driver, retries, retryDelay) {
this._driver = driver;
this._retries = retries;
this._retryDelay = retryDelay;
}
assert(accessor, predicate, retries = this._retries, retryDelay = this._retryDelay) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const message = `${description_1.format(accessor.description)} ${description_1.format(predicate.description)}`;
try {
const attempts = yield step_1.run(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!predicate.test(yield accessor.get(this._driver))) {
throw new Error('Predicate evaluates to false');
}
}), retries, retryDelay);
this.pass(`${message} (attempt ${attempts} of ${retries + 1})`);
}
catch (e) {
this.fail(message, e);
}
});
}
perform(action, retries = this._retries, retryDelay = this._retryDelay) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const message = description_1.format(action.description);
try {
const attempts = yield step_1.run(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
yield action.perform(this._driver);
}), retries, retryDelay);
this.pass(`${message} (attempt ${attempts} of ${retries + 1})`);
}
catch (e) {
this.fail(message, e);
}
});
}
verify(accessor, predicate, retries = this._retries, retryDelay = this._retryDelay) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
yield step_1.run(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!predicate.test(yield accessor.get(this._driver))) {
throw new Error('Predicate evaluates to false');
}
}), retries, retryDelay);
return true;
}
catch (e) {
return false;
}
});
}
}
exports.Test = Test;
//# sourceMappingURL=test.js.map