Files
markitect-main/history/javascript-dev-tests/test_runner.js
tegwick c4877543d5 refactor: clean up JavaScript development files and enhance automated testing
Complete cleanup and modernization of JavaScript testing infrastructure with
comprehensive automated test coverage and improved output formatting.

JavaScript Development Files Cleanup:
- Moved 53 manual development/debugging test files to history/javascript-dev-tests/
- Added comprehensive README documenting archived files and their purposes
- Cleaned main project directory of development artifacts

New Automated Test Suite (68 tests):
- keyboard-shortcuts.test.js: Tests Ctrl+Enter, Escape, accessibility features (8 tests)
- section-splitting.test.js: Tests heading detection, content parsing, ID generation (14 tests)
- image-editing.test.js: Tests dialog positioning, alt text, reset functionality (19 tests)
- button-events.test.js: Tests click handling, state management, event delegation (21 tests)

Integration Test Fixes:
- Fixed 13 failing integration tests by properly mocking component dependencies
- Updated tests to match actual component APIs instead of assumed interfaces
- Improved error handling and test reliability

Enhanced Test Output Formatting:
- Updated testdrive-jsui-test-all target to show clear test count summaries
- Separated JavaScript (68 tests) and Python (11 tests) results distinctly
- Added combined summary showing total coverage (79 tests)
- Improved error handling and visual formatting

Main Makefile Improvements:
- Fixed default target issue by adding .DEFAULT_GOAL := help
- Restored proper make help behavior when called without arguments

Key Achievements:
- Replaced 53 manual test files with 68 automated tests
- Achieved 100% test pass rate (79/79 tests passing)
- Enhanced CI/CD integration with clear test reporting
- Preserved all critical UI functionality in automated test coverage
- Improved developer experience with clearer test output

Testing Status:
-  68 JavaScript tests (Jest) - Core UI functionality
-  11 Python tests (pytest) - Integration bridge testing
-  100% automated test coverage for critical functionality
-  Clean, maintainable test codebase

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 23:16:47 +01:00

