Skip to content

Commit 85f6528

Browse files
chore: test ci
1 parent b3ebc91 commit 85f6528

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

packages/core/src/index.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ export const isBound = native_core.isBound;
1010

1111
export const mongoMeasurement = new MongoMeasurement();
1212

13-
export enum MeasurementMode {
14-
Instrumentation = "instrumentation",
15-
WallTime = "walltime",
16-
}
13+
type CodSpeedRunnerMode = "disabled" | "instrumented" | "walltime";
1714

18-
export function getMeasurementMode(): MeasurementMode {
15+
export function getCodspeedRunnerMode(): CodSpeedRunnerMode {
1916
const isCodSpeedEnabled = process.env.CODSPEED_ENV !== undefined;
20-
if (isCodSpeedEnabled) {
21-
// If CODSPEED_ENV is set, check CODSPEED_RUNNER_MODE
22-
if (process.env.CODSPEED_RUNNER_MODE === "walltime") {
23-
return MeasurementMode.WallTime;
24-
} else {
25-
return MeasurementMode.Instrumentation;
26-
}
17+
if (!isCodSpeedEnabled) {
18+
return "disabled";
19+
}
20+
21+
// If CODSPEED_ENV is set, check CODSPEED_RUNNER_MODE
22+
const codspeedRunnerMode = process.env.CODSPEED_RUNNER_MODE;
23+
if (codspeedRunnerMode === "instrumentation") {
24+
return "instrumented";
25+
} else if (codspeedRunnerMode === "walltime") {
26+
return "walltime";
2727
}
2828

29-
// Default to walltime mode when CODSPEED_ENV is not set
30-
return MeasurementMode.WallTime;
29+
console.warn("Unknown codspeed runner mode, defaulting to disabled");
30+
return "disabled";
3131
}
3232

3333
export const setupCore = () => {

packages/vitest-plugin/src/index.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
getCodspeedRunnerMode,
23
getV8Flags,
34
Measurement,
45
mongoMeasurement,
@@ -20,21 +21,12 @@ function getCodSpeedFileFromName(name: string) {
2021
}
2122

2223
function getRunnerFile(): string | undefined {
23-
// If CODSPEED_ENV is not set, use default vitest behavior
24-
if (!process.env.CODSPEED_ENV) {
25-
// TODO: Change this
26-
// return undefined;
27-
return getCodSpeedFileFromName("walltime");
24+
const codspeedRunnerMode = getCodspeedRunnerMode();
25+
if (codspeedRunnerMode === "disabled") {
26+
return undefined;
2827
}
2928

30-
const runnerMode = process.env.CODSPEED_RUNNER_MODE;
31-
32-
if (runnerMode === "instrumentation") {
33-
return getCodSpeedFileFromName("runner");
34-
} else {
35-
// Default to walltime mode (includes "walltime" mode and unrecognized modes)
36-
return getCodSpeedFileFromName("walltime");
37-
}
29+
return getCodSpeedFileFromName(codspeedRunnerMode);
3830
}
3931

4032
export default function codspeedPlugin(): Plugin {
@@ -44,7 +36,10 @@ export default function codspeedPlugin(): Plugin {
4436
if (mode !== "benchmark") {
4537
return false;
4638
}
47-
if (!Measurement.isInstrumented()) {
39+
if (
40+
getCodspeedRunnerMode() == "instrumented" &&
41+
!Measurement.isInstrumented()
42+
) {
4843
console.warn("[CodSpeed] bench detected but no instrumentation found");
4944
}
5045
return true;

packages/vitest-plugin/src/instrumented.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,5 @@ export class InstrumentedRunner extends NodeBenchmarkRunner {
105105
teardownCore();
106106
}
107107
}
108+
109+
export default InstrumentedRunner;

packages/vitest-plugin/src/walltime.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
9898
result as VitestTaskResult
9999
);
100100

101+
if (stats === null) {
102+
console.log(` ✔ No walltime data to collect for ${uri}`);
103+
return null;
104+
}
105+
101106
const coreBenchmark: Benchmark = {
102107
name: task.name,
103108
uri,
@@ -121,7 +126,7 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
121126

122127
private convertVitestResultToBenchmarkStats(
123128
result: VitestTaskResult
124-
): BenchmarkStats {
129+
): BenchmarkStats | null {
125130
const benchmark = result.benchmark;
126131

127132
if (!benchmark) {
@@ -138,6 +143,12 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
138143
const meanNs = ms_to_ns(mean);
139144
const stdevNs = ms_to_ns(sd);
140145

146+
if (sortedTimesNs.length == 0) {
147+
// Sometimes the benchmarks can be completely optimized out and not even run, but its beforeEach and afterEach hooks are still executed, and the task is still considered a success.
148+
// This is the case for the hooks.bench.ts example in this package
149+
return null;
150+
}
151+
141152
const {
142153
q1_ns,
143154
q3_ns,

0 commit comments

Comments
 (0)