diff --git a/packages/babel-core/test/config-chain.js b/packages/babel-core/test/config-chain.js index 7c85714f82..9e796fc29d 100644 --- a/packages/babel-core/test/config-chain.js +++ b/packages/babel-core/test/config-chain.js @@ -10,7 +10,23 @@ function fixture() { return path.join.apply(path, args); } -suite("evaluation", function () { +suite("buildConfigChain", function () { + var oldBabelEnv; + var oldNodeEnv; + + beforeEach(function () { + oldBabelEnv = process.env.BABEL_ENV; + oldNodeEnv = process.env.NODE_ENV; + + delete process.env.BABEL_ENV; + delete process.env.NODE_ENV; + }); + + afterEach(function () { + process.env.BABEL_ENV = oldBabelEnv; + process.env.NODE_ENV = oldNodeEnv; + }); + test("dir1", function () { var chain = buildConfigChain({ filename: fixture("dir1", "src.js") @@ -98,4 +114,146 @@ suite("evaluation", function () { assert.deepEqual(chain, expected); }); + + test("env - base", function () { + var chain = buildConfigChain({ + filename: fixture("env", "src.js") + }); + + var expected = [ + { + options: { + plugins: [ + "env-base" + ] + }, + alias: fixture("env", ".babelrc"), + loc: fixture("env", ".babelrc"), + dirname: fixture("env") + }, + { + options: { + ignore: [ + "root-ignore" + ] + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture() + }, + { + options: { + filename: fixture("env", "src.js") + }, + alias: "base", + loc: "base", + dirname: fixture("env") + } + ]; + + assert.deepEqual(chain, expected); + }); + + test("env - foo", function () { + process.env.NODE_ENV = "foo"; + + var chain = buildConfigChain({ + filename: fixture("env", "src.js") + }); + + var expected = [ + { + options: { + plugins: [ + "env-base" + ] + }, + alias: fixture("env", ".babelrc"), + loc: fixture("env", ".babelrc"), + dirname: fixture("env") + }, + { + options: { + plugins: [ + "env-foo" + ] + }, + alias: fixture("env", ".babelrc.env.foo"), + loc: fixture("env", ".babelrc.env.foo"), + dirname: fixture("env") + }, + { + options: { + ignore: [ + "root-ignore" + ] + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture() + }, + { + options: { + filename: fixture("env", "src.js") + }, + alias: "base", + loc: "base", + dirname: fixture("env") + } + ]; + + assert.deepEqual(chain, expected); + }); + + test("env - bar", function () { + process.env.NODE_ENV = "foo"; // overridden + process.env.NODE_ENV = "bar"; + + var chain = buildConfigChain({ + filename: fixture("env", "src.js") + }); + + var expected = [ + { + options: { + plugins: [ + "env-base" + ] + }, + alias: fixture("env", ".babelrc"), + loc: fixture("env", ".babelrc"), + dirname: fixture("env") + }, + { + options: { + plugins: [ + "env-bar" + ] + }, + alias: fixture("env", ".babelrc.env.bar"), + loc: fixture("env", ".babelrc.env.bar"), + dirname: fixture("env") + }, + { + options: { + ignore: [ + "root-ignore" + ] + }, + alias: fixture(".babelignore"), + loc: fixture(".babelignore"), + dirname: fixture() + }, + { + options: { + filename: fixture("env", "src.js") + }, + alias: "base", + loc: "base", + dirname: fixture("env") + } + ]; + + assert.deepEqual(chain, expected); + }); }); diff --git a/packages/babel-core/test/fixtures/config/env/.babelrc b/packages/babel-core/test/fixtures/config/env/.babelrc new file mode 100644 index 0000000000..8804d3b2fb --- /dev/null +++ b/packages/babel-core/test/fixtures/config/env/.babelrc @@ -0,0 +1,11 @@ +{ + "plugins": ["env-base"], + "env": { + "foo": { + "plugins": ["env-foo"] + }, + "bar": { + "plugins": ["env-bar"] + } + } +} diff --git a/packages/babel-core/test/fixtures/config/env/src.js b/packages/babel-core/test/fixtures/config/env/src.js new file mode 100644 index 0000000000..8b1a393741 --- /dev/null +++ b/packages/babel-core/test/fixtures/config/env/src.js @@ -0,0 +1 @@ +// empty