|
1 | | -import { BenchmarkRunner } from "../../resources/benchmark-runner.mjs"; |
| 1 | +import { BenchmarkRunner, BenchmarkTestStep } from "../../resources/benchmark-runner.mjs"; |
2 | 2 | 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"; |
4 | 5 | import { defaultParams } from "../../resources/shared/params.mjs"; |
5 | 6 |
|
6 | 7 | function TEST_FIXTURE(name) { |
@@ -109,8 +110,7 @@ describe("BenchmarkRunner", () => { |
109 | 110 | _loadFrameStub = stub(SuiteRunner.prototype, "_loadFrame").callsFake(async () => null); |
110 | 111 | _appendFrameStub = stub(runner, "_appendFrame").callsFake(async () => null); |
111 | 112 | _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")); |
114 | 114 | expect(runner._suites).not.to.have.length(0); |
115 | 115 | await runner.runAllSuites(); |
116 | 116 | }); |
@@ -256,4 +256,52 @@ describe("BenchmarkRunner", () => { |
256 | 256 | }); |
257 | 257 | }); |
258 | 258 | }); |
| 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 | + }); |
259 | 307 | }); |
0 commit comments