From 7113787027e1dd25223fe5646b891018295988dc Mon Sep 17 00:00:00 2001 From: Thorsten Kober Date: Tue, 5 Nov 2024 11:27:13 -0500 Subject: [PATCH 1/7] rework test report --- tests/index.html | 39 +++++++++++++++++++++++++++++++--- tests/run.mjs | 54 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 80 insertions(+), 13 deletions(-) diff --git a/tests/index.html b/tests/index.html index 54a9242fe..3c6a7c50f 100644 --- a/tests/index.html +++ b/tests/index.html @@ -30,12 +30,45 @@ diff --git a/tests/run.mjs b/tests/run.mjs index a71f2fb57..d36cff1bf 100644 --- a/tests/run.mjs +++ b/tests/run.mjs @@ -1,6 +1,5 @@ #! /usr/bin/env node /* eslint-disable-next-line no-unused-vars */ -import { argv } from "node:process"; import serve from "./server.mjs"; import { Builder, Capabilities } from "selenium-webdriver"; import commandLineArgs from "command-line-args"; @@ -71,22 +70,57 @@ const server = serve(PORT); let driver; +function printTree(node) { + console.log(node.title); + + for (const test of node.tests) { + console.group(); + if (test.state === "passed") { + console.log("\x1b[32m✓", `\x1b[30m${ test.title}`); + } else { + console.log("\x1b[31m✖", `\x1b[30m${ test.title}`); + console.group(); + console.log(`\x1b[31m${test.error.name}: ${test.error.message}`); + console.groupEnd(); + } + console.groupEnd(); + } + + for (const suite of node.suites) { + console.group(); + printTree(suite); + console.groupEnd(); + } +} + async function test() { driver = await new Builder().withCapabilities(capabilities).build(); try { await driver.get(`http://localhost:${PORT}/tests/index.html`); - console.log("Waiting for tests to finish"); - const stats = await driver.executeAsyncScript(function (callback) { - window.addEventListener("complete", () => callback(window.mochaResults.stats), { once: true }); + const result = await driver.executeAsyncScript(function (callback) { + window.addEventListener( + "test-complete", + () => + callback({ + stats: window.mochaResults.stats, + suite: window.suite, + }), + { once: true } + ); + const event = new Event("start-test"); + window.dispatchEvent(event); }); - console.log("stats", stats); - console.log("Checking for passed tests"); - assert(stats.passes > 0); - console.log("Checking for failed tests"); - assert(stats.failures === 0); + + // console.log("stats", result.stats); + printTree(result.suite); + if (result.stats.failures > 0){ + console.error("\n\x1b[31m✖ Not all tests passed!\n"); + process.exit(1); + } + } finally { - console.log("Tests complete"); + console.log("\n\x1b[32m✓ Tests complete\n"); driver.quit(); server.close(); } From d077bf525739231a95401ed8341c9402aee51c4b Mon Sep 17 00:00:00 2001 From: Thorsten Kober Date: Tue, 5 Nov 2024 11:31:34 -0500 Subject: [PATCH 2/7] cleanup messaging --- tests/run.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run.mjs b/tests/run.mjs index d36cff1bf..ac731ecc6 100644 --- a/tests/run.mjs +++ b/tests/run.mjs @@ -120,7 +120,7 @@ async function test() { } } finally { - console.log("\n\x1b[32m✓ Tests complete\n"); + console.log("\n\x1b[32m✓ All tests passed!\n"); driver.quit(); server.close(); } From c93d2464a61f6b22b98de9cae175a25ac6dcad3c Mon Sep 17 00:00:00 2001 From: Thorsten Kober Date: Tue, 5 Nov 2024 11:32:10 -0500 Subject: [PATCH 3/7] remove console log --- tests/run.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/run.mjs b/tests/run.mjs index ac731ecc6..788cd2f53 100644 --- a/tests/run.mjs +++ b/tests/run.mjs @@ -112,7 +112,6 @@ async function test() { window.dispatchEvent(event); }); - // console.log("stats", result.stats); printTree(result.suite); if (result.stats.failures > 0){ console.error("\n\x1b[31m✖ Not all tests passed!\n"); From b3d82bde304f18be3d4431b4c0de57d8db69a71e Mon Sep 17 00:00:00 2001 From: Thorsten Kober Date: Tue, 5 Nov 2024 11:43:05 -0500 Subject: [PATCH 4/7] run format --- tests/index.html | 62 ++++++++++++++++++++++++------------------------ tests/run.mjs | 8 +++---- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/tests/index.html b/tests/index.html index 3c6a7c50f..a2eb9fad4 100644 --- a/tests/index.html +++ b/tests/index.html @@ -31,42 +31,42 @@ diff --git a/tests/run.mjs b/tests/run.mjs index 788cd2f53..f53a631ab 100644 --- a/tests/run.mjs +++ b/tests/run.mjs @@ -4,7 +4,6 @@ import serve from "./server.mjs"; import { Builder, Capabilities } from "selenium-webdriver"; import commandLineArgs from "command-line-args"; import commandLineUsage from "command-line-usage"; -import assert from "assert"; const optionDefinitions = [ { name: "browser", type: String, description: "Set the browser to test, choices are [safari, firefox, chrome]. By default the $BROWSER env variable is used." }, @@ -76,9 +75,9 @@ function printTree(node) { for (const test of node.tests) { console.group(); if (test.state === "passed") { - console.log("\x1b[32m✓", `\x1b[30m${ test.title}`); + console.log("\x1b[32m✓", `\x1b[30m${test.title}`); } else { - console.log("\x1b[31m✖", `\x1b[30m${ test.title}`); + console.log("\x1b[31m✖", `\x1b[30m${test.title}`); console.group(); console.log(`\x1b[31m${test.error.name}: ${test.error.message}`); console.groupEnd(); @@ -113,11 +112,10 @@ async function test() { }); printTree(result.suite); - if (result.stats.failures > 0){ + if (result.stats.failures > 0) { console.error("\n\x1b[31m✖ Not all tests passed!\n"); process.exit(1); } - } finally { console.log("\n\x1b[32m✓ All tests passed!\n"); driver.quit(); From 9a98948e794e6fe7e6776845c569ebfe13d6f8cd Mon Sep 17 00:00:00 2001 From: Thorsten Kober Date: Tue, 5 Nov 2024 11:50:22 -0500 Subject: [PATCH 5/7] add assertions back --- tests/benchmark-runner-tests.mjs | 2 +- tests/run.mjs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/benchmark-runner-tests.mjs b/tests/benchmark-runner-tests.mjs index 600516f1c..550ab3e65 100644 --- a/tests/benchmark-runner-tests.mjs +++ b/tests/benchmark-runner-tests.mjs @@ -164,7 +164,7 @@ describe("BenchmarkRunner", () => { }); it("should prepare the suite first", async () => { - assert.calledOnce(_prepareSuiteSpy); + assert.calledTwice(_prepareSuiteSpy); assert.calledOnce(_suitePrepareSpy); assert.calledOnce(_loadFrameStub); }); diff --git a/tests/run.mjs b/tests/run.mjs index f53a631ab..71aa1c01f 100644 --- a/tests/run.mjs +++ b/tests/run.mjs @@ -4,6 +4,7 @@ import serve from "./server.mjs"; import { Builder, Capabilities } from "selenium-webdriver"; import commandLineArgs from "command-line-args"; import commandLineUsage from "command-line-usage"; +import assert from "assert"; const optionDefinitions = [ { name: "browser", type: String, description: "Set the browser to test, choices are [safari, firefox, chrome]. By default the $BROWSER env variable is used." }, @@ -34,12 +35,10 @@ function printHelp(message = "") { const options = commandLineArgs(optionDefinitions); -if ("help" in options) - printHelp(); +if ("help" in options) printHelp(); const BROWSER = options?.browser; -if (!BROWSER) - printHelp("No browser specified, use $BROWSER or --browser"); +if (!BROWSER) printHelp("No browser specified, use $BROWSER or --browser"); let capabilities; switch (BROWSER) { @@ -112,12 +111,13 @@ async function test() { }); printTree(result.suite); - if (result.stats.failures > 0) { - console.error("\n\x1b[31m✖ Not all tests passed!\n"); - process.exit(1); - } + + console.log("\nChecking for passed tests..."); + assert(result.stats.passes > 0); + console.log("Checking for failed tests..."); + assert(result.stats.failures === 0); } finally { - console.log("\n\x1b[32m✓ All tests passed!\n"); + console.log("\nTests complete!"); driver.quit(); server.close(); } From 3a27fdfeb8bbc6432cf072f07d517f90418307ad Mon Sep 17 00:00:00 2001 From: Thorsten Kober Date: Tue, 5 Nov 2024 11:54:48 -0500 Subject: [PATCH 6/7] run format and undo test failure --- tests/benchmark-runner-tests.mjs | 2 +- tests/run.mjs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/benchmark-runner-tests.mjs b/tests/benchmark-runner-tests.mjs index 550ab3e65..600516f1c 100644 --- a/tests/benchmark-runner-tests.mjs +++ b/tests/benchmark-runner-tests.mjs @@ -164,7 +164,7 @@ describe("BenchmarkRunner", () => { }); it("should prepare the suite first", async () => { - assert.calledTwice(_prepareSuiteSpy); + assert.calledOnce(_prepareSuiteSpy); assert.calledOnce(_suitePrepareSpy); assert.calledOnce(_loadFrameStub); }); diff --git a/tests/run.mjs b/tests/run.mjs index 71aa1c01f..30c9f224e 100644 --- a/tests/run.mjs +++ b/tests/run.mjs @@ -35,10 +35,12 @@ function printHelp(message = "") { const options = commandLineArgs(optionDefinitions); -if ("help" in options) printHelp(); +if ("help" in options) + printHelp(); const BROWSER = options?.browser; -if (!BROWSER) printHelp("No browser specified, use $BROWSER or --browser"); +if (!BROWSER) + printHelp("No browser specified, use $BROWSER or --browser"); let capabilities; switch (BROWSER) { From 2c3079e39c8b8429a29664a1d74ea4c62c9578cd Mon Sep 17 00:00:00 2001 From: Thorsten Kober Date: Tue, 5 Nov 2024 14:35:02 -0500 Subject: [PATCH 7/7] adjust terminal colors --- tests/run.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run.mjs b/tests/run.mjs index 30c9f224e..32809347c 100644 --- a/tests/run.mjs +++ b/tests/run.mjs @@ -76,9 +76,9 @@ function printTree(node) { for (const test of node.tests) { console.group(); if (test.state === "passed") { - console.log("\x1b[32m✓", `\x1b[30m${test.title}`); + console.log("\x1b[32m✓", `\x1b[0m${test.title}`); } else { - console.log("\x1b[31m✖", `\x1b[30m${test.title}`); + console.log("\x1b[31m✖", `\x1b[0m${test.title}`); console.group(); console.log(`\x1b[31m${test.error.name}: ${test.error.message}`); console.groupEnd();