Closed rahulmr-ibm closed 1 month ago
when we are doing vm.createContext(global), we are not able to access window in the js files, even though we have injected window into context
You're trying to run vm
inside of vm
, which is not really supported. Why do you need to do that?
You're trying to run
vm
inside ofvm
, which is not really supported. Why do you need to do that?
Im working on a legacy js project, we don't have export and import. so we are using vm.createcontext
to inject some js files globally before all tests runs, especially some class
.
Is there any better approach to do this.
Also what do you mean by vm inside vm ?
inject some js files globally before all tests runs, especially some class. Is there any better approach to do this.
https://jestjs.io/docs/configuration#setupfiles-array should do what you want.
Also what do you mean by vm inside vm ?
Jest already runs all tests within separate vm contexts
inject some js files globally before all tests runs, especially some class. Is there any better approach to do this.
https://jestjs.io/docs/configuration#setupfiles-array should do what you want.
Also what do you mean by vm inside vm ?
Jest already runs all tests within separate vm contexts
Still we need to inject the class and singletons to the global object right ?. since we don't have exports and imports for example
var myVar = {};
myVar.getName = function(){
return 'rahul mr'
}
it('hello this is my test', () => {
console.log('hello', myVar.getName());
})
For this to work , we are required to run vm.runincontext()
with global as context
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
Version
29.7.0
Steps to reproduce
Create these files, then npm I and npm test Package.json
My jest config file
Jest setup. file
whenever I run this code in Node 20, im getting reference errors, working correctly in Node 16
Expected behavior
window and other Dom should be accessible for tests
Actual behavior
I'am working on a legacy project, I was running on node 16. I tried to upgrade node to 20, and seeing these errors. when run using vm.runInContext, not able to access window or document.
Additional context
No response
Environment