Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/babel-helper-transform-fixture-test-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@ 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,
nicolo-ribaudo marked this conversation as resolved.
Show resolved Hide resolved
...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 +218,7 @@ function run(task) {
sourceFileName: self.filename,
sourceType: "script",
babelrc: false,
configFile: false,
inputSourceMap: task.inputSourceMap || undefined,
...opts,
};
Expand Down