add tests for env options

This commit is contained in:
James Talmage 2016-07-07 16:36:34 -04:00
parent 62ad67e5d9
commit 8e84196eb8
3 changed files with 171 additions and 1 deletions

View File

@ -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);
});
});

View File

@ -0,0 +1,11 @@
{
"plugins": ["env-base"],
"env": {
"foo": {
"plugins": ["env-foo"]
},
"bar": {
"plugins": ["env-bar"]
}
}
}

View File

@ -0,0 +1 @@
// empty