@johnf/react-native-owl
Version:
Visual regression testing for React Native
70 lines (69 loc) • 3.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.generateReport = exports.cleanupReport = void 0;
var _path = _interopRequireDefault(require("path"));
var _handlebars = _interopRequireDefault(require("handlebars"));
var _fs = require("fs");
var _fileExists = require("./utils/file-exists.js");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const cleanupReport = async () => {
const cwd = process.cwd();
const reportDirPath = _path.default.join(cwd, '.owl', 'report');
await _fs.promises.rm(reportDirPath, {
recursive: true,
force: true
});
};
exports.cleanupReport = cleanupReport;
const generateReport = async (logger, platform) => {
const cwd = process.cwd();
const reportDirPath = _path.default.join(cwd, '.owl', 'report');
const jestOutputFilepath = _path.default.join(reportDirPath, 'jest-report.json');
const jestOutputText = await _fs.promises.readFile(jestOutputFilepath, 'utf8');
const jestOutput = JSON.parse(jestOutputText);
const diffScreenshotsDirPath = _path.default.join(cwd, '.owl', 'diff', platform);
const baselineScreenshotsDirPath = _path.default.join(cwd, '.owl', 'baseline', platform);
const baselineScreenshotsDirExists = await (0, _fileExists.fileExists)(baselineScreenshotsDirPath);
if (!baselineScreenshotsDirExists) {
logger.print(`[OWL - CLI] Generating report skipped as is no baseline screenshots directory`);
return;
}
const baselineScreenshots = await _fs.promises.readdir(baselineScreenshotsDirPath);
const failingScreenshots = (await (0, _fileExists.fileExists)(diffScreenshotsDirPath)) ? await _fs.promises.readdir(diffScreenshotsDirPath) : [];
const passingScreenshots = baselineScreenshots.filter(screenshot => !failingScreenshots.includes(screenshot));
const duration = (Date.now() - jestOutput.startTime) / 1000;
const durationFormatted = parseFloat(`${duration}`).toFixed(2);
const stats = {
totalTestSuites: jestOutput.numTotalTestSuites,
totalTests: jestOutput.numTotalTests,
failedTestSuites: jestOutput.numFailedTestSuites,
failedTests: jestOutput.numFailedTests,
passedTestSuites: jestOutput.numPassedTestSuites,
passedTests: jestOutput.numPassedTests,
duration: durationFormatted,
success: jestOutput.success
};
logger.info(`[OWL - CLI] Generating Report`);
const reportFilename = 'index.html';
const entryFile = _path.default.join(__dirname, 'report', reportFilename);
const htmlTemplate = await _fs.promises.readFile(entryFile, 'utf-8');
const templateScript = _handlebars.default.compile(htmlTemplate);
const htmlContent = templateScript({
currentYear: new Date().getFullYear(),
currentDateTime: new Date().toUTCString(),
platform,
failingScreenshots,
passingScreenshots,
stats
});
await _fs.promises.mkdir(reportDirPath, {
recursive: true
});
const reportFilePath = _path.default.join(reportDirPath, 'index.html');
await _fs.promises.writeFile(reportFilePath, htmlContent);
logger.print(`[OWL - CLI] Report was built at ${reportDirPath}/${reportFilename}`);
};
exports.generateReport = generateReport;
//# sourceMappingURL=report.js.map