From 7c2970b0c41ca8cffe0113e90fbef3b097cfaf73 Mon Sep 17 00:00:00 2001 From: Robert Hurst Date: Fri, 5 Apr 2024 10:56:07 +0200 Subject: [PATCH] Web Test Runner --- src/testRunner.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/testRunner.js b/src/testRunner.js index 22f660f..4d10dd3 100755 --- a/src/testRunner.js +++ b/src/testRunner.js @@ -77,6 +77,38 @@ export async function runTests(testDirectory) { } } +// Function to run a single test file +async function runWebTestFile(testFile) { + try { + await import(testFile); + } catch (error) { + console.error(`Error running test file ${testFile}:`); + console.error(error.stack); + failedTests++; + } +} + +// Function to run all test files +export async function runWebTests(testFiles) { + console.log(`Running ${testFiles.length} test file(s)`); + + // Run each test file sequentially + for (const file of testFiles) { + await runWebTestFile(file); + } + + // Print the test summary + console.log('Test Summary:'); + console.log(` Passed: ${passedTests}`); + console.log(` Failed: ${failedTests}`); + + // Return the test results + return { + passed: passedTests, + failed: failedTests + }; +} + // CLI function export function runCLI() { const testDirectory = process.argv[2];