-- Cat Haven - Test Runner -- Runs all tests and generates reports local busted = require('busted') local lfs = require('lfs') local testDirs = { 'test/spec', 'test/integration', 'test/e2e' } local testFiles = {} -- Find all test files for _, dir in ipairs(testDirs) do if lfs.attributes(dir, 'mode') == 'directory' then for file in lfs.dir(dir) do if file:match('.*_spec%.lua$') then table.insert(testFiles, dir .. '/' .. file) end end end end -- Run tests local success, results = busted.run(testFiles, { reporter = 'tap', color = false }) -- Generate JUnit XML report local function generateJUnitXML(results) local xml = '\n' xml = xml .. '\n' local totalTests = 0 local totalFailures = 0 local totalErrors = 0 for _, suite in ipairs(results.suites) do totalTests = totalTests + suite.tests totalFailures = totalFailures + suite.failures totalErrors = totalErrors + suite.errors end xml = xml .. ' \n' for _, suite in ipairs(results.suites) do xml = xml .. ' \n' if suite.errors > 0 then xml = xml .. ' \n' xml = xml .. ' ' .. suite.error .. '\n' xml = xml .. ' \n' end if suite.failures > 0 then for _, test in ipairs(suite.tests) do if test.status == 'failed' then xml = xml .. ' \n' xml = xml .. ' ' .. test.trace .. '\n' xml = xml .. ' \n' end end end xml = xml .. ' \n' end xml = xml .. ' \n' xml = xml .. '\n' return xml end -- Write XML report local xmlReport = generateJUnitXML(results) local file = io.open('test-report.xml', 'w') if file then file:write(xmlReport) file:close() print('\nXML report written to test-report.xml') end -- Output summary print('\n========================================') print('Test Summary') print('========================================') print('Suites:', results.suites) print('Tests:', results.tests) print('Passed:', results.passed) print('Failed:', results.failures) print('Errors:', results.errors) print('Skipped:', results.skipped) if results.failures > 0 or results.errors > 0 then print('\n❌ Tests failed') return 1 else print('\n✅ All tests passed') return 0 end