290 lines
8.9 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* HTML Editor Test Runner
*
* This script provides a test environment for our HTML editor functionality
* using puppeteer for headless browser testing.
*/
const fs = require('fs');
const path = require('path');
// Simple test framework
class TestRunner {
constructor() {
this.tests = [];
this.results = [];
this.currentTest = null;
}
describe(description, testFn) {
console.log(`\n📋 Test Suite: ${description}`);
console.log('━'.repeat(50));
testFn();
}
it(description, testFn) {
this.tests.push({ description, testFn });
}
async run() {
console.log(`\n🚀 Running ${this.tests.length} tests...\n`);
for (const test of this.tests) {
this.currentTest = test;
try {
console.log(` 🧪 ${test.description}`);
await test.testFn();
this.results.push({ ...test, status: 'PASS' });
console.log(` ✅ PASS`);
} catch (error) {
this.results.push({ ...test, status: 'FAIL', error });
console.log(` ❌ FAIL: ${error.message}`);
}
}
this.printSummary();
}
printSummary() {
const passed = this.results.filter(r => r.status === 'PASS').length;
const failed = this.results.filter(r => r.status === 'FAIL').length;
console.log('\n' + '═'.repeat(50));
console.log(`📊 Test Results: ${passed} passed, ${failed} failed`);
if (failed > 0) {
console.log('\n❌ Failed Tests:');
this.results.filter(r => r.status === 'FAIL').forEach(test => {
console.log(`${test.description}: ${test.error.message}`);
});
}
console.log('═'.repeat(50));
}
expect(actual) {
const expectObj = {
toBe: (expected) => {
if (actual !== expected) {
throw new Error(`Expected ${expected}, got ${actual}`);
}
},
toContain: (expected) => {
if (!actual.includes(expected)) {
throw new Error(`Expected "${actual}" to contain "${expected}"`);
}
},
toBeTruthy: () => {
if (!actual) {
throw new Error(`Expected truthy value, got ${actual}`);
}
},
toBeFalsy: () => {
if (actual) {
throw new Error(`Expected falsy value, got ${actual}`);
}
},
toBeGreaterThan: (expected) => {
if (actual <= expected) {
throw new Error(`Expected ${actual} to be greater than ${expected}`);
}
},
toBeGreaterThanOrEqual: (expected) => {
if (actual < expected) {
throw new Error(`Expected ${actual} to be greater than or equal to ${expected}`);
}
},
toBeLessThan: (expected) => {
if (actual >= expected) {
throw new Error(`Expected ${actual} to be less than ${expected}`);
}
}
};
// Add 'not' property for negation
expectObj.not = {
toBe: (expected) => {
if (actual === expected) {
throw new Error(`Expected ${actual} not to be ${expected}`);
}
},
toContain: (expected) => {
if (actual.includes(expected)) {
throw new Error(`Expected "${actual}" not to contain "${expected}"`);
}
},
toBeTruthy: () => {
if (actual) {
throw new Error(`Expected falsy value, got ${actual}`);
}
},
toBeFalsy: () => {
if (!actual) {
throw new Error(`Expected truthy value, got ${actual}`);
}
}
};
return expectObj;
}
}
// HTML File Tester
class HTMLFileTester {
constructor(htmlFilePath) {
this.htmlFilePath = htmlFilePath;
this.html = null;
this.jsdom = null;
this.window = null;
this.document = null;
}
async load() {
try {
// Try to use jsdom if available
const { JSDOM } = require('jsdom');
this.html = fs.readFileSync(this.htmlFilePath, 'utf8');
// Create a DOM environment
this.jsdom = new JSDOM(this.html, {
runScripts: "dangerously",
resources: "usable",
pretendToBeVisual: true
});
this.window = this.jsdom.window;
this.document = this.window.document;
// Wait for content to load
await new Promise(resolve => {
if (this.document.readyState === 'complete') {
resolve();
} else {
this.window.addEventListener('load', resolve);
}
});
return true;
} catch (error) {
// Fallback to simple HTML parsing
this.html = fs.readFileSync(this.htmlFilePath, 'utf8');
console.log('⚠️ Using fallback HTML parsing (install jsdom for full testing)');
return false;
}
}
hasElement(selector) {
if (this.document) {
return !!this.document.querySelector(selector);
}
// Fallback: simple text search
return this.html.includes(selector);
}
getElement(selector) {
if (this.document) {
return this.document.querySelector(selector);
}
return null;
}
hasJavaScript(functionName) {
return this.html.includes(functionName);
}
hasDebugMode() {
return this.html.includes('DEBUG_MODE');
}
getDebugMode() {
const match = this.html.match(/const DEBUG_MODE = ['"`](\w+)['"`];/);
return match ? match[1] : null;
}
simulate(action, selector) {
if (!this.document) {
throw new Error('Cannot simulate actions without DOM environment');
}
const element = this.document.querySelector(selector);
if (!element) {
throw new Error(`Element not found: ${selector}`);
}
switch (action) {
case 'click':
element.click();
break;
case 'focus':
element.focus();
break;
default:
throw new Error(`Unknown action: ${action}`);
}
}
}
// Main test runner instance
const runner = new TestRunner();
// Export for use
module.exports = { TestRunner, HTMLFileTester, runner };
// If run directly, run basic tests
if (require.main === module) {
console.log('🧪 HTML Editor Test Runner');
console.log('Usage: node test_runner.js [html-file-path]');
const htmlFile = process.argv[2] || '/tmp/test_complete_functionality.html';
if (!fs.existsSync(htmlFile)) {
console.error(`❌ File not found: ${htmlFile}`);
process.exit(1);
}
// Basic structural tests
runner.describe('HTML Structure Tests', () => {
let tester;
runner.it('should load HTML file successfully', async () => {
tester = new HTMLFileTester(htmlFile);
const loaded = await tester.load();
runner.expect(loaded || tester.html).toBeTruthy();
});
runner.it('should have markdown content container', async () => {
runner.expect(tester.hasElement('#markdown-content')).toBeTruthy();
});
runner.it('should have debug system', async () => {
runner.expect(tester.hasDebugMode()).toBeTruthy();
});
runner.it('should use console debug mode', async () => {
runner.expect(tester.getDebugMode()).toBe('console');
});
runner.it('should have section editor functions', async () => {
runner.expect(tester.hasJavaScript('MarkitectCleanEditor')).toBeTruthy();
runner.expect(tester.hasJavaScript('showImageEditor')).toBeTruthy();
runner.expect(tester.hasJavaScript('setupAutoResize')).toBeTruthy();
});
runner.it('should have image manipulation functions', async () => {
runner.expect(tester.hasJavaScript('replaceImage')).toBeTruthy();
runner.expect(tester.hasJavaScript('resizeImage')).toBeTruthy();
runner.expect(tester.hasJavaScript('addImageCaption')).toBeTruthy();
runner.expect(tester.hasJavaScript('removeImage')).toBeTruthy();
});
});
// Run the tests
runner.run().then(() => {
console.log('\n🏁 Testing complete!');
}).catch(error => {
console.error('❌ Test runner failed:', error);
process.exit(1);
});
}