Skip to content

Commit

Permalink
Do not load root babel.config.js in tests (#13087)
Browse files Browse the repository at this point in the history
* Do not load root `babel.config.js` in tests

* Update packages/babel-helper-transform-fixture-test-runner/src/index.ts
  • Loading branch information
nicolo-ribaudo committed Apr 2, 2021
1 parent b577e44 commit 61e866f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/babel-helper-transform-fixture-test-runner/src/index.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -207,6 +219,7 @@ function run(task) {
sourceFileName: self.filename,
sourceType: "script",
babelrc: false,
configFile: false,
inputSourceMap: task.inputSourceMap || undefined,
...opts,
};
Expand Down

0 comments on commit 61e866f

Please sign in to comment.