Add bench
to globals?
#6358
aleclarson
started this conversation in
Ideas
Replies: 2 comments
-
The workaround involving conditional diff --git a/benchmarks/globals.ts b/benchmarks/globals.ts
new file mode 100644
index 0000000..60fbddc
--- /dev/null
+++ b/benchmarks/globals.ts
@@ -0,0 +1,7 @@
+import * as vitest from 'vitest'
+
+declare global {
+ var bench: typeof import('vitest')['bench']
+}
+
+globalThis.bench = vitest.bench
diff --git a/vitest.config.ts b/vitest.config.ts
index 97c353d..677c287 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -3,7 +3,7 @@ import { defineConfig } from 'vitest/config'
const resolve = (specifier: string) =>
new URL(import.meta.resolve(specifier)).pathname
-export default defineConfig({
+export default defineConfig(env => ({
test: {
globals: true,
include: ['tests/**/*.test.ts'],
@@ -14,10 +14,11 @@ export default defineConfig({
thresholds: { 100: true },
include: ['src/**'],
},
+ setupFiles: env.mode === 'benchmark' ? ['benchmarks/globals.ts'] : [],
},
resolve: {
alias: {
radashi: resolve('./src/mod.js'),
},
},
-})
+})) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Make sense to me that it should be in globals: vitest/packages/vitest/globals.d.ts Line 1 in 8ff6356 vitest/packages/vitest/src/constants.ts Line 31 in 8ff6356 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It would be great to not have to import
bench
when the globals API is enabled.Beta Was this translation helpful? Give feedback.
All reactions