Skip to content

Commit 33251c0

Browse files
committed
fix
1 parent 8205951 commit 33251c0

4 files changed

Lines changed: 58 additions & 10 deletions

File tree

suites-experimental/javascript-wc-indexeddb/dist/src/speedometer-utils/benchmark.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export class BenchmarkStep {
1414
this.ignoreResult = ignoreResult;
1515
}
1616

17-
async runAndRecord(params, suite, test, callback) {
17+
async runAndRecord(params, suite, test) {
1818
const TestRunnerClass = params.useAsyncSteps ? AsyncTestRunner : TestRunner;
1919
const type = params.useAsyncSteps ? "async" : "sync";
20-
const testRunner = new TestRunnerClass(null, null, params, suite, test, callback, type);
20+
const testRunner = new TestRunnerClass(null, null, params, suite, test, type);
2121
const result = await testRunner.runTest();
2222
return result;
2323
}

suites-experimental/javascript-wc-indexeddb/src/speedometer-utils/benchmark.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export class BenchmarkStep {
1414
this.ignoreResult = ignoreResult;
1515
}
1616

17-
async runAndRecord(params, suite, test, callback) {
17+
async runAndRecord(params, suite, test) {
1818
const TestRunnerClass = params.useAsyncSteps ? AsyncTestRunner : TestRunner;
1919
const type = params.useAsyncSteps ? "async" : "sync";
20-
const testRunner = new TestRunnerClass(null, null, params, suite, test, callback, type);
20+
const testRunner = new TestRunnerClass(null, null, params, suite, test, type);
2121
const result = await testRunner.runTest();
2222
return result;
2323
}

suites/todomvc/vanilla-examples/javascript-web-components/dist/src/speedometer-utils/benchmark.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class BenchmarkStep {
1313
this.run = run;
1414
}
1515

16-
async runAndRecord(params, suite, test, callback) {
17-
const testRunner = new TestRunner(null, null, params, suite, test, callback);
16+
async runAndRecord(params, suite, test) {
17+
const testRunner = new TestRunner(null, null, params, suite, test);
1818
const result = await testRunner.runTest();
1919
return result;
2020
}

tests/unittests/benchmark-runner.mjs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { BenchmarkRunner } from "../../resources/benchmark-runner.mjs";
1+
import { BenchmarkRunner, BenchmarkTestStep } from "../../resources/benchmark-runner.mjs";
22
import { SuiteRunner } from "../../resources/suite-runner.mjs";
3-
import { StepRunner } from "../../resources/shared/step-runner.mjs";
3+
import { StepRunner, AsyncStepRunner } from "../../resources/shared/step-runner.mjs";
4+
import { STEP_SCHEDULER_LOOKUP } from "../../resources/shared/step-scheduler.mjs";
45
import { defaultParams } from "../../resources/shared/params.mjs";
56

67
function TEST_FIXTURE(name) {
@@ -109,8 +110,7 @@ describe("BenchmarkRunner", () => {
109110
_loadFrameStub = stub(SuiteRunner.prototype, "_loadFrame").callsFake(async () => null);
110111
_appendFrameStub = stub(runner, "_appendFrame").callsFake(async () => null);
111112
_removeFrameStub = stub(runner, "_removeFrame").callsFake(() => null);
112-
for (const suite of runner._suites)
113-
spy(suite, "prepare");
113+
runner._suites.forEach((suite) => spy(suite, "prepare"));
114114
expect(runner._suites).not.to.have.length(0);
115115
await runner.runAllSuites();
116116
});
@@ -256,4 +256,52 @@ describe("BenchmarkRunner", () => {
256256
});
257257
});
258258
});
259+
260+
describe("StepRunner", () => {
261+
const suite = SUITES_FIXTURE[0];
262+
const params = { measurementMethod: "raf", warmupBeforeSync: 0 };
263+
264+
it("should run StepRunner and return { syncTime, asyncTime }", async () => {
265+
const step = new BenchmarkTestStep("SyncStep", sinon.stub());
266+
const runner = new StepRunner(null, null, params, suite, step, "default");
267+
const { syncTime, asyncTime } = await runner.runStep();
268+
expect(typeof syncTime).to.equal("number");
269+
expect(typeof asyncTime).to.equal("number");
270+
assert.calledOnce(step.run);
271+
});
272+
273+
it("should run AsyncStepRunner and return { syncTime, asyncTime }", async () => {
274+
const asyncStep = new BenchmarkTestStep(
275+
"AsyncStep",
276+
sinon.stub().callsFake(async () => {})
277+
);
278+
const runner = new AsyncStepRunner(null, null, params, suite, asyncStep, "async");
279+
const { syncTime, asyncTime } = await runner.runStep();
280+
expect(typeof syncTime).to.equal("number");
281+
expect(typeof asyncTime).to.equal("number");
282+
assert.calledOnce(asyncStep.run);
283+
});
284+
});
285+
286+
describe("StepScheduler", () => {
287+
it("should schedule callbacks and resolve in RAFStepScheduler", async () => {
288+
const syncCallback = sinon.stub();
289+
const asyncCallback = sinon.stub();
290+
const scheduler = new STEP_SCHEDULER_LOOKUP.raf(syncCallback, asyncCallback, { waitBeforeSync: 0 });
291+
const result = await scheduler.start();
292+
expect(result).to.be(undefined);
293+
assert.calledOnce(syncCallback);
294+
assert.calledOnce(asyncCallback);
295+
});
296+
297+
it("should respect waitBeforeSync when starting scheduler", async () => {
298+
const syncCallback = sinon.stub();
299+
const asyncCallback = sinon.stub();
300+
const scheduler = new STEP_SCHEDULER_LOOKUP.raf(syncCallback, asyncCallback, { waitBeforeSync: 10 });
301+
const result = await scheduler.start();
302+
expect(result).to.be(undefined);
303+
assert.calledOnce(syncCallback);
304+
assert.calledOnce(asyncCallback);
305+
});
306+
});
259307
});

0 commit comments

Comments
 (0)