Skip to content

Commit cef4fa4

Browse files
GuillaumeLagrangeart049
authored andcommitted
refactor(tinybench-plugin): call setupCore no matter the codspeed mode if not disabled
1 parent 9fc499c commit cef4fa4

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

packages/tinybench-plugin/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
getGitDir,
44
InstrumentHooks,
55
mongoMeasurement,
6+
setupCore,
67
SetupInstrumentsRequestBody,
78
SetupInstrumentsResponse,
89
tryIntrospect,
@@ -22,6 +23,7 @@ export function withCodSpeed(bench: Bench): Bench {
2223
if (codspeedRunnerMode === "disabled") {
2324
return bench;
2425
}
26+
setupCore();
2527

2628
const rootCallingFile = getCallingFile();
2729

packages/tinybench-plugin/src/instrumented.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
InstrumentHooks,
33
mongoMeasurement,
44
optimizeFunction,
5-
setupCore,
65
teardownCore,
76
} from "@codspeed/core";
87
import { Bench, Fn, FnOptions } from "tinybench";
@@ -18,7 +17,6 @@ export function runInstrumentedBench(
1817
console.log(
1918
`[CodSpeed] running with @codspeed/tinybench v${__VERSION__} (instrumented mode)`
2019
);
21-
setupCore();
2220

2321
for (const task of bench.tasks) {
2422
const uri = getTaskUri(bench, task.name, rootCallingFile);

packages/tinybench-plugin/tests/index.integ.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe("Benchmark.Suite", () => {
205205
expect(afterAll).toHaveBeenCalledTimes(2);
206206
});
207207

208-
it("should call setupCore and teardownCore only once after run()", async () => {
208+
it("should call setupCore and teardownCore only once", async () => {
209209
mockCore.InstrumentHooks.isInstrumented.mockReturnValue(true);
210210
const bench = withCodSpeed(new Bench())
211211
.add("RegExp", function () {
@@ -215,7 +215,7 @@ describe("Benchmark.Suite", () => {
215215
/o/.test("Hello World!");
216216
});
217217

218-
expect(mockCore.setupCore).not.toHaveBeenCalled();
218+
expect(mockCore.setupCore).toHaveBeenCalledTimes(1);
219219
expect(mockCore.teardownCore).not.toHaveBeenCalled();
220220

221221
await bench.run();

0 commit comments

Comments
 (0)