add full bin test suite
This commit is contained in:
4
test/bin-fixtures/6to5-node/--eval/options.json
Normal file
4
test/bin-fixtures/6to5-node/--eval/options.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"args": ["--eval", "console.log([1, 2, 3].map(x => x * x));"],
|
||||
"stdout": "[ 1, 4, 9 ]"
|
||||
}
|
||||
4
test/bin-fixtures/6to5-node/--print/options.json
Normal file
4
test/bin-fixtures/6to5-node/--print/options.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"args": ["--print", "--eval", "([1, 2, 3].map(x => x * x))"],
|
||||
"stdout": "[ 1, 4, 9 ]"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
var foo = () => console.log("foo");
|
||||
foo();
|
||||
3
test/bin-fixtures/6to5-node/directory/options.json
Normal file
3
test/bin-fixtures/6to5-node/directory/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["foo"]
|
||||
}
|
||||
1
test/bin-fixtures/6to5-node/directory/stdout.txt
Normal file
1
test/bin-fixtures/6to5-node/directory/stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
||||
2
test/bin-fixtures/6to5-node/filename/in-files/foo.js
Normal file
2
test/bin-fixtures/6to5-node/filename/in-files/foo.js
Normal file
@@ -0,0 +1,2 @@
|
||||
var foo = () => console.log("foo");
|
||||
foo();
|
||||
3
test/bin-fixtures/6to5-node/filename/options.json
Normal file
3
test/bin-fixtures/6to5-node/filename/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["foo"]
|
||||
}
|
||||
1
test/bin-fixtures/6to5-node/filename/stdout.txt
Normal file
1
test/bin-fixtures/6to5-node/filename/stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
||||
2
test/bin-fixtures/6to5-node/filenames/in-files/bar.js
Normal file
2
test/bin-fixtures/6to5-node/filenames/in-files/bar.js
Normal file
@@ -0,0 +1,2 @@
|
||||
var bar = () => console.log("bar");
|
||||
bar();
|
||||
2
test/bin-fixtures/6to5-node/filenames/in-files/foo.js
Normal file
2
test/bin-fixtures/6to5-node/filenames/in-files/foo.js
Normal file
@@ -0,0 +1,2 @@
|
||||
var foo = () => console.log("foo");
|
||||
foo();
|
||||
3
test/bin-fixtures/6to5-node/filenames/options.json
Normal file
3
test/bin-fixtures/6to5-node/filenames/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["foo", "bar"]
|
||||
}
|
||||
2
test/bin-fixtures/6to5-node/filenames/stdout.txt
Normal file
2
test/bin-fixtures/6to5-node/filenames/stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
foo
|
||||
bar
|
||||
2
test/bin-fixtures/6to5-node/require/in-files/bar.js
Normal file
2
test/bin-fixtures/6to5-node/require/in-files/bar.js
Normal file
@@ -0,0 +1,2 @@
|
||||
var bar = () => console.log("bar");
|
||||
bar();
|
||||
4
test/bin-fixtures/6to5-node/require/in-files/foo.js
Normal file
4
test/bin-fixtures/6to5-node/require/in-files/foo.js
Normal file
@@ -0,0 +1,4 @@
|
||||
var foo = () => console.log("foo");
|
||||
foo();
|
||||
|
||||
import "./bar";
|
||||
3
test/bin-fixtures/6to5-node/require/options.json
Normal file
3
test/bin-fixtures/6to5-node/require/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["foo"]
|
||||
}
|
||||
2
test/bin-fixtures/6to5-node/require/stdout.txt
Normal file
2
test/bin-fixtures/6to5-node/require/stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
foo
|
||||
bar
|
||||
3
test/bin-fixtures/6to5/--blacklist/options.json
Normal file
3
test/bin-fixtures/6to5/--blacklist/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--blacklist", "arrowFunctions"]
|
||||
}
|
||||
3
test/bin-fixtures/6to5/--whitelist/options.json
Normal file
3
test/bin-fixtures/6to5/--whitelist/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "arrowFunctions"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
let MULTIPLER = 5;
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--source-maps-inline", "--out-dir", "lib"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
var Test = function() {
|
||||
function Test() {}
|
||||
return Test;
|
||||
}();
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGliL2Jhci9iYXIuanMiLCJzb3VyY2VzIjpbInNyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJJQUFNLENBQUMsQ0FBQyxDQUFDO1dBQUgsQ0FBQyxDQUFDLENBQUM7U0FBSCxDQUFDLENBQUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59Il19
|
||||
@@ -0,0 +1,4 @@
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGliL2Zvby5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLFVBQUM7U0FBSyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Q0FBQyxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0=
|
||||
@@ -0,0 +1,2 @@
|
||||
src/bar/bar.js -> lib/bar/bar.js
|
||||
src/foo.js -> lib/foo.js
|
||||
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--source-maps", "--out-dir", "lib"]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
var Test = function() {
|
||||
function Test() {}
|
||||
return Test;
|
||||
}();
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"lib/bar/bar.js","sources":["src/bar/bar.js"],"names":[],"mappings":"IAAM,CAAC,CAAC,CAAC;WAAH,CAAC,CAAC,CAAC;SAAH,CAAC,CAAC,CAAC","sourcesContent":["class Test {\n\n}"]}
|
||||
@@ -0,0 +1,3 @@
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"lib/foo.js","sources":["src/foo.js"],"names":[],"mappings":"AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAC;SAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAC,CAAC","sourcesContent":["arr.map(x => x * MULTIPLIER);"]}
|
||||
@@ -0,0 +1,2 @@
|
||||
src/bar/bar.js -> lib/bar/bar.js
|
||||
src/foo.js -> lib/foo.js
|
||||
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
|
||||
}
|
||||
1
test/bin-fixtures/6to5/dir --out-dir/in-files/src/foo.js
Normal file
1
test/bin-fixtures/6to5/dir --out-dir/in-files/src/foo.js
Normal file
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
3
test/bin-fixtures/6to5/dir --out-dir/options.json
Normal file
3
test/bin-fixtures/6to5/dir --out-dir/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib"]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
var Test = function() {
|
||||
function Test() {}
|
||||
return Test;
|
||||
}();
|
||||
@@ -0,0 +1,3 @@
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
2
test/bin-fixtures/6to5/dir --out-dir/stdout.txt
Normal file
2
test/bin-fixtures/6to5/dir --out-dir/stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
src/bar/bar.js -> lib/bar/bar.js
|
||||
src/foo.js -> lib/foo.js
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "--source-maps-inline", "--out-file", "script2.js"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLFVBQUM7U0FBSyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Q0FBQyxDQUFDIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ==
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
3
test/bin-fixtures/6to5/filename --out-file/options.json
Normal file
3
test/bin-fixtures/6to5/filename --out-file/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "--out-file", "script2.js"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "script2.js", "--source-maps-inline", "--out-file", "script3.js"]
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
var Test = function() {
|
||||
function Test() {}
|
||||
return Test;
|
||||
}();
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IklBQU0sQ0FBQyxDQUFDLENBQUM7V0FBSCxDQUFDLENBQUMsQ0FBQztTQUFILENBQUMsQ0FBQyxDQUFDOzs7QUNBVCxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLFVBQUM7U0FBSyxFQUFFLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Q0FBQyxDQUFDIiwiZmlsZSI6InNjcmlwdDMuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSIsImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19
|
||||
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "script2.js", "--source-maps", "--out-file", "script3.js"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
var Test = function() {
|
||||
function Test() {}
|
||||
return Test;
|
||||
}();
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":"IAAM,CAAC,CAAC,CAAC;WAAH,CAAC,CAAC,CAAC;SAAH,CAAC,CAAC,CAAC;;;ACAT,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAC;SAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAC,CAAC","file":"script3.js","sourcesContent":["class Test {\n\n}","arr.map(x => x * MULTIPLIER);"]}
|
||||
@@ -0,0 +1,3 @@
|
||||
class Test {
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
3
test/bin-fixtures/6to5/filenames --out-file/options.json
Normal file
3
test/bin-fixtures/6to5/filenames --out-file/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "script2.js", "--out-file", "script3.js"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
var Test = function() {
|
||||
function Test() {}
|
||||
return Test;
|
||||
}();
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
4
test/bin-fixtures/6to5/stdin --filename/options.json
Normal file
4
test/bin-fixtures/6to5/stdin --filename/options.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"args": ["--filename", "test.js"],
|
||||
"stderrContains": true
|
||||
}
|
||||
1
test/bin-fixtures/6to5/stdin --filename/stderr.txt
Normal file
1
test/bin-fixtures/6to5/stdin --filename/stderr.txt
Normal file
@@ -0,0 +1 @@
|
||||
Error: test.js: Line 2: Unexpected token ILLEGAL
|
||||
3
test/bin-fixtures/6to5/stdin --filename/stdin.txt
Normal file
3
test/bin-fixtures/6to5/stdin --filename/stdin.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
arr.map(x => {
|
||||
$@!
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--source-maps", "--out-file", "test.js"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
arr.map(function(x) {
|
||||
return x * x;
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["stdin"],"names":[],"mappings":"AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAC;SAAK,EAAE,EAAE;CAAC,CAAC","file":"test.js","sourcesContent":["arr.map(x => x * x);"]}
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * x);
|
||||
3
test/bin-fixtures/6to5/stdin --out-file/options.json
Normal file
3
test/bin-fixtures/6to5/stdin --out-file/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--out-file", "script.js"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
1
test/bin-fixtures/6to5/stdin --out-file/stdin.txt
Normal file
1
test/bin-fixtures/6to5/stdin --out-file/stdin.txt
Normal file
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--source-maps-inline"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * x);
|
||||
@@ -0,0 +1,5 @@
|
||||
arr.map(function(x) {
|
||||
return x * x;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsVUFBQztTQUFLLEVBQUUsRUFBRTtDQUFDLENBQUMiLCJmaWxlIjoic3Rkb3V0Iiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiB4KTsiXX0=
|
||||
1
test/bin-fixtures/6to5/stdin/stdin.txt
Normal file
1
test/bin-fixtures/6to5/stdin/stdin.txt
Normal file
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
3
test/bin-fixtures/6to5/stdin/stdout.txt
Normal file
3
test/bin-fixtures/6to5/stdin/stdout.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
arr.map(function(x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
162
test/bin.js
162
test/bin.js
@@ -1,24 +1,79 @@
|
||||
var assert = require("assert");
|
||||
var child = require("child_process");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var assert = require("assert");
|
||||
var rimraf = require("rimraf");
|
||||
var mkdirp = require("mkdirp");
|
||||
var child = require("child_process");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
var fixtureLoc = __dirname + "/bin-fixtures";
|
||||
var tmpLoc = __dirname + "/tmp";
|
||||
|
||||
var build = function (binName, testName, opts) {
|
||||
var testFixtureLoc = fixtureLoc + "/" + binName + "/" + testName;
|
||||
if (fs.existsSync(testFixtureLoc)) {
|
||||
_.each(fs.readdirSync(testFixtureLoc), function (filename) {
|
||||
var key = path.basename(filename, path.extname(filename));
|
||||
var file = fs.readFileSync(testFixtureLoc + "/" + filename, "utf8").trim();
|
||||
opts[key] = file;
|
||||
var readFile = function (filename) {
|
||||
return fs.readFileSync(filename, "utf8").trim();
|
||||
};
|
||||
|
||||
var readDir = function (loc) {
|
||||
var files = {};
|
||||
if (fs.existsSync(loc)) {
|
||||
_.each(readdir(loc), function (filename) {
|
||||
var contents = readFile(loc + "/" + filename);
|
||||
files[filename] = contents;
|
||||
});
|
||||
}
|
||||
return files;
|
||||
};
|
||||
|
||||
var saveInFiles = function (files) {
|
||||
_.each(files, function (content, filename) {
|
||||
var up = path.normalize(filename + "/..");
|
||||
mkdirp.sync(up);
|
||||
|
||||
fs.writeFileSync(filename, content);
|
||||
});
|
||||
};
|
||||
|
||||
var assertTest = function (stdout, stderr, opts) {
|
||||
var expectStderr = opts.stderr.trim();
|
||||
stderr = stderr.trim();
|
||||
|
||||
if (opts.stderr) {
|
||||
if (opts.stderrContains) {
|
||||
assert.ok(_.contains(stderr, expectStderr), "stderr didn't contain " + JSON.stringify(expectStderr));
|
||||
} else {
|
||||
assert.equal(stderr, expectStderr, "stderr didn't match");
|
||||
}
|
||||
} else if (stderr) {
|
||||
throw new Error("stderr: " + JSON.stringify(stderr));
|
||||
}
|
||||
|
||||
var expectStdout = opts.stdout.trim();
|
||||
stdout = stdout.trim();
|
||||
|
||||
if (opts.stdout) {
|
||||
if (opts.stdoutContains) {
|
||||
assert.ok(_.contains(stdout, expectStdout), "stdout didn't contain " + JSON.stringify(expectStdout));
|
||||
} else {
|
||||
assert.equal(stdout, expectStdout, "stdout didn't match");
|
||||
}
|
||||
} else if (stdout) {
|
||||
throw new Error("stdout: " + JSON.stringify(stdout));
|
||||
}
|
||||
|
||||
_.each(opts.outFiles, function (expect, filename) {
|
||||
var actual = readFile(filename);
|
||||
assert.equal(actual, expect, "out-file " + filename);
|
||||
});
|
||||
};
|
||||
|
||||
var build = function (binName, testName, opts) {
|
||||
var binLoc = path.normalize(__dirname + "/../bin/" + binName);
|
||||
|
||||
return function (callback) {
|
||||
var args = [__dirname + "/../bin/" + binName].concat(opts.args);
|
||||
saveInFiles(opts.inFiles);
|
||||
|
||||
var args = [binLoc].concat(opts.args);
|
||||
var spawn = child.spawn(process.execPath, args);
|
||||
|
||||
var stderr = "";
|
||||
@@ -34,26 +89,17 @@ var build = function (binName, testName, opts) {
|
||||
|
||||
spawn.on("close", function () {
|
||||
var err;
|
||||
|
||||
try {
|
||||
if (opts.stderr) {
|
||||
assert.equal(stderr.trim(), opts.stderr);
|
||||
} else if (stderr) {
|
||||
throw new Error("stderr: " + stderr);
|
||||
}
|
||||
|
||||
if (opts.stdout) {
|
||||
assert.equal(stdout.trim(), opts.stdout);
|
||||
} else if (stdout) {
|
||||
throw new Error("stdout: " + stdout);
|
||||
}
|
||||
|
||||
_.each(opts.files, function (expect, filename) {
|
||||
var actual = fs.readFileSync(filename, "utf8");
|
||||
assert.equal(actual, expect);
|
||||
});
|
||||
assertTest(stdout, stderr, opts);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
err.message = args.join(" ") + ": " + err.message;
|
||||
}
|
||||
|
||||
callback(err);
|
||||
});
|
||||
|
||||
@@ -65,41 +111,45 @@ var build = function (binName, testName, opts) {
|
||||
};
|
||||
|
||||
before(function () {
|
||||
if (!fs.existsSync(tmpLoc)) fs.mkdirSync(tmpLoc);
|
||||
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
|
||||
fs.mkdirSync(tmpLoc);
|
||||
process.chdir(tmpLoc);
|
||||
});
|
||||
|
||||
suite("bin/6to5", function () {
|
||||
test("--source-maps-inline");
|
||||
_.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
if (binName[0] === ".") return;
|
||||
|
||||
test("--source-maps");
|
||||
var suiteLoc = fixtureLoc + "/" + binName;
|
||||
suite("bin/" + binName, function () {
|
||||
_.each(fs.readdirSync(fixtureLoc + "/" + binName), function (testName) {
|
||||
if (testName[0] === ".") return;
|
||||
|
||||
test("--whitelist", build("6to5", "whitelist", {
|
||||
args: ["--whitelist", "arrowFunctions"]
|
||||
}));
|
||||
var testLoc = suiteLoc + "/" + testName;
|
||||
|
||||
test("--blacklist", build("6to5", "blacklist", {
|
||||
args: ["--blacklist", "arrowFunctions"]
|
||||
}));
|
||||
var opts = {
|
||||
args: []
|
||||
};
|
||||
|
||||
test("--out-file", build("6to5", "out-file", {
|
||||
args: ["--out-file", "script.js"],
|
||||
files: {
|
||||
"script.js": "(function() {\n var MULTIPLER = 5;\n arr.map(function(x) {\n return x * MULTIPLIER;\n });\n})();"
|
||||
}
|
||||
}));
|
||||
var optionsLoc = testLoc + "/options.json"
|
||||
if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));
|
||||
|
||||
test("--out-dir");
|
||||
_.each(["stdout", "stdin", "stderr"], function (key) {
|
||||
var loc = testLoc + "/" + key + ".txt";
|
||||
if (fs.existsSync(loc)) {
|
||||
opts[key] = readFile(loc);
|
||||
} else {
|
||||
opts[key] = opts[key] || "";
|
||||
}
|
||||
});
|
||||
|
||||
opts.outFiles = readDir(testLoc + "/out-files");
|
||||
opts.inFiles = readDir(testLoc + "/in-files");
|
||||
|
||||
test(testName, build(binName, testName, opts));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite("bin/6to5-node", function () {
|
||||
test("--eval", build("6to5-node", "eval", {
|
||||
args: ["--eval", "console.log([1, 2, 3].map(x => x * x));"],
|
||||
stdout: "[ 1, 4, 9 ]"
|
||||
}));
|
||||
|
||||
test("--print", build("6to5-node", "print", {
|
||||
args: ["--print", "--eval", "([1, 2, 3].map(x => x * x))"],
|
||||
stdout: "[ 1, 4, 9 ]"
|
||||
}));
|
||||
after(function () {
|
||||
rimraf.sync(tmpLoc);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user