UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

68 lines 2.62 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const response_1 = require("./response"); const jpath_1 = require("./jpath"); class JsonResponse extends response_1.GenericResponse { get typeName() { return 'JSON'; } get type() { return response_1.ResponseType.json; } constructor(scenario, response) { super(scenario, response); const json = this.jsonBody.$; this.context.assert('JSON is valid', json).type.not.equals('null'); this._json = json || {}; } getRoot() { return this._json; } evaluate(context, callback) { return __awaiter(this, void 0, void 0, function* () { return callback.apply(context, [this._json]); }); } 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 this._wrapAsValue(selection, path); }); } 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