flagpole
Version:
Simple and fast DOM integration, headless or headful browser, and REST API testing framework.
75 lines • 2.84 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.JsonResponse = void 0;
const response_1 = require("./response");
const jpath_1 = require("./jpath");
const util_1 = require("./util");
class JsonResponse extends response_1.ProtoResponse {
constructor() {
super(...arguments);
this._json = {};
}
get responseTypeName() {
return "JSON";
}
get responseType() {
return "json";
}
init(httpResponse) {
super.init(httpResponse);
const json = this.jsonBody.$;
this.context.assert("JSON is valid", json).type.not.equals("null");
this._json = json || {};
}
getRoot() {
return this._json;
}
eval() {
return __awaiter(this, void 0, void 0, function* () {
throw "This type of scenario does not suport eval.";
});
}
find(path) {
return __awaiter(this, void 0, void 0, function* () {
yield this.loadJmesPath();
if (typeof this._jPath == "undefined") {
throw new Error("Could not load jmespath");
}
const selection = yield this._jPath.search(this._json, path);
return util_1.wrapAsValue(this.context, selection, path, selection);
});
}
findAll(path) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error("findAll() is not supported by JSON scenarios, please use select()");
});
}
loadJmesPath() {
return __awaiter(this, void 0, void 0, function* () {
if (typeof this._jPath == "undefined") {
return (Promise.resolve().then(() => require("jmespath")).then((jpath) => {
this._jPath = jpath;
return this._jPath;
})
.catch((e) => {
this._jPath = new jpath_1.jPath();
return this._jPath;
}));
}
else {
return this._jPath;
}
});
}
}
exports.JsonResponse = JsonResponse;
//# sourceMappingURL=jsonresponse.js.map