UNPKG

tdpw

Version:

CLI tool for uploading Playwright test reports to TestDino platform with TestDino storage support

73 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateJsonReport = validateJsonReport; exports.validateHtmlReportDir = validateHtmlReportDir; exports.validateTraceDir = validateTraceDir; const fs_1 = require("fs"); const path_1 = require("path"); const types_1 = require("../types"); /** * Validate that the JSON report exists and is parsable. */ async function validateJsonReport(jsonPath) { try { const stat = await fs_1.promises.stat(jsonPath); if (!stat.isFile()) { throw new types_1.ValidationError(`JSON report path is not a file: ${jsonPath}`); } } catch (error) { if (error instanceof types_1.ValidationError) throw error; throw new types_1.FileSystemError(`JSON report not found: ${jsonPath}`, error); } try { const content = await fs_1.promises.readFile(jsonPath, 'utf-8'); JSON.parse(content); } catch (error) { if (error instanceof SyntaxError) { throw new types_1.ValidationError(`Failed to parse JSON report: ${error.message}`); } throw error; } } /** * Validate that the HTML report directory exists and contains index.html. */ async function validateHtmlReportDir(htmlDir) { try { const stat = await fs_1.promises.stat(htmlDir); if (!stat.isDirectory()) { throw new types_1.ValidationError(`HTML report path is not a directory: ${htmlDir}`); } } catch (error) { throw new types_1.FileSystemError(`HTML report directory not found: ${htmlDir}`, error); } const indexPath = (0, path_1.join)(htmlDir, 'index.html'); try { const stat = await fs_1.promises.stat(indexPath); if (!stat.isFile()) { throw new types_1.ValidationError(`index.html not found in HTML report directory: ${htmlDir}`); } } catch { throw new types_1.ValidationError(`index.html not found in HTML report directory: ${htmlDir}`); } } /** * Validate that the trace directory exists. */ async function validateTraceDir(traceDir) { try { const stat = await fs_1.promises.stat(traceDir); if (!stat.isDirectory()) { throw new types_1.ValidationError(`Trace path is not a directory: ${traceDir}`); } } catch (error) { throw new types_1.FileSystemError(`Trace directory not found: ${traceDir}`, error); } } //# sourceMappingURL=validators.js.map