tdpw
Version:
CLI tool for uploading Playwright test reports to TestDino platform with TestDino storage support
194 lines • 5.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.collectFilePaths = collectFilePaths;
exports.isAllowedForHtmlUpload = isAllowedForHtmlUpload;
exports.collectFilePathsForHtml = collectFilePathsForHtml;
exports.getContentType = getContentType;
const fs_1 = require("./fs");
const types_1 = require("../types");
const verbose_1 = require("./verbose");
/**
* Recursively collect all file paths under a directory
*/
async function collectFilePaths(dir) {
const files = [];
try {
const entries = await (0, fs_1.readDir)(dir);
for (const entry of entries) {
if (await (0, fs_1.isDirectory)(entry)) {
const nested = await collectFilePaths(entry);
files.push(...nested);
}
else if (await (0, fs_1.isFile)(entry)) {
files.push(entry);
}
}
return files;
}
catch (error) {
throw new types_1.FileSystemError(`Failed to collect files from directory: ${dir}`, error);
}
}
/**
* File extension sets for filtering HTML report uploads
*/
const HTML_REPORT_ALLOWED_EXTENSIONS = new Set([
// HTML files
'html',
'htm',
// CSS and JavaScript (needed for HTML reports)
'css',
'js',
'mjs',
// Images
'png',
'jpg',
'jpeg',
'gif',
'webp',
'svg',
'bmp',
'tiff',
// Videos
'webm',
'mp4',
'avi',
'mov',
'mkv',
// Other web assets (excluding json)
'ico',
'woff',
'woff2',
'ttf',
'eot',
]);
/**
* Check if a file should be included in HTML report uploads
*/
function isAllowedForHtmlUpload(filePath, config) {
const ext = filePath.toLowerCase().split('.').pop() || '';
// If no config provided, use the default behavior (all allowed extensions)
if (!config) {
return HTML_REPORT_ALLOWED_EXTENSIONS.has(ext);
}
// HTML, CSS, JS, and web assets only allowed with --upload-html
const webAssets = [
'html',
'htm',
'css',
'js',
'mjs',
'ico',
'woff',
'woff2',
'ttf',
'eot',
];
if (webAssets.includes(ext)) {
return config.uploadHtml;
}
// Exclude files with "trace" in the name for HTML uploads
const fileName = filePath.toLowerCase().split('/').pop() || '';
if (config.uploadHtml && fileName.includes('trace')) {
return false;
}
// Apply filtering based on config for media files
const imageExtensions = [
'png',
'jpg',
'jpeg',
'gif',
'webp',
'svg',
'bmp',
'tiff',
];
const videoExtensions = ['webm', 'mp4', 'avi', 'mov', 'mkv'];
if (imageExtensions.includes(ext)) {
return config.uploadImages || config.uploadHtml;
}
if (videoExtensions.includes(ext)) {
return config.uploadVideos || config.uploadHtml;
}
// Other extensions not allowed
return false;
}
/**
* Recursively collect file paths with optional filtering for HTML uploads
*/
async function collectFilePathsForHtml(dir, filterForHtml = false, config) {
const files = [];
const skippedFiles = [];
try {
const entries = await (0, fs_1.readDir)(dir);
for (const entry of entries) {
if (await (0, fs_1.isDirectory)(entry)) {
// Skip trace directories when uploading HTML
const dirName = entry.toLowerCase().split('/').pop() || '';
if (config?.uploadHtml && dirName.includes('trace')) {
continue; // Skip trace directories silently
}
const nested = await collectFilePathsForHtml(entry, filterForHtml, config);
files.push(...nested);
}
else if (await (0, fs_1.isFile)(entry)) {
// Apply filtering if requested
if (!filterForHtml || isAllowedForHtmlUpload(entry, config)) {
files.push(entry);
}
else if (filterForHtml) {
skippedFiles.push(entry);
}
}
}
if (filterForHtml &&
skippedFiles.length > 0 &&
(process.env.LOG_LEVEL === 'debug' || (0, verbose_1.isVerboseMode)())) {
console.log(`🚫 Filtered ${skippedFiles.length} files (traces, logs, etc.)`);
}
return files;
}
catch (error) {
throw new types_1.FileSystemError(`Failed to collect files from directory: ${dir}`, error);
}
}
/**
* Basic content-type detection based on file extension
*/
function getContentType(filePath) {
const ext = filePath.toLowerCase().split('.').pop() || '';
switch (ext) {
case 'html':
return 'text/html';
case 'css':
return 'text/css';
case 'js':
return 'application/javascript';
case 'json':
return 'application/json';
case 'png':
return 'image/png';
case 'jpg':
case 'jpeg':
return 'image/jpeg';
case 'svg':
return 'image/svg+xml';
case 'webm':
return 'video/webm';
case 'webp':
return 'image/webp';
case 'zip':
return 'application/zip';
case 'txt':
return 'text/plain';
case 'md':
return 'text/plain; charset=utf-8';
case 'pdf':
return 'application/pdf';
case 'log':
return 'text/plain; charset=utf-8';
default:
return 'application/octet-stream';
}
}
//# sourceMappingURL=files.js.map