Skip to content

Commit a31ae7d

Browse files
committed
feat(vitest-runner): add mongo-measurement integration
1 parent 84f9b52 commit a31ae7d

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

packages/core/moon.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ tasks:
55
- generated/openapi
66
build:
77
deps:
8-
- "build-native-addon"
8+
- build-native-addon
9+
- build-tracer-client
910

1011
build-native-addon:
1112
command: prebuildify --napi --strip

packages/vitest-plugin/src/__tests__/runner.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const coreMocks = vi.hoisted(() => {
1111
},
1212
setupCore: vi.fn(),
1313
teardownCore: vi.fn(),
14+
mongoMeasurement: {
15+
start: vi.fn(),
16+
stop: vi.fn(),
17+
},
1418
};
1519
});
1620

@@ -44,7 +48,13 @@ describe("CodSpeedRunner", () => {
4448
);
4549

4650
// run
51+
expect(coreMocks.mongoMeasurement.start).toHaveBeenCalledWith(
52+
"packages/vitest-plugin/src/__tests__/runner.test.ts::test bench"
53+
);
54+
expect(coreMocks.Measurement.startInstrumentation).toHaveBeenCalledTimes(1);
4755
expect(benchFn).toHaveBeenCalledTimes(2);
56+
expect(coreMocks.Measurement.stopInstrumentation).toHaveBeenCalledTimes(1);
57+
expect(coreMocks.mongoMeasurement.stop).toHaveBeenCalledTimes(1);
4858
expect(console.log).toHaveBeenCalledWith(
4959
"[CodSpeed] packages/vitest-plugin/src/__tests__/runner.test.ts::test bench done"
5060
);
@@ -89,7 +99,13 @@ describe("CodSpeedRunner", () => {
8999
);
90100

91101
// run
102+
expect(coreMocks.mongoMeasurement.start).toHaveBeenCalledWith(
103+
"packages/vitest-plugin/src/__tests__/runner.test.ts::nested suite::test bench"
104+
);
105+
expect(coreMocks.Measurement.startInstrumentation).toHaveBeenCalledTimes(1);
92106
expect(benchFn).toHaveBeenCalledTimes(2);
107+
expect(coreMocks.Measurement.stopInstrumentation).toHaveBeenCalledTimes(1);
108+
expect(coreMocks.mongoMeasurement.stop).toHaveBeenCalledTimes(1);
93109
expect(console.log).toHaveBeenCalledWith(
94110
"[CodSpeed] packages/vitest-plugin/src/__tests__/runner.test.ts::nested suite::test bench done"
95111
);

packages/vitest-plugin/src/runner.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
getGitDir,
33
logDebug,
44
Measurement,
5+
mongoMeasurement,
56
optimizeFunction,
67
setupCore,
78
teardownCore,
@@ -48,12 +49,14 @@ async function runBenchmarkSuite(suite: Suite, parentSuiteName?: string) {
4849
const fn = getBenchFn(benchmark);
4950

5051
await optimizeFunction(fn);
52+
await mongoMeasurement.start(uri);
5153
await (async function __codspeed_root_frame__() {
5254
Measurement.startInstrumentation();
5355
// @ts-expect-error we do not need to bind the function to an instance of tinybench's Bench
5456
await fn();
5557
Measurement.stopInstrumentation(uri);
5658
})();
59+
await mongoMeasurement.stop(uri);
5760

5861
logCodSpeed(`${uri} done`);
5962
}
@@ -82,7 +85,10 @@ class CodSpeedRunner extends NodeBenchmarkRunner {
8285
await runBenchmarkSuite(suite);
8386
logCodSpeed(`running suite ${suite.name} done`);
8487

85-
teardownCore();
88+
const mongoAggregate = await teardownCore();
89+
logCodSpeed(
90+
`[CodSpeed] Mongo Aggregate: ${JSON.stringify(mongoAggregate, null, 2)}`
91+
);
8692
}
8793
}
8894

0 commit comments

Comments
 (0)