UNPKG

@iamkenos/iris

Version:

Test API endpoints with Axios & Jest using a collection of custom matchers and built-in utility functions.

73 lines 3 kB
"use strict"; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Reporter = void 0; const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const _common_1 = require("../index"); const enums_1 = require("./enums"); class Reporter { static directory() { return path.join(iris.config.resultsDir, "allure"); } static instance() { return reporter; } static addAttachment(...args) { reporter.addAttachment(...args); } static startStep(...args) { reporter.startStep(...args); } static endStep(...args) { reporter.endStep(...args); } static attachFile(title, filename, attachment, mimetype) { reporter.addAttachment(`${title}: ${filename}`, attachment, mimetype); } static attachJSON(title, filename) { if (fs.existsSync(filename)) { const content = fs.readFileSync(filename, enums_1.BufferEncoding.UTF8); this.attachFile(title, filename, (0, _common_1.isJSON)(content) ? JSON.parse(content) : content, enums_1.MimeType.APP_JSON); } } static attachRequest(request, shouldAttachBody = true) { // eslint-disable-next-line const { data: deleted, ...rest } = request.spec; // immutably delete data prop; it's redundant to body prop let spec = { ...rest }; if (!shouldAttachBody) { // eslint-disable-next-line const { body: deleted, ...rest } = spec; spec = rest; } reporter.addAttachment("Request", JSON.stringify(spec, null, 2), enums_1.MimeType.APP_JSON); } static attachResponse(response) { const { status, statusText, headers, time, body } = response; reporter.addAttachment("Response", JSON.stringify({ status, statusText, time: `${time}ms`, headers, body }, null, 2), enums_1.MimeType.APP_JSON); } } exports.Reporter = Reporter; //# sourceMappingURL=reporter.js.map