arda-site-scan
Version:
A standalone CLI tool for comprehensive website analysis including screenshots, SEO, and accessibility testing using Playwright
123 lines • 3.81 kB
JavaScript
;
/**
* Test Output Type System
*
* Defines standardized output behavior for all test types, ensuring consistent
* file generation and result handling across the application.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutputTypeUtils = exports.OUTPUT_CONFIGURATIONS = void 0;
/**
* Predefined output configurations for common test types
*/
exports.OUTPUT_CONFIGURATIONS = {
'screenshots': {
type: 'per-page',
fileExtension: 'png',
subdirectory: 'screenshots',
filenamePattern: '{pageName}-{viewport}',
includeInReports: true,
mimeType: 'image/png'
},
'seo': {
type: 'per-page',
fileExtension: 'md',
subdirectory: 'scans',
filenamePattern: '{pageName}-seo-scan',
includeInReports: true,
mimeType: 'text/markdown'
},
'accessibility': {
type: 'per-page',
fileExtension: 'md',
subdirectory: 'scans',
filenamePattern: '{pageName}-accessibility-scan',
includeInReports: true,
mimeType: 'text/markdown'
},
'content-scraping': {
type: 'per-page',
fileExtension: 'md',
subdirectory: 'content',
filenamePattern: '{pageName}-content',
includeInReports: true,
mimeType: 'text/markdown'
},
'sitemap': {
type: 'site-wide',
fileExtension: 'xml',
filenamePattern: 'sitemap',
includeInReports: true,
mimeType: 'application/xml'
},
'site-summary': {
type: 'site-wide',
fileExtension: 'md',
filenamePattern: 'site-summary',
includeInReports: true,
mimeType: 'text/markdown'
},
'api-key-scan': {
type: 'site-wide',
fileExtension: 'md',
filenamePattern: 'api-key-security-report',
includeInReports: true,
mimeType: 'text/markdown'
}
};
/**
* Utility functions for working with output types
*/
class OutputTypeUtils {
/**
* Check if a test type generates per-page output
*/
static isPerPageTest(testType) {
const config = exports.OUTPUT_CONFIGURATIONS[testType];
return config?.type === 'per-page';
}
/**
* Check if a test type generates site-wide output
*/
static isSiteWideTest(testType) {
const config = exports.OUTPUT_CONFIGURATIONS[testType];
return config?.type === 'site-wide';
}
/**
* Get the output configuration for a test type
*/
static getOutputConfig(testType) {
return exports.OUTPUT_CONFIGURATIONS[testType];
}
/**
* Replace placeholders in filename patterns
*/
static replacePlaceholders(pattern, context) {
return pattern
.replace(/{pageName}/g, context.pageName || 'unknown-page')
.replace(/{sessionId}/g, context.sessionId || 'unknown-session')
.replace(/{testType}/g, context.testType || 'unknown-test')
.replace(/{viewport}/g, context.viewport || '');
}
/**
* Validate that an output configuration is properly formed
*/
static validateOutputConfig(config) {
const errors = [];
if (!config.type || !['per-page', 'site-wide'].includes(config.type)) {
errors.push('Invalid or missing output type');
}
if (!config.fileExtension || config.fileExtension.trim().length === 0) {
errors.push('File extension is required');
}
if (config.fileExtension.includes('.')) {
errors.push('File extension should not include the dot');
}
return {
valid: errors.length === 0,
errors
};
}
}
exports.OutputTypeUtils = OutputTypeUtils;
//# sourceMappingURL=test-output-types.js.map