Creates a new require function which runs all required modules in a context other than
require extensions and
resolvers. Useful for things like mocking the
browser field without a bundler and using JSDOM (without using jsdom global) along side the native
commonjs require system.
Although other uses are possible this module was built to run tests in a browser like context with out using a bundler. Because modules are cached once per context this tool also makes it easy to isolate globals and state between tests running in the same process.
npm install context-require
;const browserRequire =;innerHTML; // <div>Hello World</div>
typeof global; // undefinedmoduleexports = documentbody;
npm testto build and run tests.
Please feel free to create a PR!