From 6ca8275817f00a46293d1b280b7da41de4c52888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 3 Oct 2019 10:02:08 +0200 Subject: [PATCH] Add tests --- packages/babel-core/test/config-chain.js | 46 +++++++++++++++++++ .../babel-config-js-and-json/babel.config.js | 3 ++ .../babel.config.json | 3 ++ .../babel-config-js/babel.config.js | 3 ++ .../babel-config-json/babel.config.json | 3 ++ 5 files changed, 58 insertions(+) create mode 100644 packages/babel-core/test/fixtures/config/config-files/babel-config-js-and-json/babel.config.js create mode 100644 packages/babel-core/test/fixtures/config/config-files/babel-config-js-and-json/babel.config.json create mode 100644 packages/babel-core/test/fixtures/config/config-files/babel-config-js/babel.config.js create mode 100644 packages/babel-core/test/fixtures/config/config-files/babel-config-json/babel.config.json diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index 32513b1a4519..c5f6e2ebf205 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -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"); diff --git a/packages/babel-core/test/fixtures/config/config-files/babel-config-js-and-json/babel.config.js b/packages/babel-core/test/fixtures/config/config-files/babel-config-js-and-json/babel.config.js new file mode 100644 index 000000000000..409f4a98ac90 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babel-config-js-and-json/babel.config.js @@ -0,0 +1,3 @@ +module.exports = { + comments: true +}; diff --git a/packages/babel-core/test/fixtures/config/config-files/babel-config-js-and-json/babel.config.json b/packages/babel-core/test/fixtures/config/config-files/babel-config-js-and-json/babel.config.json new file mode 100644 index 000000000000..4b7be6033f68 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babel-config-js-and-json/babel.config.json @@ -0,0 +1,3 @@ +{ + "comments": true +} \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/config/config-files/babel-config-js/babel.config.js b/packages/babel-core/test/fixtures/config/config-files/babel-config-js/babel.config.js new file mode 100644 index 000000000000..409f4a98ac90 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babel-config-js/babel.config.js @@ -0,0 +1,3 @@ +module.exports = { + comments: true +}; diff --git a/packages/babel-core/test/fixtures/config/config-files/babel-config-json/babel.config.json b/packages/babel-core/test/fixtures/config/config-files/babel-config-json/babel.config.json new file mode 100644 index 000000000000..4b7be6033f68 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/config-files/babel-config-json/babel.config.json @@ -0,0 +1,3 @@ +{ + "comments": true +} \ No newline at end of file