/**
* HVAC Community Events - Build System Validation Tests
*
* Comprehensive test suite for the JavaScript build pipeline including:
* - Webpack build process validation
* - Bundle generation verification
* - Security vulnerability testing
* - WordPress integration testing
* - Performance and compatibility validation
*
* @package HVAC_Community_Events
* @since 2.0.0
*/
const fs = require('fs').promises;
const path = require('path');
const { execSync, spawn } = require('child_process');
const { test, expect } = require('@playwright/test');
const BasePage = require('./page-objects/base/BasePage');
// Configuration
const BUILD_CONFIG = {
PROJECT_ROOT: path.resolve(__dirname, '..'),
BUILD_OUTPUT: path.resolve(__dirname, '../assets/js/dist'),
SOURCE_DIR: path.resolve(__dirname, '../src/js'),
WEBPACK_CONFIG: path.resolve(__dirname, '../webpack.config.js'),
MANIFEST_PATH: path.resolve(__dirname, '../assets/js/dist/manifest.json'),
EXPECTED_BUNDLES: [
'hvac-core.bundle.js',
'hvac-dashboard.bundle.js',
'hvac-certificates.bundle.js',
'hvac-master.bundle.js',
'hvac-trainer.bundle.js',
'hvac-events.bundle.js',
'hvac-admin.bundle.js',
'hvac-safari-compat.bundle.js'
],
// Security test payloads
SECURITY_PAYLOADS: {
XSS_MANIFEST: '{"hvac-core.js": ""}',
MALICIOUS_USER_AGENT: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"; maliciousScript();',
PATH_TRAVERSAL: '../../../../etc/passwd',
SQL_INJECTION: "'; DROP TABLE wp_users; --"
}
};
/**
* Build System Test Utilities
*/
class BuildSystemTestUtils {
/**
* Run webpack build command
* @param {string} mode - 'development' or 'production'
* @returns {Promise<{success: boolean, output: string, error?: string}>}
*/
static async runWebpackBuild(mode = 'production') {
return new Promise((resolve) => {
const buildCommand = mode === 'production' ? 'npm run build' : 'npm run build:dev';
const process = spawn('bash', ['-c', buildCommand], {
cwd: BUILD_CONFIG.PROJECT_ROOT,
stdio: ['pipe', 'pipe', 'pipe']
});
let output = '';
let errorOutput = '';
process.stdout.on('data', (data) => {
output += data.toString();
});
process.stderr.on('data', (data) => {
errorOutput += data.toString();
});
process.on('close', (code) => {
resolve({
success: code === 0,
output,
error: code !== 0 ? errorOutput : undefined
});
});
// Timeout after 60 seconds
setTimeout(() => {
process.kill('SIGTERM');
resolve({
success: false,
output,
error: 'Build process timed out after 60 seconds'
});
}, 60000);
});
}
/**
* Analyze bundle sizes
* @returns {Promise