@mmisty/cypress-allure-adapter
Version:
cypress allure adapter to generate allure results during tests execution (Allure TestOps compatible)
81 lines (80 loc) • 3.44 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeResultFile = exports.copyTest = exports.copyAttachments = exports.copyFileCp = exports.mkdirSyncWithTry = void 0;
const fs_1 = require("fs");
const promises_1 = require("fs/promises");
const debug_1 = __importDefault(require("debug"));
const path_1 = require("path");
const common_1 = require("../common");
const debug = (0, debug_1.default)('cypress-allure:fs-tools');
const log = (...args) => {
debug(args);
};
const mkdirSyncWithTry = (dir) => {
if (!(0, fs_1.existsSync)(dir)) {
for (let i = 0; i < 5; i++) {
try {
(0, fs_1.mkdirSync)(dir);
return;
}
catch (err) {
// ignore
log(`Could not create dir: ${err.message}`);
}
}
}
};
exports.mkdirSyncWithTry = mkdirSyncWithTry;
const copyFileCp = (from, to, isRemoveSource) => __awaiter(void 0, void 0, void 0, function* () {
log(`copy file ${from} to ${to}`);
yield (0, promises_1.copyFile)(from, to)
.then(() => {
log(`Copied ${from} to ${to}`);
if (isRemoveSource && from !== to) {
(0, fs_1.rm)(from, () => {
// ignore
});
}
})
.catch(err => {
(0, common_1.logWithPackage)('error', `Failed to copy ${from} to ${to}: ${err}`);
});
});
exports.copyFileCp = copyFileCp;
const copyAttachments = (attachments, watchPath, allureResultFile) => __awaiter(void 0, void 0, void 0, function* () {
const allureResults = (0, path_1.dirname)(allureResultFile);
for (const attach of attachments) {
const attachTo = `${watchPath}/${attach.source}`;
const attachFrom = `${allureResults}/${attach.source}`;
yield (0, exports.copyFileCp)(attachFrom, attachTo, true);
}
});
exports.copyAttachments = copyAttachments;
const copyTest = (testFile, watchPath) => __awaiter(void 0, void 0, void 0, function* () {
const to = `${watchPath}/${(0, path_1.basename)(testFile)}`;
// do not remove for understanding how containers connected to tests
yield (0, exports.copyFileCp)(testFile, to, false);
});
exports.copyTest = copyTest;
const writeResultFile = (resultContainer, content) => __awaiter(void 0, void 0, void 0, function* () {
return (0, promises_1.writeFile)(resultContainer, content)
.then(() => {
log(`write test file done ${resultContainer} `);
})
.catch(err => {
log(`error test file ${err.message} `);
});
});
exports.writeResultFile = writeResultFile;