Skip to content

Commit 4662ad7

Browse files
committed
feat(vitest-plugin): add dynamic startInstruments function
1 parent 4b66b8f commit 4662ad7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/vitest-plugin/src/index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { getV8Flags, Measurement } from "@codspeed/core";
1+
import {
2+
getV8Flags,
3+
Measurement,
4+
mongoMeasurement,
5+
SetupInstrumentsRequestBody,
6+
SetupInstrumentsResponse,
7+
} from "@codspeed/core";
28
import { join } from "path";
39
import { Plugin } from "vite";
410
import { UserConfig } from "vitest/config";
@@ -45,3 +51,18 @@ export default function codspeedPlugin(): Plugin {
4551
},
4652
};
4753
}
54+
55+
/**
56+
* Dynamically setup the CodSpeed instruments.
57+
*/
58+
export async function setupInstruments(
59+
body: SetupInstrumentsRequestBody
60+
): Promise<SetupInstrumentsResponse> {
61+
if (!Measurement.isInstrumented()) {
62+
console.warn("[CodSpeed] No instrumentation found, using default mongoUrl");
63+
64+
return { remoteAddr: body.mongoUrl };
65+
}
66+
67+
return await mongoMeasurement.setupInstruments(body);
68+
}

0 commit comments

Comments
 (0)