// Runs bundle.js inside a `vm` context holding only the globals listed below, // so the bundle sees the same bare environment the embedded V8 engine gives it. const fs = require("fs") const vm = require("vm") const code = fs.readFileSync(__dirname + "/bundle.js", "utf8") // The host globals React's bundle touches at init and during a sync render. const sandbox = { console, setTimeout, clearTimeout, queueMicrotask, MessageChannel, performance, TextEncoder, TextDecoder, } sandbox.globalThis = sandbox vm.createContext(sandbox) vm.runInContext(code, sandbox) const html = sandbox.renderApp({ name: "World" }) const expected = '
Hello, World!
' if (html !== expected) { console.error(`expected ${expected}, got ${html}`) process.exit(1) } console.log(html) // The sandbox's MessageChannel holds an open handle, so the event loop never // drains on its own; exit once the render has been checked. process.exit(0)