Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Runner cleanup - for our internal tests #446

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,45 @@
<script src="../resources/benchmark-runner.mjs" type="module"></script>
<script src="benchmark-runner-tests.mjs" type="module"></script>
<script type="module">
const runner = mocha.run();
runner.on("end", function () {
const event = new Event("complete");
window.dispatchEvent(event);
});
window.mochaResults = runner;
function startTest() {
const runner = mocha.run();
window.mochaResults = runner;

function createReport(node) {
const tree = {
tests: [],
suites: [],
id: node.id,
title: node.title,
root: node.root,
};

for (const test of node.tests) {
tree.tests.push({
id: test.id,
title: test.title,
state: test.state,
error: {
name: test?.err?.name,
message: test?.err?.message,
},
});
}

for (const suite of node.suites) {
tree.suites.push(createReport(suite));
}

return tree;
}

runner.on("end", function () {
window.suite = createReport(runner.suite);
const event = new Event("test-complete");
window.dispatchEvent(event);
});
}
window.addEventListener("start-test", startTest);
</script>
</body>
</html>
53 changes: 43 additions & 10 deletions tests/run.mjs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -71,22 +70,56 @@ 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);

printTree(result.suite);

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("Tests complete");
console.log("\nTests complete!");
driver.quit();
server.close();
}
Expand Down
Loading