(code, filename)
| 19 | import vm from 'vm'; |
| 20 | |
| 21 | export 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 | |
| 36 | Module._resolveFilename = (request, parent) => { |
| 37 | if (Module.builtinModules.includes(request)) { |
no outgoing calls
no test coverage detected