Only set options in cli if different from default (#4507)
* CLI: Only set options if different from default Currently default values (like comments: true) will be set always for the transform. This behaviour dos not allow for setting this options from babelrc as the default would always have precedence. * Add new tests for comments Also ensure that the babelrc in the fixture folder is copied over to the working directory during tests
This commit is contained in:
parent
993f887240
commit
ff78fb19f7
@ -107,7 +107,7 @@ if (errors.length) {
|
||||
let opts = exports.opts = {};
|
||||
|
||||
each(options, function (opt, key) {
|
||||
if (commander[key] !== undefined) {
|
||||
if (commander[key] !== undefined && commander[key] !== opt.default) {
|
||||
opts[key] = commander[key];
|
||||
}
|
||||
});
|
||||
|
||||
7
packages/babel-cli/test/fixtures/babel/filename --no-comments/in-files/script.js
vendored
Normal file
7
packages/babel-cli/test/fixtures/babel/filename --no-comments/in-files/script.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
Test comment
|
||||
*/
|
||||
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
|
||||
// END OF FILE
|
||||
3
packages/babel-cli/test/fixtures/babel/filename --no-comments/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/filename --no-comments/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "--out-file", "script2.js", "--no-comments"]
|
||||
}
|
||||
5
packages/babel-cli/test/fixtures/babel/filename --no-comments/out-files/script2.js
vendored
Normal file
5
packages/babel-cli/test/fixtures/babel/filename --no-comments/out-files/script2.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
3
packages/babel-cli/test/fixtures/babel/filename babelrc no comments/.babelrc
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/filename babelrc no comments/.babelrc
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"comments": false
|
||||
}
|
||||
7
packages/babel-cli/test/fixtures/babel/filename babelrc no comments/in-files/script.js
vendored
Normal file
7
packages/babel-cli/test/fixtures/babel/filename babelrc no comments/in-files/script.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
Test comment
|
||||
*/
|
||||
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
|
||||
// END OF FILE
|
||||
3
packages/babel-cli/test/fixtures/babel/filename babelrc no comments/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/filename babelrc no comments/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "--out-file", "script2.js"]
|
||||
}
|
||||
5
packages/babel-cli/test/fixtures/babel/filename babelrc no comments/out-files/script2.js
vendored
Normal file
5
packages/babel-cli/test/fixtures/babel/filename babelrc no comments/out-files/script2.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
7
packages/babel-cli/test/fixtures/babel/filename default comments/in-files/script.js
vendored
Normal file
7
packages/babel-cli/test/fixtures/babel/filename default comments/in-files/script.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
Test comment
|
||||
*/
|
||||
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
|
||||
// END OF FILE
|
||||
3
packages/babel-cli/test/fixtures/babel/filename default comments/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/filename default comments/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "--out-file", "script2.js"]
|
||||
}
|
||||
11
packages/babel-cli/test/fixtures/babel/filename default comments/out-files/script2.js
vendored
Normal file
11
packages/babel-cli/test/fixtures/babel/filename default comments/out-files/script2.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Test comment
|
||||
*/
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
|
||||
// END OF FILE
|
||||
@ -12,25 +12,24 @@ var fs = require("fs");
|
||||
var pathExists = require("path-exists");
|
||||
var _ = require("lodash");
|
||||
|
||||
var fixtureLoc = __dirname + "/fixtures";
|
||||
var tmpLoc = __dirname + "/tmp";
|
||||
var fixtureLoc = path.join(__dirname, "fixtures");
|
||||
var tmpLoc = path.join(__dirname, "tmp");
|
||||
|
||||
var presetLocs = [
|
||||
__dirname + "/../../babel-preset-es2015",
|
||||
__dirname + "/../../babel-preset-react"
|
||||
path.join(__dirname, "../../babel-preset-es2015"),
|
||||
path.join(__dirname, "../../babel-preset-react")
|
||||
].join(",");
|
||||
|
||||
var pluginLocs = [
|
||||
__dirname + "/../../babel-plugin-transform-strict-mode",
|
||||
__dirname + "/../../babel-plugin-transform-es2015-modules-commonjs",
|
||||
path.join(__dirname, "/../../babel-plugin-transform-strict-mode"),
|
||||
path.join(__dirname, "/../../babel-plugin-transform-es2015-modules-commonjs"),
|
||||
].join(",");
|
||||
|
||||
var readDir = function (loc) {
|
||||
var files = {};
|
||||
if (pathExists.sync(loc)) {
|
||||
_.each(readdir(loc), function (filename) {
|
||||
var contents = helper.readFile(loc + "/" + filename);
|
||||
files[filename] = contents;
|
||||
files[filename] = helper.readFile(path.join(loc, filename));
|
||||
});
|
||||
}
|
||||
return files;
|
||||
@ -77,7 +76,7 @@ var assertTest = function (stdout, stderr, opts) {
|
||||
};
|
||||
|
||||
var buildTest = function (binName, testName, opts) {
|
||||
var binLoc = path.normalize(__dirname + "/../../babel-cli/lib/" + binName);
|
||||
var binLoc = path.join(__dirname, "../lib", binName);
|
||||
|
||||
return function (callback) {
|
||||
this.timeout(5000);
|
||||
@ -142,22 +141,22 @@ var clear = function () {
|
||||
_.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
if (binName[0] === ".") return;
|
||||
|
||||
var suiteLoc = fixtureLoc + "/" + binName;
|
||||
var suiteLoc = path.join(fixtureLoc, binName);
|
||||
suite("bin/" + binName, function () {
|
||||
_.each(fs.readdirSync(fixtureLoc + "/" + binName), function (testName) {
|
||||
_.each(fs.readdirSync(suiteLoc), function (testName) {
|
||||
if (testName[0] === ".") return;
|
||||
|
||||
var testLoc = suiteLoc + "/" + testName;
|
||||
var testLoc = path.join(suiteLoc, testName);
|
||||
|
||||
var opts = {
|
||||
args: []
|
||||
};
|
||||
|
||||
var optionsLoc = testLoc + "/options.json"
|
||||
var optionsLoc = path.join(testLoc, "options.json");
|
||||
if (pathExists.sync(optionsLoc)) _.merge(opts, require(optionsLoc));
|
||||
|
||||
_.each(["stdout", "stdin", "stderr"], function (key) {
|
||||
var loc = testLoc + "/" + key + ".txt";
|
||||
var loc = path.join(testLoc, key + ".txt");
|
||||
if (pathExists.sync(loc)) {
|
||||
opts[key] = helper.readFile(loc);
|
||||
} else {
|
||||
@ -165,8 +164,14 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
}
|
||||
});
|
||||
|
||||
opts.outFiles = readDir(testLoc + "/out-files");
|
||||
opts.inFiles = readDir(testLoc + "/in-files");
|
||||
opts.outFiles = readDir(path.join(testLoc, "out-files"));
|
||||
opts.inFiles = readDir(path.join(testLoc, "in-files"));
|
||||
|
||||
var babelrcLoc = path.join(testLoc, ".babelrc");
|
||||
if (pathExists.sync(babelrcLoc)) {
|
||||
// copy .babelrc file to tmp directory
|
||||
opts.inFiles['.babelrc'] = helper.readFile(babelrcLoc);
|
||||
}
|
||||
|
||||
test(testName, buildTest(binName, testName, opts));
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user