UNPKG

playwright-archive

Version:

A lightweight CLI tool to archive and serve your Playwright test run history with a web interface. Useful for CI environments and local development.

90 lines (75 loc) 2.45 kB
#!/usr/bin/env node const express = require('express'); const path = require('path'); const fs = require('fs-extra'); const JsonReportParser = require('../utils/jsonReportParser'); const loadUserConfig = require('../utils/userConfig'); const serve = require('../server/index'); const args = process.argv.slice(2); if(args.length === 0 || args.includes('--help')) { showHelp(); process.exit(0); } function showHelp() { console.log(` playwright-history — CLI for managing Playwright run history Usage: --serve Launch the server to view run history --archive copy the latest Playwright report to archive --clear Clear the run history (delete files in run-history) --help Show this help message `); } async function archive() { const userConfig = loadUserConfig(); const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); const targetDir = path.join('./run-history', timestamp); // Check if we have a report to archive const srcDir = './playwright-report'; if (!fs.existsSync(srcDir)) { console.error('❌ Report not found for archiving. Please run tests first!'); process.exit(1); } // Create target directory fs.ensureDirSync(targetDir); // Copy report files fs.copySync(srcDir, path.join(targetDir, 'report')); console.log('✅ Report files copied to archive.'); // Copy metadata if available const archivePath = path.resolve("test-results", "pw-archive.json"); if (fs.existsSync(archivePath)) { fs.copySync(archivePath, path.join(targetDir, 'metadata.json')); console.log('✅ Metadata copied to archive.'); } else { console.log('ℹ️ No metadata file found to archive.'); } console.log(`✅ Report copied to ${targetDir}`); } function clear() { const dir = path.resolve('./run-history'); if (fs.existsSync(dir)) { fs.removeSync(dir); console.log('📂 Folder run-history cleared.'); } else { console.log('Folder not found: run-history'); } } async function main() { if (args.length === 0 || args.includes('--help')) { showHelp(); return; } if (args.includes('--serve')) { await serve(); } else if (args.includes('--archive')) { await archive(); } else if (args.includes('--clear')) { await clear(); } else { console.log('Unknown command. Try --help'); } } main();