add tests for env options
This commit is contained in:
parent
62ad67e5d9
commit
8e84196eb8
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
11
packages/babel-core/test/fixtures/config/env/.babelrc
vendored
Normal file
11
packages/babel-core/test/fixtures/config/env/.babelrc
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"plugins": ["env-base"],
|
||||
"env": {
|
||||
"foo": {
|
||||
"plugins": ["env-foo"]
|
||||
},
|
||||
"bar": {
|
||||
"plugins": ["env-bar"]
|
||||
}
|
||||
}
|
||||
}
|
||||
1
packages/babel-core/test/fixtures/config/env/src.js
vendored
Normal file
1
packages/babel-core/test/fixtures/config/env/src.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
// empty
|
||||
Loading…
x
Reference in New Issue
Block a user