-
Notifications
You must be signed in to change notification settings - Fork 751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 BUG vitest-pool-workers loads opentelemetry for Node not the browser #6581
Comments
i am getting the same issue. is there any workaround to bypass open telemetry integration when running test cases? |
Running into this as well :( |
After messing with this for way too long, I found a solution that worked for me. I created a package that bundles Not sure what the real fix would be here. I think what's happening is that Vitest is loading all files without any treeshaking and then complaining because of Node-specific stuff that isn't supported in Workers. That's why pre-bundling with esbuild resolves the issue (and also speeds up vitest because it doesn't have to load nearly as many files.) If anyone wants to use this, I'd recommend copying this package for your own use, rather than relying on my version published to NPM. |
running into this issue |
Running into this issue as well. |
According to the issue linked above apparently fixable on the pool worker side |
You can shim this. This is only an example that works for me, you'll have to adapt the shim to proxy methods that you use.
export const createCFOtel = () => {
return {
handler: (handler) => {
return handler;
},
durableObject: (handler) => {
return handler;
},
};
};
export const trace = {
getActiveSpan: () => {
return {
setAttribute: () => {},
};
},
};
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
import path from 'node:path';
export default defineWorkersConfig({
resolve: {
alias: {
'@opentelemetry/api': path.join(process.cwd(), 'test', 'otel-shim.js'),
'@frend-digital/worker-utils/otel': path.join(process.cwd(), 'test', 'otel-shim.js'),
},
},
test: {
poolOptions: {
workers: {
main: './test/worker-test.ts',
wrangler: { configPath: './wrangler.toml' },
},
},
},
}); |
Also running this issue with libraries that depend on |
Which Cloudflare product(s) does this pertain to?
Workers Vitest Integration
What version(s) of the tool(s) are you using?
[email protected], @cloudflare/[email protected], @microlabs/[email protected]
What version of Node are you using?
v22.3.0
What operating system and version are you using?
OSX Sonoma 14.5, Macbook Air M2
Describe the Bug
Observed behavior
When running tests via vitest and vitest-pool-workers, it crashes due when I am also using the opentelemetry packages, since their node version is imported, instead of the compatible browser version. This only happens when running the tests, but not when running the dev server or deploying to cloudflare.
Expected behavior
I would expect it to work the same way it does for the dev server and my deployed applicatin
Steps to reproduce
I provided a simple reproduction here: https://github.com/KeKs0r/cf-vitest-otel
It just requires to install deps and run the tests.
Rererences
It feels very similar to Issue 1 described in this comment #5127 (comment) by @mrbbot
But potentially the package.json from open telemetry is different in some way.
Here their exports for reference:
Please provide a link to a minimal reproduction
https://github.com/KeKs0r/cf-vitest-otel
Please provide any relevant error logs
The text was updated successfully, but these errors were encountered: