MCPcopy Index your code
hub / github.com/adobe/react-spectrum / evaluate

Function evaluate

packages/dev/test-utils/src/ssrUtils.js:21–34  ·  view source on GitHub ↗
(code, filename)

Source from the content-addressed store, hash-verified

19import vm from 'vm';
20
21export function evaluate(code, filename) {
22 // Setup a context to use as the global object when evaluating code.
23 // It will include React, along with a fake `require` function that resolves
24 // relative to the filename that's passed in (the test script.)
25 let ctx = {
26 React,
27 require(id) {
28 return require(Module._resolveFilename(id, {filename}));
29 }
30 };
31
32 vm.createContext(ctx);
33 return vm.runInContext(code, ctx);
34}
35
36Module._resolveFilename = (request, parent) => {
37 if (Module.builtinModules.includes(request)) {

Callers 2

testSSRFunction · 0.90
ssrWorker.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected