add tests for build-config-chain
This commit is contained in:
@@ -95,7 +95,8 @@ class ConfigChainBuilder {
|
||||
if (lines.length) {
|
||||
this.mergeConfig({
|
||||
options: { ignore: lines },
|
||||
loc
|
||||
alias: loc,
|
||||
dirname: path.dirname(loc)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
101
packages/babel-core/test/config-chain.js
Normal file
101
packages/babel-core/test/config-chain.js
Normal file
@@ -0,0 +1,101 @@
|
||||
var assert = require("assert");
|
||||
var path = require("path");
|
||||
var buildConfigChain = require("../lib/transformation/file/options/build-config-chain");
|
||||
|
||||
function fixture() {
|
||||
var args = [__dirname, "fixtures", "config"];
|
||||
for (var i = 0; i < arguments.length; i ++) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
return path.join.apply(path, args);
|
||||
}
|
||||
|
||||
suite("evaluation", function () {
|
||||
test("dir1", function () {
|
||||
var chain = buildConfigChain({
|
||||
filename: fixture("dir1", "src.js")
|
||||
});
|
||||
|
||||
var expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
"extended"
|
||||
]
|
||||
},
|
||||
alias: fixture("extended.babelrc.json"),
|
||||
loc: fixture("extended.babelrc.json"),
|
||||
dirname: fixture()
|
||||
},
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
"root"
|
||||
]
|
||||
},
|
||||
alias: fixture(".babelrc"),
|
||||
loc: fixture(".babelrc"),
|
||||
dirname: fixture()
|
||||
},
|
||||
{
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore"
|
||||
]
|
||||
},
|
||||
alias: fixture(".babelignore"),
|
||||
loc: fixture(".babelignore"),
|
||||
dirname: fixture()
|
||||
},
|
||||
{
|
||||
options: {
|
||||
filename: fixture("dir1", "src.js")
|
||||
},
|
||||
alias: "base",
|
||||
loc: "base",
|
||||
dirname: fixture("dir1")
|
||||
}
|
||||
];
|
||||
|
||||
assert.deepEqual(chain, expected);
|
||||
});
|
||||
|
||||
test("dir2", function () {
|
||||
var chain = buildConfigChain({
|
||||
filename: fixture("dir2", "src.js")
|
||||
});
|
||||
|
||||
var expected = [
|
||||
{
|
||||
options: {
|
||||
plugins: [
|
||||
"dir2"
|
||||
]
|
||||
},
|
||||
alias: fixture("dir2", ".babelrc"),
|
||||
loc: fixture("dir2", ".babelrc"),
|
||||
dirname: fixture("dir2")
|
||||
},
|
||||
{
|
||||
options: {
|
||||
ignore: [
|
||||
"root-ignore"
|
||||
]
|
||||
},
|
||||
alias: fixture(".babelignore"),
|
||||
loc: fixture(".babelignore"),
|
||||
dirname: fixture()
|
||||
},
|
||||
{
|
||||
options: {
|
||||
filename: fixture("dir2", "src.js")
|
||||
},
|
||||
alias: "base",
|
||||
loc: "base",
|
||||
dirname: fixture("dir2")
|
||||
}
|
||||
];
|
||||
|
||||
assert.deepEqual(chain, expected);
|
||||
});
|
||||
});
|
||||
1
packages/babel-core/test/fixtures/config/.babelignore
vendored
Normal file
1
packages/babel-core/test/fixtures/config/.babelignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
root-ignore
|
||||
4
packages/babel-core/test/fixtures/config/.babelrc
vendored
Normal file
4
packages/babel-core/test/fixtures/config/.babelrc
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["root"],
|
||||
"extends": "./extended.babelrc.json"
|
||||
}
|
||||
1
packages/babel-core/test/fixtures/config/dir1/src.js
vendored
Normal file
1
packages/babel-core/test/fixtures/config/dir1/src.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
// empty
|
||||
5
packages/babel-core/test/fixtures/config/dir2/.babelrc
vendored
Normal file
5
packages/babel-core/test/fixtures/config/dir2/.babelrc
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"plugins": [
|
||||
"dir2"
|
||||
]
|
||||
}
|
||||
1
packages/babel-core/test/fixtures/config/dir2/src.js
vendored
Normal file
1
packages/babel-core/test/fixtures/config/dir2/src.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
// empty
|
||||
5
packages/babel-core/test/fixtures/config/extended.babelrc.json
vendored
Normal file
5
packages/babel-core/test/fixtures/config/extended.babelrc.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"plugins": [
|
||||
"extended"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user