Skip to content

Commit

Permalink
web: Add getTraceOutput util
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinnerbone authored and torokati44 committed Nov 13, 2023
1 parent 82cab61 commit 1bb96d8
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions web/packages/selfhosted/test/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require("path");
const { expect } = require("chai");

async function isRuffleLoaded(browser) {
return await browser.execute(
Expand Down Expand Up @@ -75,16 +76,34 @@ async function playAndMonitor(browser, player, expectedOutput) {
expectedOutput = "Hello from Flash!\n";
}

const actualOutput = await getTraceOutput(browser, player);
expect(actualOutput).to.eql(expectedOutput);
}

async function getTraceOutput(browser, player) {
// Await any trace output
await browser.waitUntil(
async () =>
(await browser.execute(
(player) => player.__ruffle_log__,
player,
)) === expectedOutput,
async () => {
return (
(await browser.execute(
(player) => player.__ruffle_log__,
player,
)) !== ""
);
},
{
timeoutMsg: "Expected Ruffle to trace a message",
},
);

// Get the output, and replace it with an empty string for any future test
const output = await browser.execute((player) => {
const log = player.__ruffle_log__;
player.__ruffle_log__ = "";
return log;
}, player);

return output;
}

async function injectRuffleAndWait(browser) {
Expand Down Expand Up @@ -141,4 +160,5 @@ module.exports = {
openTest,
setupErrorHandler,
jsApiBefore,
getTraceOutput,
};

0 comments on commit 1bb96d8

Please sign in to comment.