Skip to content

Commit

Permalink
feat(vitest-plugin): add dynamic startInstruments function
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Jan 17, 2024
1 parent 4b66b8f commit 4662ad7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/vitest-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { getV8Flags, Measurement } from "@codspeed/core";
import {
getV8Flags,
Measurement,
mongoMeasurement,
SetupInstrumentsRequestBody,
SetupInstrumentsResponse,
} from "@codspeed/core";
import { join } from "path";
import { Plugin } from "vite";
import { UserConfig } from "vitest/config";
Expand Down Expand Up @@ -45,3 +51,18 @@ export default function codspeedPlugin(): Plugin {
},
};
}

/**
* Dynamically setup the CodSpeed instruments.
*/
export async function setupInstruments(
body: SetupInstrumentsRequestBody
): Promise<SetupInstrumentsResponse> {
if (!Measurement.isInstrumented()) {
console.warn("[CodSpeed] No instrumentation found, using default mongoUrl");

return { remoteAddr: body.mongoUrl };
}

return await mongoMeasurement.setupInstruments(body);
}

0 comments on commit 4662ad7

Please sign in to comment.