Add support for babel.config.json (#10501)

* Add support for babel.config.json root config

* Throw if multiple configuration files are found

* Add tests
This commit is contained in:
Devon Govett
2019-10-29 11:37:50 -07:00
committed by Nicolò Ribaudo
parent 38a3063111
commit 3a5e8a8dd4
6 changed files with 88 additions and 6 deletions

View File

@@ -944,6 +944,52 @@ describe("buildConfigChain", function() {
}
});
it("should load babel.config.json", () => {
const filename = fixture("config-files", "babel-config-json", "src.js");
expect(
loadOptions({
filename,
cwd: path.dirname(filename),
}),
).toEqual({
...getDefaults(),
filename: filename,
cwd: path.dirname(filename),
root: path.dirname(filename),
comments: true,
});
});
it("should load babel.config.js", () => {
const filename = fixture("config-files", "babel-config-js", "src.js");
expect(
loadOptions({
filename,
cwd: path.dirname(filename),
}),
).toEqual({
...getDefaults(),
filename: filename,
cwd: path.dirname(filename),
root: path.dirname(filename),
comments: true,
});
});
it("should whtow if both babel.config.json and babel.config.js are used", () => {
const filename = fixture(
"config-files",
"babel-config-js-and-json",
"src.js",
);
expect(() =>
loadOptions({ filename, cwd: path.dirname(filename) }),
).toThrow(/Multiple configuration files found/);
});
it("should load .babelrc", () => {
const filename = fixture("config-files", "babelrc", "src.js");

View File

@@ -0,0 +1,3 @@
module.exports = {
comments: true
};

View File

@@ -0,0 +1,3 @@
{
"comments": true
}

View File

@@ -0,0 +1,3 @@
module.exports = {
comments: true
};

View File

@@ -0,0 +1,3 @@
{
"comments": true
}