@chtsinc/ch-playwright-report
Version:
Custom Playwright Reporter that logs test and execution results to MongoDB
79 lines • 2.83 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadServiceConfig = loadServiceConfig;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
// Internal cache for the parsed JSON file
let cachedRawConfig = null;
/**
* Load and parse the raw config file once, caching the result.
* Throws a clear error if the file is missing or invalid.
*/
function loadRawConfig() {
if (cachedRawConfig) {
return cachedRawConfig;
}
const configPath = path_1.default.resolve(process.cwd(), "ch-services.json");
let fileContents;
try {
fileContents = fs_1.default.readFileSync(configPath, "utf8");
}
catch (err) {
throw new Error(`Unable to read config file at ${configPath}: ${err}`);
}
try {
cachedRawConfig = JSON.parse(fileContents);
;
}
catch (err) {
throw new Error(`Invalid JSON in ${configPath}: ${err}`);
}
return cachedRawConfig;
}
/**
* Helper to retrieve a key and optionally coerce types.
*/
function getKey(key) {
const cfg = loadRawConfig();
return cfg[key];
}
/**
* Load a fully-typed ServiceConfig object.
*/
function loadServiceConfig() {
return {
isVideoUploadEnabled: Boolean(getKey("is_ch_video_upload_enabled")),
reportTimezone: getKey("report_timezone"),
chAZRVideoBlobSasUrl: getKey("ch_azure_video_blob_sas_url"),
isReportUploadEnabled: Boolean(getKey("is_ch_report_upload_enabled")),
mailSMTPHost: getKey("mail_smtp_host"),
mailSMTPPort: (() => {
const raw = getKey("mail_smtp_port");
if (typeof raw === "string") {
const n = parseInt(raw, 10);
return Number.isNaN(n) ? undefined : n;
}
return typeof raw === "number" ? raw : undefined;
})(),
isSessionDebugEnabled: Boolean(getKey("session_debug_enable")),
isMailSMTPStartTLSEnabled: Boolean(getKey("mail_smtp_starttls_enable")),
isMailSMTPSSLEnabled: Boolean(getKey("mail_smtp_ssl_enable")),
isMailSMTPAuthEnabled: Boolean(getKey("mail_smtp_auth_enable")),
isEmailEnabled: Boolean(getKey("is_email_enabled")),
fromAddress: getKey("from_address"),
toRecipients: (() => {
const raw = getKey("to_recipients");
if (Array.isArray(raw))
return raw;
if (typeof raw === "string")
return raw.split(/[,;]\s*/);
return undefined;
})(),
user: getKey("user"),
password: getKey("password"),
};
}
//# sourceMappingURL=service-config-loader.js.map