Skip to content

Commit

Permalink
add stepper
Browse files Browse the repository at this point in the history
  • Loading branch information
camillobruni committed Oct 10, 2024
1 parent 657ee34 commit b8df80a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
16 changes: 11 additions & 5 deletions resources/developer-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,20 @@ function createUIForSuites() {
}

function createUIForRun() {
let button = document.createElement("button");
button.textContent = "Start Test";
button.onclick = (event) => {
const stepTestButton = document.createElement("button");
stepTestButton.textContent = "Step Test ⏯";
stepTestButton.onclick = (event) => {
globalThis.benchmarkClient.step();
};
const startTestButton = document.createElement("button");
startTestButton.textContent = "Start Test ⏵";
startTestButton.onclick = (event) => {
globalThis.benchmarkClient.start();
};
let buttons = document.createElement("div");
const buttons = document.createElement("div");
buttons.className = "button-bar";
buttons.appendChild(button);
buttons.appendChild(stepTestButton);
buttons.appendChild(startTestButton);
return buttons;
}

Expand Down
42 changes: 38 additions & 4 deletions resources/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,49 @@ class MainBenchmarkClient {
_hasResults = false;
_developerModeContainer = null;
_metrics = Object.create(null);
_steppingPromise = null;
_steppingResolver = null;

constructor() {
window.addEventListener("DOMContentLoaded", () => this.prepareUI());
this._showSection(window.location.hash);
}

start() {
if (this._startBenchmark())
if (this._isStepping())
this._clearStepping();
else if (this._startBenchmark())
this._showSection("#running");
}

step() {
const currentSteppingResolver = this._steppingResolver;
this._steppingPromise = new Promise((resolve) => {
this._steppingResolver = resolve;
});
if (this._isStepping())
currentSteppingResolver();
if (!this._isRunning) {
this._startBenchmark();
this._showSection("#running");
}
}

_clearStepping() {
this._steppingResolver();
this._steppingPromise = null;
this._steppingResolver = null;
}

async _awaitNextStep(suite, test) {
console.log(`Next Step: ${suite.name} ${test.name}`, { suite, test });
await this._steppingPromise;
}

_isStepping() {
return this._steppingResolver !== null;
}

_startBenchmark() {
if (this._isRunning)
return false;
Expand All @@ -44,8 +76,8 @@ class MainBenchmarkClient {

return false;
}

this._developerModeContainer?.remove();
if (!this._isStepping())
this._developerModeContainer?.remove();
this._progressCompleted = document.getElementById("progress-completed");
if (params.iterationCount < 50) {
const progressNode = document.getElementById("progress");
Expand Down Expand Up @@ -81,9 +113,11 @@ class MainBenchmarkClient {
frame.style.transform = "translate(-50%, -50%)";
}

willRunTest(suite, test) {
async willRunTest(suite, test) {
document.getElementById("info-label").textContent = suite.name;
document.getElementById("info-progress").textContent = `${this._finishedTestCount} / ${this.stepCount}`;
if (this._steppingPromise)
await this._awaitNextStep(suite, test);
}

didRunTest() {
Expand Down

0 comments on commit b8df80a

Please sign in to comment.