Do not load root babel.config.js in tests (#13087)

* Do not load root `babel.config.js` in tests

* Update packages/babel-helper-transform-fixture-test-runner/src/index.ts
This commit is contained in:
Nicolò Ribaudo 2021-04-02 21:57:49 +02:00 committed by GitHub
parent b577e44d16
commit 61e866f6b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,11 +27,23 @@ const cachedScripts = new QuickLRU({ maxSize: 10 });
const contextModuleCache = new WeakMap();
const sharedTestContext = createContext();
// We never want our tests to accidentally load the root
// babel.config.js file, so we disable config loading by
// default. Tests can still set `configFile: true | string`
// to re-enable config loading.
function transformWithoutConfigFile(code, opts) {
return babel.transform(code, {
configFile: false,
babelrc: false,
...opts,
});
}
function createContext() {
const context = vm.createContext({
...helpers,
process: process,
transform: babel.transform,
transform: transformWithoutConfigFile,
setTimeout: setTimeout,
setImmediate: setImmediate,
expect,
@ -207,6 +219,7 @@ function run(task) {
sourceFileName: self.filename,
sourceType: "script",
babelrc: false,
configFile: false,
inputSourceMap: task.inputSourceMap || undefined,
...opts,
};