restructure testing infrastructure to be more modular
This commit is contained in:
7
test/core/_browser.js
Normal file
7
test/core/_browser.js
Normal file
@@ -0,0 +1,7 @@
|
||||
if (process.browser) {
|
||||
require("../../lib/babel/api/browser");
|
||||
require("./generation");
|
||||
require("./transformation");
|
||||
require("./traverse");
|
||||
require("./util");
|
||||
}
|
||||
25
test/core/_generator-helpers.js
Normal file
25
test/core/_generator-helpers.js
Normal file
@@ -0,0 +1,25 @@
|
||||
var assert = require("assert");
|
||||
|
||||
exports.check = function check(g, yields, returnValue) {
|
||||
for (var i = 0; i < yields.length; ++i) {
|
||||
var info = i > 0 ? g.next(i) : g.next();
|
||||
assert.deepEqual(info.value, yields[i]);
|
||||
assert.strictEqual(info.done, false);
|
||||
}
|
||||
|
||||
assert.deepEqual(
|
||||
i > 0 ? g.next(i) : g.next(),
|
||||
{ value: returnValue, done: true }
|
||||
);
|
||||
};
|
||||
|
||||
// A version of `throw` whose behavior can't be statically analyzed.
|
||||
// Useful for testing dynamic exception dispatching.
|
||||
exports.raise = function raise(argument) {
|
||||
throw argument;
|
||||
};
|
||||
|
||||
exports.assertAlreadyFinished = function assertAlreadyFinished(generator) {
|
||||
var item = generator.next();
|
||||
assert.ok(item.done && item.value === undefined, "not finished");
|
||||
};
|
||||
158
test/core/_helper.js
Normal file
158
test/core/_helper.js
Normal file
@@ -0,0 +1,158 @@
|
||||
var esvalid = require("esvalid");
|
||||
var util = require("../../lib/babel/util");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
var humanize = function (val, noext) {
|
||||
if (noext) val = path.basename(val, path.extname(val));
|
||||
return val.replace(/-/g, " ");
|
||||
};
|
||||
|
||||
var readFile = exports.readFile = function (filename) {
|
||||
if (fs.existsSync(filename)) {
|
||||
var file = fs.readFileSync(filename, "utf8").trim();
|
||||
file = file.replace(/\r\n/g, "\n");
|
||||
return file;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
exports.esvalid = function (ast, code, loc) {
|
||||
var errors = esvalid.errors(ast);
|
||||
if (errors.length) {
|
||||
var msg = [];
|
||||
_.each(errors, function (err) {
|
||||
msg.push(err.message + " - " + util.inspect(err.node));
|
||||
});
|
||||
throw new Error(loc + ": " + msg.join(". ") + "\n" + code);
|
||||
}
|
||||
};
|
||||
|
||||
exports.assertVendor = function (name) {
|
||||
if (!fs.existsSync(__dirname + "/../../vendor/" + name)) {
|
||||
console.error("No vendor/" + name + " - run `make bootstrap`");
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
exports.get = function (entryName, entryLoc) {
|
||||
if (exports.cache[entryName]) return exports.cache[entryName];
|
||||
|
||||
var suites = [];
|
||||
var entryLoc = entryLoc || __dirname + "/fixtures/" + entryName;
|
||||
|
||||
_.each(fs.readdirSync(entryLoc), function (suiteName) {
|
||||
if (suiteName[0] === ".") return;
|
||||
|
||||
var suite = {
|
||||
options: {},
|
||||
tests: [],
|
||||
title: humanize(suiteName),
|
||||
filename: entryLoc + "/" + suiteName
|
||||
};
|
||||
suites.push(suite);
|
||||
|
||||
var suiteOptsLoc = util.resolve(suite.filename + "/options");
|
||||
if (suiteOptsLoc) suite.options = require(suiteOptsLoc);
|
||||
|
||||
if (fs.statSync(suite.filename).isFile()) {
|
||||
push(suiteName, suite.filename);
|
||||
} else {
|
||||
_.each(fs.readdirSync(suite.filename), function (taskName) {
|
||||
var taskDir = suite.filename + "/" + taskName;
|
||||
push(taskName, taskDir);
|
||||
});
|
||||
}
|
||||
|
||||
function push(taskName, taskDir) {
|
||||
// tracuer error tests
|
||||
if (taskName.indexOf("Error_") >= 0) return;
|
||||
|
||||
var actualLocAlias = suiteName + "/" + taskName + "/actual.js";
|
||||
var expectLocAlias = suiteName + "/" + taskName + "/expected.js";
|
||||
var execLocAlias = suiteName + "/" + taskName + "/exec.js";
|
||||
|
||||
var actualLoc = taskDir + "/actual.js";
|
||||
var expectLoc = taskDir + "/expected.js";
|
||||
var execLoc = taskDir + "/exec.js";
|
||||
|
||||
if (fs.statSync(taskDir).isFile()) {
|
||||
var ext = path.extname(taskDir);
|
||||
if (ext !== ".js" && ext !== ".module.js") return;
|
||||
|
||||
execLoc = taskDir;
|
||||
}
|
||||
|
||||
var taskOpts = _.merge({
|
||||
filenameRelative: expectLocAlias,
|
||||
sourceFileName: actualLocAlias,
|
||||
sourceMapName: expectLocAlias
|
||||
}, _.cloneDeep(suite.options));
|
||||
|
||||
var taskOptsLoc = util.resolve(taskDir + "/options");
|
||||
if (taskOptsLoc) _.merge(taskOpts, require(taskOptsLoc));
|
||||
|
||||
var test = {
|
||||
title: humanize(taskName, true),
|
||||
disabled: taskName[0] === ".",
|
||||
options: taskOpts,
|
||||
exec: {
|
||||
loc: execLoc,
|
||||
code: readFile(execLoc),
|
||||
filename: execLocAlias,
|
||||
},
|
||||
actual: {
|
||||
loc: actualLoc,
|
||||
code: readFile(actualLoc),
|
||||
filename: actualLocAlias,
|
||||
},
|
||||
expect: {
|
||||
loc: expectLoc,
|
||||
code: readFile(expectLoc),
|
||||
filename: expectLocAlias
|
||||
}
|
||||
};
|
||||
|
||||
// traceur checks
|
||||
|
||||
var shouldSkip = function (code) {
|
||||
return code.indexOf("// Error:") >= 0 || code.indexOf("// Skip.") >= 0;
|
||||
};
|
||||
|
||||
if (shouldSkip(test.actual.code) || shouldSkip(test.exec.code)) {
|
||||
return;
|
||||
} else if (test.exec.code.indexOf("// Async.") >= 0) {
|
||||
//test.options.asyncExec = true;
|
||||
}
|
||||
|
||||
suite.tests.push(test);
|
||||
|
||||
var sourceMappingsLoc = taskDir + "/source-mappings.json";
|
||||
if (fs.existsSync(sourceMappingsLoc)) {
|
||||
test.options.sourceMap = true;
|
||||
test.sourceMappings = require(sourceMappingsLoc);
|
||||
}
|
||||
|
||||
var sourceMap = taskDir + "/source-map.json";
|
||||
if (fs.existsSync(sourceMap)) {
|
||||
test.options.sourceMap = true;
|
||||
test.sourceMap = require(sourceMap);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return exports.cache[entryName] = suites;
|
||||
};
|
||||
|
||||
try {
|
||||
exports.cache = require("../../tests.json");
|
||||
} catch (err) {
|
||||
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
||||
|
||||
var cache = exports.cache = {};
|
||||
cache.transformation = exports.get("transformation");
|
||||
cache.generation = exports.get("generation");
|
||||
cache.esnext = exports.get("esnext");
|
||||
}
|
||||
181
test/core/_transformation-helper.js
Normal file
181
test/core/_transformation-helper.js
Normal file
@@ -0,0 +1,181 @@
|
||||
var genHelpers = require("./_generator-helpers");
|
||||
var transform = require("../../lib/babel/transformation");
|
||||
var buildExernalHelpers = require("../../lib/babel/tools/build-external-helpers");
|
||||
var sourceMap = require("source-map");
|
||||
var codeFrame = require("../../lib/babel/helpers/code-frame");
|
||||
var Module = require("module");
|
||||
var helper = require("./_helper");
|
||||
var assert = require("assert");
|
||||
var chai = require("chai");
|
||||
var path = require("path");
|
||||
var util = require("../../lib/babel/util");
|
||||
var _ = require("lodash");
|
||||
|
||||
require("../../lib/babel/polyfill");
|
||||
|
||||
eval(buildExernalHelpers());
|
||||
|
||||
global.assertNoOwnProperties = function (obj) {
|
||||
assert.equal(Object.getOwnPropertyNames(obj).length, 0);
|
||||
};
|
||||
|
||||
global.assertHasOwnProperty = function () {
|
||||
|
||||
};
|
||||
|
||||
global.assertLacksOwnProperty = function () {
|
||||
|
||||
};
|
||||
|
||||
global.assertArrayEquals = assert.deepEqual;
|
||||
global.assert = chai.assert;
|
||||
global.chai = chai;
|
||||
global.genHelpers = genHelpers;
|
||||
|
||||
// Different Traceur generator message
|
||||
chai.assert._throw = chai.assert.throw;
|
||||
chai.assert.throw = function (fn, msg) {
|
||||
if (msg === '"throw" on executing generator' ||
|
||||
msg === '"next" on executing generator') {
|
||||
msg = "Generator is already running";
|
||||
} else if (msg === "Sent value to newborn generator") {
|
||||
msg = /^attempt to send (.*?) to newborn generator$/;
|
||||
} else if (msg === "super prototype must be an Object or null") {
|
||||
msg = "Object prototype may only be an Object or null";
|
||||
}
|
||||
|
||||
return chai.assert._throw(fn, msg);
|
||||
};
|
||||
|
||||
var run = function (task, done) {
|
||||
var actual = task.actual;
|
||||
var expect = task.expect;
|
||||
var exec = task.exec;
|
||||
var opts = task.options;
|
||||
|
||||
var getOpts = function (self) {
|
||||
return _.merge({
|
||||
suppressDeprecationMessages: true,
|
||||
filename: self.loc
|
||||
}, opts);
|
||||
};
|
||||
|
||||
var execCode = exec.code;
|
||||
var result;
|
||||
|
||||
var noCheckAst = opts.noCheckAst;
|
||||
delete opts.noCheckAst;
|
||||
|
||||
var checkAst = function (result, opts) {
|
||||
if (noCheckAst) return;
|
||||
helper.esvalid(result.ast.program, result.code, opts.loc);
|
||||
};
|
||||
|
||||
if (execCode) {
|
||||
result = transform(execCode, getOpts(exec));
|
||||
execCode = result.code;
|
||||
|
||||
try {
|
||||
var fakeRequire = function (loc) {
|
||||
if (loc === "../../../src/runtime/polyfills/Number.js") {
|
||||
return Number;
|
||||
} else if (loc === "../../../src/runtime/polyfills/Math.js") {
|
||||
return Math;
|
||||
} else {
|
||||
return require(path.resolve(exec.loc, "..", loc));
|
||||
}
|
||||
};
|
||||
|
||||
var fn = new Function("require", "done", "exports", execCode);
|
||||
fn.call(global, fakeRequire, chai.assert, {}, done);
|
||||
} catch (err) {
|
||||
err.message = exec.loc + ": " + err.message;
|
||||
err.message += codeFrame(execCode);
|
||||
throw err;
|
||||
}
|
||||
|
||||
checkAst(result, exec);
|
||||
}
|
||||
|
||||
var actualCode = actual.code;
|
||||
var expectCode = expect.code;
|
||||
if (!execCode || actualCode) {
|
||||
result = transform(actualCode, getOpts(actual));
|
||||
actualCode = result.code.trim();
|
||||
|
||||
try {
|
||||
chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc);
|
||||
} catch (err) {
|
||||
//require("fs").writeFileSync(expect.loc, actualCode);
|
||||
throw err;
|
||||
}
|
||||
|
||||
checkAst(result, actual);
|
||||
}
|
||||
|
||||
if (task.sourceMap) {
|
||||
chai.expect(result.map).to.deep.equal(task.sourceMap);
|
||||
}
|
||||
|
||||
if (task.sourceMappings) {
|
||||
var consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
|
||||
_.each(task.sourceMappings, function (mapping, i) {
|
||||
var actual = mapping.original;
|
||||
|
||||
var expect = consumer.originalPositionFor(mapping.generated);
|
||||
chai.expect({ line: expect.line, column: expect.column }).to.deep.equal(actual);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function (suiteOpts, taskOpts, dynamicOpts) {
|
||||
taskOpts = taskOpts || {};
|
||||
|
||||
_.each(helper.get(suiteOpts.name, suiteOpts.loc), function (testSuite) {
|
||||
if (_.contains(suiteOpts.ignoreSuites, testSuite.title)) return;
|
||||
|
||||
suite(suiteOpts.name + "/" + testSuite.title, function () {
|
||||
setup(function () {
|
||||
require("../../register")(taskOpts);
|
||||
});
|
||||
|
||||
_.each(testSuite.tests, function (task) {
|
||||
if (_.contains(suiteOpts.ignoreTasks, task.title) || _.contains(suiteOpts.ignoreTasks, testSuite.title + "/" + task.title)) return;
|
||||
|
||||
var runTest = function (done) {
|
||||
var runTask = function () {
|
||||
run(task, done);
|
||||
};
|
||||
|
||||
_.extend(task.options, taskOpts);
|
||||
if (dynamicOpts) dynamicOpts(task.options, task);
|
||||
|
||||
var throwMsg = task.options.throws;
|
||||
if (throwMsg) {
|
||||
// internal api doesn't have this option but it's best not to pollute
|
||||
// the options object with useless options
|
||||
delete task.options.throws;
|
||||
|
||||
assert.throws(runTask, function (err) {
|
||||
return throwMsg === true || err.message.indexOf(throwMsg) >= 0;
|
||||
});
|
||||
} else {
|
||||
runTask();
|
||||
}
|
||||
};
|
||||
|
||||
var callback;
|
||||
if (task.options.asyncExec) {
|
||||
callback = runTest;
|
||||
} else {
|
||||
callback = function () {
|
||||
return runTest();
|
||||
};
|
||||
}
|
||||
|
||||
test(task.title, !task.disabled && callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
37
test/core/api.js
Normal file
37
test/core/api.js
Normal file
@@ -0,0 +1,37 @@
|
||||
var buildExternalHelpers = require("../lib/babel/tools/build-external-helpers");
|
||||
var transform = require("../lib/babel/transformation");
|
||||
var assert = require("assert");
|
||||
var File = require("../lib/babel/transformation/file");
|
||||
|
||||
suite("api", function () {
|
||||
test("{ code: false }", function () {
|
||||
var result = transform("foo('bar');", { code: false });
|
||||
assert.ok(!result.code);
|
||||
});
|
||||
|
||||
test("{ ast: false }", function () {
|
||||
var result = transform("foo('bar');", { ast: false });
|
||||
assert.ok(!result.ast);
|
||||
});
|
||||
|
||||
test("addHelper unknown", function () {
|
||||
var file = new File;
|
||||
assert.throws(function () {
|
||||
file.addHelper("foob");
|
||||
}, /Unknown helper foob/);
|
||||
});
|
||||
|
||||
suite("buildExternalHelpers", function () {
|
||||
test("all", function () {
|
||||
var script = buildExternalHelpers();
|
||||
assert.ok(script.indexOf("classCallCheck") >= -1);
|
||||
assert.ok(script.indexOf("inherits") >= 0);
|
||||
});
|
||||
|
||||
test("whitelist", function () {
|
||||
var script = buildExternalHelpers(["inherits"]);
|
||||
assert.ok(script.indexOf("classCallCheck") === -1);
|
||||
assert.ok(script.indexOf("inherits") >= 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
150
test/core/bin.js
Normal file
150
test/core/bin.js
Normal file
@@ -0,0 +1,150 @@
|
||||
if (process.env.running_under_istanbul) return;
|
||||
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var helper = require("./_helper");
|
||||
var assert = require("assert");
|
||||
var rimraf = require("rimraf");
|
||||
var outputFileSync = require("output-file-sync");
|
||||
var child = require("child_process");
|
||||
var path = require("path");
|
||||
var chai = require("chai");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
var fixtureLoc = __dirname + "/fixtures/bin";
|
||||
var tmpLoc = __dirname + "/tmp";
|
||||
|
||||
var readDir = function (loc) {
|
||||
var files = {};
|
||||
if (fs.existsSync(loc)) {
|
||||
_.each(readdir(loc), function (filename) {
|
||||
var contents = helper.readFile(loc + "/" + filename);
|
||||
files[filename] = contents;
|
||||
});
|
||||
}
|
||||
return files;
|
||||
};
|
||||
|
||||
var saveInFiles = function (files) {
|
||||
_.each(files, function (content, filename) {
|
||||
outputFileSync(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 " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
|
||||
} else {
|
||||
chai.expect(stderr).to.equal(expectStderr, "stderr didn't match");
|
||||
}
|
||||
} else if (stderr) {
|
||||
throw new Error("stderr: " + JSON.stringify(stderr));
|
||||
}
|
||||
|
||||
var expectStdout = opts.stdout.trim();
|
||||
stdout = stdout.trim();
|
||||
stdout = stdout.replace(/\\/g, "/");
|
||||
|
||||
if (opts.stdout) {
|
||||
if (opts.stdoutContains) {
|
||||
assert.ok(_.contains(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
|
||||
} else {
|
||||
chai.expect(stdout).to.equal(expectStdout, "stdout didn't match");
|
||||
}
|
||||
} else if (stdout) {
|
||||
throw new Error("stdout: " + JSON.stringify(stdout));
|
||||
}
|
||||
|
||||
_.each(opts.outFiles, function (expect, filename) {
|
||||
var actual = helper.readFile(filename);
|
||||
chai.expect(actual).to.equal(expect, "out-file " + filename);
|
||||
});
|
||||
};
|
||||
|
||||
var buildTest = function (binName, testName, opts) {
|
||||
var binLoc = path.normalize(__dirname + "/../bin/" + binName);
|
||||
|
||||
return function (callback) {
|
||||
this.timeout(5000);
|
||||
saveInFiles(opts.inFiles);
|
||||
|
||||
var args = [binLoc].concat(opts.args);
|
||||
var spawn = child.spawn(process.execPath, args);
|
||||
|
||||
var stderr = "";
|
||||
var stdout = "";
|
||||
|
||||
spawn.stderr.on("data", function (chunk) {
|
||||
stderr += chunk;
|
||||
});
|
||||
|
||||
spawn.stdout.on("data", function (chunk) {
|
||||
stdout += chunk;
|
||||
});
|
||||
|
||||
spawn.on("close", function () {
|
||||
var err;
|
||||
|
||||
try {
|
||||
assertTest(stdout, stderr, opts);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
err.message = args.join(" ") + ": " + err.message;
|
||||
}
|
||||
|
||||
callback(err);
|
||||
});
|
||||
|
||||
if (opts.stdin) {
|
||||
spawn.stdin.write(opts.stdin);
|
||||
spawn.stdin.end();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
before(function () {
|
||||
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
|
||||
fs.mkdirSync(tmpLoc);
|
||||
process.chdir(tmpLoc);
|
||||
});
|
||||
|
||||
_.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
if (binName[0] === ".") return;
|
||||
|
||||
var suiteLoc = fixtureLoc + "/" + binName;
|
||||
suite("bin/" + binName, function () {
|
||||
_.each(fs.readdirSync(fixtureLoc + "/" + binName), function (testName) {
|
||||
if (testName[0] === ".") return;
|
||||
|
||||
var testLoc = suiteLoc + "/" + testName;
|
||||
|
||||
var opts = {
|
||||
args: []
|
||||
};
|
||||
|
||||
var optionsLoc = testLoc + "/options.json"
|
||||
if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));
|
||||
|
||||
_.each(["stdout", "stdin", "stderr"], function (key) {
|
||||
var loc = testLoc + "/" + key + ".txt";
|
||||
if (fs.existsSync(loc)) {
|
||||
opts[key] = helper.readFile(loc);
|
||||
} else {
|
||||
opts[key] = opts[key] || "";
|
||||
}
|
||||
});
|
||||
|
||||
opts.outFiles = readDir(testLoc + "/out-files");
|
||||
opts.inFiles = readDir(testLoc + "/in-files");
|
||||
|
||||
test(testName, buildTest(binName, testName, opts));
|
||||
});
|
||||
});
|
||||
});
|
||||
19
test/core/browserify.js
Normal file
19
test/core/browserify.js
Normal file
@@ -0,0 +1,19 @@
|
||||
var browserify = require("browserify");
|
||||
var assert = require("assert");
|
||||
var path = require("path");
|
||||
var vm = require("vm");
|
||||
|
||||
suite("browserify", function() {
|
||||
test("babel/register may be used without breaking browserify", function(done) {
|
||||
var bundler = browserify(path.join(__dirname, "fixtures/browserify/register.js"));
|
||||
|
||||
bundler.bundle(function(err, bundle) {
|
||||
if (err) return done(err);
|
||||
assert.ok(bundle.length, "bundle output code");
|
||||
|
||||
// ensure that the code runs without throwing an exception
|
||||
vm.runInNewContext("var global = this;\n" + bundle, {});
|
||||
done();
|
||||
})
|
||||
})
|
||||
});
|
||||
3
test/core/esnext.js
Normal file
3
test/core/esnext.js
Normal file
@@ -0,0 +1,3 @@
|
||||
require("./_transformation-helper")({
|
||||
name: "esnext"
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "nonexistent"]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
(function (global) {
|
||||
var babelHelpers = global.babelHelpers = {};
|
||||
})(typeof global === "undefined" ? self : global);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "nonexistent", "--output-type", "umd"]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports"], factory);
|
||||
} else if (typeof exports === "object") {
|
||||
factory(exports);
|
||||
} else {
|
||||
factory(root.babelHelpers = {});
|
||||
}
|
||||
})(this, function (global) {
|
||||
var babelHelpers = global;
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "nenexistent", "--output-type", "var"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
var babelHelpers = {};
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "slice,has-own"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
(function (global) {
|
||||
var babelHelpers = global.babelHelpers = {};
|
||||
babelHelpers.hasOwn = Object.prototype.hasOwnProperty;
|
||||
babelHelpers.slice = Array.prototype.slice;
|
||||
})(typeof global === "undefined" ? self : global);
|
||||
4
test/core/fixtures/bin/babel-node/--eval/options.json
Normal file
4
test/core/fixtures/bin/babel-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 ]"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
console.log([1, 2, 3].map(x => x * x));
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"args": ["foo", "--extensions", ".bar"],
|
||||
"stdout": "[ 1, 4, 9 ]"
|
||||
}
|
||||
4
test/core/fixtures/bin/babel-node/--print/options.json
Normal file
4
test/core/fixtures/bin/babel-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/core/fixtures/bin/babel-node/directory/options.json
Normal file
3
test/core/fixtures/bin/babel-node/directory/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["foo"]
|
||||
}
|
||||
1
test/core/fixtures/bin/babel-node/directory/stdout.txt
Normal file
1
test/core/fixtures/bin/babel-node/directory/stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
||||
@@ -0,0 +1,2 @@
|
||||
var foo = () => console.log("foo");
|
||||
foo();
|
||||
3
test/core/fixtures/bin/babel-node/filename/options.json
Normal file
3
test/core/fixtures/bin/babel-node/filename/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["bar"]
|
||||
}
|
||||
1
test/core/fixtures/bin/babel-node/filename/stdout.txt
Normal file
1
test/core/fixtures/bin/babel-node/filename/stdout.txt
Normal file
@@ -0,0 +1 @@
|
||||
foo
|
||||
@@ -0,0 +1,2 @@
|
||||
var bar = () => console.log("bar");
|
||||
bar();
|
||||
@@ -0,0 +1,4 @@
|
||||
var foo = () => console.log("foo");
|
||||
foo();
|
||||
|
||||
import "./bar2";
|
||||
3
test/core/fixtures/bin/babel-node/require/options.json
Normal file
3
test/core/fixtures/bin/babel-node/require/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["foo2"]
|
||||
}
|
||||
2
test/core/fixtures/bin/babel-node/require/stdout.txt
Normal file
2
test/core/fixtures/bin/babel-node/require/stdout.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
foo
|
||||
bar
|
||||
3
test/core/fixtures/bin/babel/--blacklist/options.json
Normal file
3
test/core/fixtures/bin/babel/--blacklist/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--blacklist", "es6.arrowFunctions"]
|
||||
}
|
||||
1
test/core/fixtures/bin/babel/--blacklist/stdin.txt
Normal file
1
test/core/fixtures/bin/babel/--blacklist/stdin.txt
Normal file
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
3
test/core/fixtures/bin/babel/--blacklist/stdout.txt
Normal file
3
test/core/fixtures/bin/babel/--blacklist/stdout.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
3
test/core/fixtures/bin/babel/--whitelist/options.json
Normal file
3
test/core/fixtures/bin/babel/--whitelist/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "es6.arrowFunctions"]
|
||||
}
|
||||
2
test/core/fixtures/bin/babel/--whitelist/stdin.txt
Normal file
2
test/core/fixtures/bin/babel/--whitelist/stdin.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
let MULTIPLER = 5;
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
4
test/core/fixtures/bin/babel/--whitelist/stdout.txt
Normal file
4
test/core/fixtures/bin/babel/--whitelist/stdout.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
let MULTIPLER = 5;
|
||||
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": ["src", "--source-maps", "inline", "--out-dir", "lib"]
|
||||
}
|
||||
@@ -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,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);
|
||||
3
test/core/fixtures/bin/babel/dir --out-dir/options.json
Normal file
3
test/core/fixtures/bin/babel/dir --out-dir/options.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib"]
|
||||
}
|
||||
2
test/core/fixtures/bin/babel/dir --out-dir/stdout.txt
Normal file
2
test/core/fixtures/bin/babel/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,7 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLEdBQUcsQ0FBQyxHQUFHLENBQUMsVUFBQSxDQUFDO1NBQUksQ0FBQyxHQUFHLFVBQVU7Q0FBQSxDQUFDLENBQUMiLCJmaWxlIjoic2NyaXB0Mi5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "--out-file", "script2.js"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
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,14 @@
|
||||
"use strict";
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
var Test = function Test() {
|
||||
_classCallCheck(this, Test);
|
||||
};
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLElBQUksWUFBSixJQUFJO3dCQUFKLElBQUk7Ozs7O0FDQVYsR0FBRyxDQUFDLEdBQUcsQ0FBQyxVQUFBLENBQUM7U0FBSSxDQUFDLEdBQUcsVUFBVTtDQUFBLENBQUMsQ0FBQyIsImZpbGUiOiJzY3JpcHQzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgVGVzdCB7XG5cbn0iLCJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ==
|
||||
@@ -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,14 @@
|
||||
"use strict";
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
var Test = function Test() {
|
||||
_classCallCheck(this, Test);
|
||||
};
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=script3.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["script.js","script2.js"],"names":[],"mappings":";;;;IAAM,IAAI,YAAJ,IAAI;wBAAJ,IAAI;;;;;ACAV,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,UAAU;CAAA,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);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["script.js", "script2.js", "--out-file", "script3.js"]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
var Test = function Test() {
|
||||
_classCallCheck(this, Test);
|
||||
};
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"args": ["--filename", "test.js"],
|
||||
"stderrContains": true
|
||||
}
|
||||
1
test/core/fixtures/bin/babel/stdin --filename/stderr.txt
Normal file
1
test/core/fixtures/bin/babel/stdin --filename/stderr.txt
Normal file
@@ -0,0 +1 @@
|
||||
SyntaxError: test.js: Unexpected token (2:10)
|
||||
3
test/core/fixtures/bin/babel/stdin --filename/stdin.txt
Normal file
3
test/core/fixtures/bin/babel/stdin --filename/stdin.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
arr.map(function () {
|
||||
return $]!;
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--source-maps", "--out-file", "test.js"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * x;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=test.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["stdin"],"names":[],"mappings":";;AAAA,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,CAAC;CAAA,CAAC,CAAC","file":"test.js","sourcesContent":["arr.map(x => x * x);"]}
|
||||
@@ -0,0 +1 @@
|
||||
arr.map(x => x * x);
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--out-file", "script.js"]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
1
test/core/fixtures/bin/babel/stdin --out-file/stdin.txt
Normal file
1
test/core/fixtures/bin/babel/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,7 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * x;
|
||||
});
|
||||
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsR0FBRyxDQUFDLEdBQUcsQ0FBQyxVQUFBLENBQUM7U0FBSSxDQUFDLEdBQUcsQ0FBQztDQUFBLENBQUMsQ0FBQyIsImZpbGUiOiJzdGRvdXQiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIHgpOyJdfQ==
|
||||
1
test/core/fixtures/bin/babel/stdin/stdin.txt
Normal file
1
test/core/fixtures/bin/babel/stdin/stdin.txt
Normal file
@@ -0,0 +1 @@
|
||||
arr.map(x => x * MULTIPLIER);
|
||||
5
test/core/fixtures/bin/babel/stdin/stdout.txt
Normal file
5
test/core/fixtures/bin/babel/stdin/stdout.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
arr.map(function (x) {
|
||||
return x * MULTIPLIER;
|
||||
});
|
||||
3
test/core/fixtures/browserify/register.js
Normal file
3
test/core/fixtures/browserify/register.js
Normal file
@@ -0,0 +1,3 @@
|
||||
require("../../../../register")({
|
||||
ignore: false
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
function makeMultiplier() {
|
||||
// `arguments` should refer to `makeMultiplier`'s arguments.
|
||||
return (n) => [].slice.call(arguments).reduce((a, b) => a * b) * n;
|
||||
}
|
||||
|
||||
function toArray() {
|
||||
// Intentionally nest arrow functions to ensure `arguments` is put inside
|
||||
// `toArray`'s scope.
|
||||
return (() => (arguments, (() => [].slice.call(arguments)).call())).call();
|
||||
}
|
||||
|
||||
function returnDotArguments(object) {
|
||||
// Ensure `arguments` is not treated as a reference to the magic value.
|
||||
return (() => object.arguments).call();
|
||||
}
|
||||
|
||||
function returnArgumentsObject() {
|
||||
// Ensure `arguments` is not treated as a reference to the magic value.
|
||||
return (() => ({arguments: 1})).call();
|
||||
}
|
||||
|
||||
function makeArgumentsReturner() {
|
||||
return (() => function() {
|
||||
return [].slice.call(arguments);
|
||||
}).call();
|
||||
}
|
||||
|
||||
// i.e. 2 * 3 * 4 == 24, not 16 (4 * 4)
|
||||
assert.equal(
|
||||
makeMultiplier(2, 3)(4),
|
||||
24,
|
||||
'ensure `arguments` is hoisted out to the first non-arrow scope'
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
toArray(1, 2, 3),
|
||||
[1, 2, 3],
|
||||
'ensure `arguments` is hoisted out to the first non-arrow scope'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
returnDotArguments({arguments: 1}),
|
||||
1,
|
||||
'member accesses with `arguments` property should not be replaced'
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
returnArgumentsObject(),
|
||||
{arguments: 1},
|
||||
'object property keys named `arguments` should not be replaced'
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
makeArgumentsReturner()(1, 2, 3),
|
||||
[1, 2, 3],
|
||||
'arguments should not be hoisted from inside non-arrow functions'
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
var empty = () => {};
|
||||
assert.equal(empty(), undefined);
|
||||
@@ -0,0 +1,12 @@
|
||||
var obj = {
|
||||
method: function() {
|
||||
return () => (this, () => this);
|
||||
},
|
||||
|
||||
method2: function() {
|
||||
return () => () => this;
|
||||
}
|
||||
};
|
||||
|
||||
assert.strictEqual(obj.method()()(), obj);
|
||||
assert.strictEqual(obj.method2()()(), obj);
|
||||
@@ -0,0 +1,2 @@
|
||||
var square = x => x * x;
|
||||
assert.equal(square(4), 16);
|
||||
@@ -0,0 +1,2 @@
|
||||
var keyMaker = val => ({ key: val });
|
||||
assert.deepEqual(keyMaker(9), { key: 9 });
|
||||
@@ -0,0 +1,7 @@
|
||||
var obj = {
|
||||
method: function() {
|
||||
return () => this;
|
||||
}
|
||||
};
|
||||
|
||||
assert.strictEqual(obj.method()(), obj);
|
||||
@@ -0,0 +1,2 @@
|
||||
var odds = [0, 2, 4].map(v => v + 1);
|
||||
assert.deepEqual(odds, [1, 3, 5]);
|
||||
@@ -0,0 +1,2 @@
|
||||
var identity = x => x;
|
||||
assert.equal(identity(1), 1);
|
||||
29
test/core/fixtures/esnext/es6-classes/anonymous-class.js
Normal file
29
test/core/fixtures/esnext/es6-classes/anonymous-class.js
Normal file
@@ -0,0 +1,29 @@
|
||||
var Animal = class {
|
||||
sayHi() {
|
||||
return 'Hi, I am a '+this.type()+'.';
|
||||
}
|
||||
|
||||
static getName() {
|
||||
return 'Animal';
|
||||
}
|
||||
};
|
||||
|
||||
var Dog = class extends Animal {
|
||||
type() { return 'dog'; }
|
||||
|
||||
sayHi() {
|
||||
return super.sayHi() + ' WOOF!';
|
||||
}
|
||||
|
||||
static getName() {
|
||||
return super.getName() + '/Dog';
|
||||
}
|
||||
};
|
||||
|
||||
assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!');
|
||||
assert.equal(Dog.getName(), 'Animal/Dog');
|
||||
|
||||
var count = 0;
|
||||
var Cat = class extends (function(){ count++; return Animal; })() {};
|
||||
|
||||
assert.equal(count, 1);
|
||||
21
test/core/fixtures/esnext/es6-classes/call-super-function.js
Normal file
21
test/core/fixtures/esnext/es6-classes/call-super-function.js
Normal file
@@ -0,0 +1,21 @@
|
||||
class Animal {
|
||||
sayHi() {
|
||||
return 'I am an animal.'
|
||||
}
|
||||
|
||||
sayOther() {
|
||||
return 'WAT?!';
|
||||
}
|
||||
}
|
||||
|
||||
class Horse extends Animal {
|
||||
sayHi() {
|
||||
return super.sayOther();
|
||||
}
|
||||
|
||||
sayOther() {
|
||||
return 'I see dead objects.';
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new Horse().sayHi(), 'WAT?!');
|
||||
@@ -0,0 +1,9 @@
|
||||
var Person = (class Person {});
|
||||
assert.equal(typeof Person, 'function');
|
||||
|
||||
assert.equal(
|
||||
(function(){ return (class Person {}); })().name,
|
||||
'Person'
|
||||
);
|
||||
|
||||
assert.equal(typeof (class {}), 'function');
|
||||
15
test/core/fixtures/esnext/es6-classes/class-extend.js
Normal file
15
test/core/fixtures/esnext/es6-classes/class-extend.js
Normal file
@@ -0,0 +1,15 @@
|
||||
class Animal {
|
||||
sayHi() {
|
||||
return 'Hi, I am a '+this.type()+'.';
|
||||
}
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
type() { return 'dog'; }
|
||||
|
||||
sayHi() {
|
||||
return super.sayHi() + ' WOOF!';
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!');
|
||||
@@ -0,0 +1,14 @@
|
||||
class Multiplier {
|
||||
constructor(n=1) {
|
||||
this.n = n;
|
||||
}
|
||||
|
||||
multiply(n=1) {
|
||||
return n * this.n;
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new Multiplier().n, 1);
|
||||
assert.equal(new Multiplier(6).n, 6);
|
||||
assert.equal(new Multiplier().multiply(), 1);
|
||||
assert.equal(new Multiplier(2).multiply(3), 6);
|
||||
@@ -0,0 +1,10 @@
|
||||
class Person {
|
||||
getName() {
|
||||
return this.firstName + ' ' + this.lastName;
|
||||
}
|
||||
}
|
||||
|
||||
var me = new Person();
|
||||
me.firstName = 'Brian';
|
||||
me.lastName = 'Donovan';
|
||||
assert.equal(me.getName(), 'Brian Donovan');
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
}
|
||||
|
||||
assert.equal(new Foo().constructor, Foo, 'Foo instances should have Foo as constructor');
|
||||
assert.ok(new Foo() instanceof Foo, 'Foo instances should be `instanceof` Foo');
|
||||
20
test/core/fixtures/esnext/es6-classes/enumerable.js
Normal file
20
test/core/fixtures/esnext/es6-classes/enumerable.js
Normal file
@@ -0,0 +1,20 @@
|
||||
class Point {
|
||||
constructor(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return '(' + this.x + ', ' + this.y + ')';
|
||||
}
|
||||
}
|
||||
|
||||
var point = new Point(1, 2);
|
||||
var keys = [];
|
||||
|
||||
for (var key in point) {
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
assert.equal(point.toString(), '(1, 2)');
|
||||
assert.deepEqual(keys.sort(), ['x', 'y']);
|
||||
@@ -0,0 +1,15 @@
|
||||
class Point {
|
||||
constructor(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
class ZeroPoint extends Point {
|
||||
constructor() {
|
||||
super(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(new ZeroPoint().x, 0);
|
||||
assert.equal(new ZeroPoint().y, 0);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user