enable prefer const (#5113)
This commit is contained in:
@@ -1,29 +1,29 @@
|
||||
let readdir = require("fs-readdir-recursive");
|
||||
let helper = require("babel-helper-fixtures");
|
||||
let assert = require("assert");
|
||||
let rimraf = require("rimraf");
|
||||
let outputFileSync = require("output-file-sync");
|
||||
let child = require("child_process");
|
||||
let path = require("path");
|
||||
let chai = require("chai");
|
||||
let fs = require("fs");
|
||||
let _ = require("lodash");
|
||||
const readdir = require("fs-readdir-recursive");
|
||||
const helper = require("babel-helper-fixtures");
|
||||
const assert = require("assert");
|
||||
const rimraf = require("rimraf");
|
||||
const outputFileSync = require("output-file-sync");
|
||||
const child = require("child_process");
|
||||
const path = require("path");
|
||||
const chai = require("chai");
|
||||
const fs = require("fs");
|
||||
const _ = require("lodash");
|
||||
|
||||
let fixtureLoc = path.join(__dirname, "fixtures");
|
||||
let tmpLoc = path.join(__dirname, "tmp");
|
||||
const fixtureLoc = path.join(__dirname, "fixtures");
|
||||
const tmpLoc = path.join(__dirname, "tmp");
|
||||
|
||||
let presetLocs = [
|
||||
const presetLocs = [
|
||||
path.join(__dirname, "../../babel-preset-es2015"),
|
||||
path.join(__dirname, "../../babel-preset-react")
|
||||
].join(",");
|
||||
|
||||
let pluginLocs = [
|
||||
const pluginLocs = [
|
||||
path.join(__dirname, "/../../babel-plugin-transform-strict-mode"),
|
||||
path.join(__dirname, "/../../babel-plugin-transform-es2015-modules-commonjs"),
|
||||
].join(",");
|
||||
|
||||
let readDir = function (loc) {
|
||||
let files = {};
|
||||
const readDir = function (loc) {
|
||||
const files = {};
|
||||
if (fs.existsSync(loc)) {
|
||||
_.each(readdir(loc), function (filename) {
|
||||
files[filename] = helper.readFile(path.join(loc, filename));
|
||||
@@ -32,14 +32,14 @@ let readDir = function (loc) {
|
||||
return files;
|
||||
};
|
||||
|
||||
let saveInFiles = function (files) {
|
||||
const saveInFiles = function (files) {
|
||||
_.each(files, function (content, filename) {
|
||||
outputFileSync(filename, content);
|
||||
});
|
||||
};
|
||||
|
||||
let assertTest = function (stdout, stderr, opts) {
|
||||
let expectStderr = opts.stderr.trim();
|
||||
const assertTest = function (stdout, stderr, opts) {
|
||||
const expectStderr = opts.stderr.trim();
|
||||
stderr = stderr.trim();
|
||||
|
||||
if (opts.stderr) {
|
||||
@@ -52,7 +52,7 @@ let assertTest = function (stdout, stderr, opts) {
|
||||
throw new Error("stderr:\n" + stderr);
|
||||
}
|
||||
|
||||
let expectStdout = opts.stdout.trim();
|
||||
const expectStdout = opts.stdout.trim();
|
||||
stdout = stdout.trim();
|
||||
stdout = stdout.replace(/\\/g, "/");
|
||||
|
||||
@@ -67,13 +67,13 @@ let assertTest = function (stdout, stderr, opts) {
|
||||
}
|
||||
|
||||
_.each(opts.outFiles, function (expect, filename) {
|
||||
let actual = helper.readFile(filename);
|
||||
const actual = helper.readFile(filename);
|
||||
chai.expect(actual).to.equal(expect, "out-file " + filename);
|
||||
});
|
||||
};
|
||||
|
||||
let buildTest = function (binName, testName, opts) {
|
||||
let binLoc = path.join(__dirname, "../lib", binName);
|
||||
const buildTest = function (binName, testName, opts) {
|
||||
const binLoc = path.join(__dirname, "../lib", binName);
|
||||
|
||||
return function (callback) {
|
||||
clear();
|
||||
@@ -91,7 +91,7 @@ let buildTest = function (binName, testName, opts) {
|
||||
|
||||
args = args.concat(opts.args);
|
||||
|
||||
let spawn = child.spawn(process.execPath, args);
|
||||
const spawn = child.spawn(process.execPath, args);
|
||||
|
||||
let stderr = "";
|
||||
let stdout = "";
|
||||
@@ -127,7 +127,7 @@ let buildTest = function (binName, testName, opts) {
|
||||
};
|
||||
};
|
||||
|
||||
let clear = function () {
|
||||
const clear = function () {
|
||||
process.chdir(__dirname);
|
||||
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
|
||||
fs.mkdirSync(tmpLoc);
|
||||
@@ -137,22 +137,22 @@ let clear = function () {
|
||||
_.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
if (binName[0] === ".") return;
|
||||
|
||||
let suiteLoc = path.join(fixtureLoc, binName);
|
||||
const suiteLoc = path.join(fixtureLoc, binName);
|
||||
describe("bin/" + binName, function () {
|
||||
_.each(fs.readdirSync(suiteLoc), function (testName) {
|
||||
if (testName[0] === ".") return;
|
||||
|
||||
let testLoc = path.join(suiteLoc, testName);
|
||||
const testLoc = path.join(suiteLoc, testName);
|
||||
|
||||
let opts = {
|
||||
const opts = {
|
||||
args: []
|
||||
};
|
||||
|
||||
let optionsLoc = path.join(testLoc, "options.json");
|
||||
const optionsLoc = path.join(testLoc, "options.json");
|
||||
if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));
|
||||
|
||||
_.each(["stdout", "stdin", "stderr"], function (key) {
|
||||
let loc = path.join(testLoc, key + ".txt");
|
||||
const loc = path.join(testLoc, key + ".txt");
|
||||
if (fs.existsSync(loc)) {
|
||||
opts[key] = helper.readFile(loc);
|
||||
} else {
|
||||
@@ -163,7 +163,7 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
opts.outFiles = readDir(path.join(testLoc, "out-files"));
|
||||
opts.inFiles = readDir(path.join(testLoc, "in-files"));
|
||||
|
||||
let babelrcLoc = path.join(testLoc, ".babelrc");
|
||||
const babelrcLoc = path.join(testLoc, ".babelrc");
|
||||
if (fs.existsSync(babelrcLoc)) {
|
||||
// copy .babelrc file to tmp directory
|
||||
opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
|
||||
|
||||
Reference in New Issue
Block a user