@iamkenos/iris
Version:
Test API endpoints with Axios & Jest using a collection of custom matchers and built-in utility functions.
53 lines • 2.59 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.givenGraphQLQueryFile = exports.givenRequest = void 0;
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
const _common_1 = require("../common/index");
const _client_1 = require("../client/index");
const callsites_1 = __importDefault(require("callsites"));
const givenRequest = (url, options) => {
const request = new _client_1.Request(url, { ...options });
const fname = (0, callsites_1.default)()[1].getFunctionName();
_common_1.Reporter.startStep(`${_common_1.changecase.capitalCase(fname)}: ${request.spec.method} ${new URL(request.spec.url).pathname}`);
_common_1.Reporter.attachRequest(request, options.shouldAttachBody);
_common_1.Reporter.endStep();
return request;
};
exports.givenRequest = givenRequest;
const givenGraphQLQueryFile = (file, variables) => {
const query = fs.readFileSync(path.join(iris.config.baseDir, file), _common_1.BufferEncoding.UTF8);
const data = { query, variables };
_common_1.Reporter.startStep(`${_common_1.changecase.capitalCase(exports.givenGraphQLQueryFile.name)}: ${file}`);
_common_1.Reporter.addAttachment("Query", JSON.stringify(data, null, 2), _common_1.MimeType.TEXT_PLAIN);
_common_1.Reporter.endStep();
return data;
};
exports.givenGraphQLQueryFile = givenGraphQLQueryFile;
//# sourceMappingURL=given.js.map