@mmisty/cypress-allure-adapter
Version:
cypress allure adapter to generate allure results during tests execution (Allure TestOps compatible)
74 lines (73 loc) • 2.7 kB
JavaScript
;
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) => {
log(`copy file ${from} to ${to}`);
return (0, promises_1.copyFile)(from, to)
.then(() => {
log(`Copied ${from} to ${to}`);
if (isRemoveSource) {
(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 = (allTasks, attachments, watchPath, allureResultFile) => {
const allureResults = (0, path_1.dirname)(allureResultFile);
const attachCopyOperations = attachments.map(attach => {
const attachTo = `${watchPath}/${attach.source}`;
const attachFrom = `${allureResults}/${attach.source}`;
return (0, exports.copyFileCp)(attachFrom, attachTo, true);
});
allTasks.push(...attachCopyOperations);
};
exports.copyAttachments = copyAttachments;
const copyTest = (allTasks, testFile, watchPath) => {
const to = `${watchPath}/${(0, path_1.basename)(testFile)}`;
// do not remove for understanding how containers connected to tests
const testCopyOperation = [(0, exports.copyFileCp)(testFile, to, false)];
allTasks.push(testCopyOperation);
};
exports.copyTest = copyTest;
const writeResultFile = (resultContainer, content) => {
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;