Replies: 5 comments 4 replies
-
Supported runtimes are browsers and node.js (see here for more details). Other runtimes like deno,... or toolings which modify a runtime to look like another may work but there is no guarantee nor tests. If I understand jest-environment-jsdom correct it uses node.js as runtime to simulate a browser. Maybe the simulation is incomplete which results in wrong variant of opentelemetry is used. Or the runtime detection of OTel is not good enough. Not sure if the runtime detection can be easily extended to detect jest-environment-jsdom as browser. Besides that I'm also not sure if the browser emulation of jest-environment-jsdom goes that far that everything (e.g. exporters,...) works like in a browser. Maybe @SimenB has some hints how to close this gap. |
Beta Was this translation helpful? Give feedback.
-
@SimenB I tried the link you sent and it works perfectly for the test files that have docblock at the top like this (browser env): /**
* @jest-environment jsdom
*/ But when it comes to the test files that actually need |
Beta Was this translation helpful? Give feedback.
-
@SimenB do you have any resolution on this? we are stuck with the resolver, can you advise how to have a resolver that will support both node and browser for a given app? |
Beta Was this translation helpful? Give feedback.
-
I got the issue as well. Jest + JSDom trying to test some tracing functionality. Calling span's end function I'm getting as well the issue about the unref function. |
Beta Was this translation helpful? Give feedback.
-
So far, I have found two ways of resolving it:
Here is a sample code that worked for me! // resolver.js
module.exports = function (file, options) {
// defaulting it to the default resolver
const resolver = require("resolve");
// run the resolver normally to find the full file path
let filepath = resolver.sync(file, {
basedir: options.basedir,
extensions: options.extensions,
moduleDirectory: options.moduleDirectory,
paths: options.paths,
});
// add a check to make sure we replace the file when we should
if (
filepath.indexOf(
"@opentelemetry/core/build/src/platform/node/timer-util.js"
) > -1
) {
filepath = filepath.replace("/node/", "/browser/");
}
return filepath;
}; And in your module.exports = {
resolver: // path_to_your_resolver.js
} |
Beta Was this translation helpful? Give feedback.
-
I have a test case, that runs using jsdom (@jest-environment jsdom) because it requires some window operations. One of the components involved in this test case, recently received telemetry support via the opentelemetry library. However the test case is throwing a
TypeError: timer.unref is not a function error
. I looked at the file that is throwing the error (timer-util.js), there are two implementations, the file from the node folder is being executed instead of the folder from the browser file. Am I missing some configuration maybe?Beta Was this translation helpful? Give feedback.
All reactions