Skip to content

Commit 87fd28d

Browse files
committed
feat: add codspeed integration metadata dump
1 parent 59a7d8d commit 87fd28d

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

packages/benchmark.js/tests/unit.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import Benchmark from "benchmark";
55
import { withCodSpeed } from "..";
66
import type { Measurement } from "@codspeed/core";
77

8-
jest.mock("@codspeed/core", () => mockCore);
8+
jest.mock("@codspeed/core", () => ({
9+
...jest.requireActual("@codspeed/core"),
10+
measurement: mockCore,
11+
}));
912

1013
beforeEach(() => {
1114
mockReset(mockCore);

packages/core/rollup.config.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import resolve from "@rollup/plugin-node-resolve";
2+
import json from "@rollup/plugin-json";
3+
import commonjs from "@rollup/plugin-commonjs";
4+
import esbuild from "rollup-plugin-esbuild";
15
import { defineConfig } from "rollup";
2-
import { declarationsPlugin, jsPlugins } from "../../rollup.options";
6+
import { declarationsPlugin } from "../../rollup.options";
37

48
import pkg from "./package.json" assert { type: "json" };
5-
69
const entrypoint = "src/index.ts";
710

811
export default defineConfig([
@@ -27,6 +30,15 @@ export default defineConfig([
2730
},
2831
{ file: pkg.module, format: "es", sourcemap: true },
2932
],
30-
plugins: jsPlugins,
33+
plugins: [
34+
json(),
35+
esbuild({
36+
define: {
37+
__VERSION__: '"' + pkg.version + '"',
38+
},
39+
}),
40+
commonjs(),
41+
resolve(),
42+
],
3143
},
3244
]);

packages/core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from "path";
2+
declare const __VERSION__: string;
23

34
/* eslint-disable @typescript-eslint/no-empty-function */
45
export interface Measurement {
@@ -27,10 +28,10 @@ try {
2728
};
2829
}
2930
export const measurement = m;
30-
3131
export const initCore = () => {
3232
// eslint-disable-next-line @typescript-eslint/no-var-requires
3333
require("v8").setFlagsFromString("--allow-natives-syntax");
34+
measurement.stopInstrumentation(`Metadata: codspeed-node ${__VERSION__}`);
3435
};
3536

3637
export const optimizeFunction = async (fn: CallableFunction) => {

packages/core/tests/unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ beforeEach(() => {
77

88
describe("with bindings", () => {
99
it("should be bound", () => {
10-
const measurement = require("..") as Measurement;
10+
const measurement = require("..").measurement as Measurement;
1111
expect(measurement.isBound).toBe(true);
1212
});
1313
});
@@ -21,7 +21,7 @@ describe("without bindings", () => {
2121
process.env = initialEnv;
2222
});
2323
it("should not be bound", () => {
24-
const measurement = require("..") as Measurement;
24+
const measurement = require("..").measurement as Measurement;
2525
expect(measurement.isBound).toBe(false);
2626
});
2727
});

packages/tinybench/tests/unit.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { Bench } from "tinybench";
55
import { withCodSpeed } from "..";
66
import type { Measurement } from "@codspeed/core";
77

8-
jest.mock("@codspeed/core", () => mockCore);
8+
jest.mock("@codspeed/core", () => ({
9+
...jest.requireActual("@codspeed/core"),
10+
measurement: mockCore,
11+
}));
912

1013
beforeEach(() => {
1114
mockReset(mockCore);

0 commit comments

Comments
 (0)