Skip to content

Commit

Permalink
📦 NEW: Express to open report in localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
ortoniKC committed Oct 16, 2024
1 parent 51ed94e commit 5fc427f
Show file tree
Hide file tree
Showing 6 changed files with 1,680 additions and 73 deletions.
33 changes: 33 additions & 0 deletions dist/utils/expressServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.startReportServer = void 0;
const express_1 = __importDefault(require("express"));
/**
* Starts an Express server to serve the HTML report and keeps it running.
* @param {string} reportPath - Path to the folder where the report is stored.
* @param {string} reportFilename - Name of the HTML report file to serve.
* @param {number} port - Port number to serve the report on (default is 8080).
*/
function startReportServer(reportPath, reportFilename, port = 8080) {
const app = (0, express_1.default)();
// Serve static files from the report directory
app.use(express_1.default.static(reportPath));
// Start the server and keep it running
const server = app.listen(port, () => {
const reportUrl = `http://localhost:${port}/${reportFilename}`;
console.log(`Report is available at ${reportUrl}`);
});
// Ensure that the process doesn't exit prematurely
process.on('SIGINT', () => {
console.log('Shutting down the server...');
server.close(() => {
console.log('Server closed');
process.exit(0);
});
});
return server;
}
exports.startReportServer = startReportServer;
18 changes: 17 additions & 1 deletion dist/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureHtmlExtension = exports.safeStringify = exports.formatDate = exports.normalizeFilePath = exports.msToTime = void 0;
exports.escapeHtml = exports.ensureHtmlExtension = exports.safeStringify = exports.formatDate = exports.normalizeFilePath = exports.msToTime = void 0;
const path_1 = __importDefault(require("path"));
function msToTime(duration) {
const milliseconds = Math.floor(duration % 1000);
Expand Down Expand Up @@ -67,3 +67,19 @@ function ensureHtmlExtension(filename) {
return `${filename}.html`;
}
exports.ensureHtmlExtension = ensureHtmlExtension;
function escapeHtml(unsafe) {
if (typeof unsafe !== 'string') {
return String(unsafe);
}
return unsafe.replace(/[&<"']/g, function (match) {
const escapeMap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};
return escapeMap[match] || match;
});
}
exports.escapeHtml = escapeHtml;
Loading

0 comments on commit 5fc427f

Please sign in to comment.