Skip to content

Commit

Permalink
Patch @codspeed/[email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Apr 30, 2024
1 parent f60caf4 commit b40652d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"[email protected]": "patches/[email protected]",
"@types/[email protected]": "patches/@[email protected]",
"@types/[email protected]": "patches/@[email protected]",
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"@codspeed/[email protected]": "patches/@[email protected]"
}
}
}
6 changes: 4 additions & 2 deletions packages/cli/src/benchmark/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function collectSuites() {
}

export function registerSuites(bench: Bench) {
for (const { hooks, tasks } of Object.values(suites)) {
for (const { name: suiteName, hooks, tasks } of Object.values(suites)) {
/**
* In tinybench, `beforeAll` and `afterAll` refer to all _iterations_ of
* a single task, while `beforeEach` and `afterEach` refer to each _iteration_.
Expand All @@ -40,7 +40,9 @@ export function registerSuites(bench: Bench) {
if (hooks.afterEachTask) options.afterAll = hooks.afterEachTask;

for (const t of tasks) {
bench.add(t.name, t.operation, options);
const taskName = process.env.CI === 'true' ? [suiteName, t.name].join('::') : t.name;

bench.add(taskName, t.operation, options);
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/dist/index.cjs.js b/dist/index.cjs.js
index a75964e40eaeff15df33fabd3c0bef20e9b1e5dd..42f2bec4950f13675ddccba675b2c207b2789d42 100644
--- a/dist/index.cjs.js
+++ b/dist/index.cjs.js
@@ -80,7 +80,12 @@ function withCodSpeed(bench) {
const rawAdd = bench.add;
bench.add = (name, fn, opts) => {
const callingFile = getCallingFile();
- const uri = `${callingFile}::${name}`;
+ let uri = `${callingFile}::${name}`;
+ if (name.includes('::')) {
+ // ignore calling file misdirecting to benchmark/lib/api.js
+ const [suiteName, taskName] = name.split('::');
+ uri = `${suiteName} - ${taskName}`
+ }
const options = Object.assign({}, opts ?? {}, { uri });
return rawAdd.bind(bench)(name, fn, options);
};
14 changes: 9 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b40652d

Please sign in to comment.