diff --git a/test/classes.js b/test/classes.js deleted file mode 100644 index 3dc175bc0d..0000000000 --- a/test/classes.js +++ /dev/null @@ -1,51 +0,0 @@ -var transform = require("../lib/6to5/transform"); -var assert = require("assert"); - -suite("classes", function () { - test("no calling super properties", function () { - assert.throws(function () { - transform.test([ - "class Test extends Foo {", - " constructor() {", - " super.test.whatever();", - " }", - "}" - ]); - }, /cannot access super properties/); - }); - - test("no accessing super properties", function () { - assert.throws(function () { - transform.test([ - "class Test extends Foo {", - " constructor() {", - " super.test.whatever;", - " }", - "}" - ]); - }, /cannot access super properties/); - }); - - test("accessing super without having one", function () { - assert.throws(function () { - transform.test([ - "class Test {", - " constructor() {", - " super();", - " }", - "}" - ]); - }, /cannot access super as this class has none/); - }); - - test("defining constructor as a mutator", function () { - assert.throws(function () { - transform.test([ - "class Test {", - " get constructor() {", - " }", - "}" - ]); - }, /unknown kind for constructor method/); - }); -}); diff --git a/test/errors.js b/test/errors.js deleted file mode 100644 index e4ccd0ef8d..0000000000 --- a/test/errors.js +++ /dev/null @@ -1,14 +0,0 @@ -var transform = require("../lib/6to5/transform"); -var assert = require("assert"); - -suite("errors", function () { - test("syntax", function () { - assert.throws(function () { - transform.test([ - "arr.map(function () {", - " return $@!@#;", - "});" - ]); - }, /Error: test: Line 2: Unexpected token ILLEGAL/); - }); -}); diff --git a/test/fixtures/block-binding/ignore-root/expected.js b/test/fixtures/block-binding/ignore-root/expected.js deleted file mode 100644 index f17c6fc26d..0000000000 --- a/test/fixtures/block-binding/ignore-root/expected.js +++ /dev/null @@ -1,5 +0,0 @@ -var arr = [ - 1, - 2, - 3 -]; diff --git a/test/fixtures/block-binding/ignore-root/actual.js b/test/fixtures/block-binding/program/actual.js similarity index 100% rename from test/fixtures/block-binding/ignore-root/actual.js rename to test/fixtures/block-binding/program/actual.js diff --git a/test/fixtures/block-binding/program/expected.js b/test/fixtures/block-binding/program/expected.js new file mode 100644 index 0000000000..593f2c31b6 --- /dev/null +++ b/test/fixtures/block-binding/program/expected.js @@ -0,0 +1,7 @@ +(function () { + var arr = [ + 1, + 2, + 3 + ]; +})(); diff --git a/test/fixtures/classes/accessing-super-without-having-one/actual.js b/test/fixtures/classes/accessing-super-without-having-one/actual.js new file mode 100644 index 0000000000..023c8c5d75 --- /dev/null +++ b/test/fixtures/classes/accessing-super-without-having-one/actual.js @@ -0,0 +1,5 @@ +class Test { + constructor() { + super(); + } +} diff --git a/test/fixtures/classes/accessing-super-without-having-one/options.json b/test/fixtures/classes/accessing-super-without-having-one/options.json new file mode 100644 index 0000000000..bef99851e8 --- /dev/null +++ b/test/fixtures/classes/accessing-super-without-having-one/options.json @@ -0,0 +1,3 @@ +{ + "throws": "cannot access super as this class has none" +} diff --git a/test/fixtures/classes/defining-constructor-as-a-mutator/actual.js b/test/fixtures/classes/defining-constructor-as-a-mutator/actual.js new file mode 100644 index 0000000000..4de089b72a --- /dev/null +++ b/test/fixtures/classes/defining-constructor-as-a-mutator/actual.js @@ -0,0 +1,4 @@ +class Test { + get constructor() { + } +} diff --git a/test/fixtures/classes/defining-constructor-as-a-mutator/options.json b/test/fixtures/classes/defining-constructor-as-a-mutator/options.json new file mode 100644 index 0000000000..2761b2ba72 --- /dev/null +++ b/test/fixtures/classes/defining-constructor-as-a-mutator/options.json @@ -0,0 +1,3 @@ +{ + "throws": "unknown kind for constructor method" +} diff --git a/test/fixtures/classes/no-accessing-super-properties/actual.js b/test/fixtures/classes/no-accessing-super-properties/actual.js new file mode 100644 index 0000000000..51195a3c6f --- /dev/null +++ b/test/fixtures/classes/no-accessing-super-properties/actual.js @@ -0,0 +1,5 @@ +class Test extends Foo { + constructor() { + super.test.whatever; + } +} diff --git a/test/fixtures/classes/no-accessing-super-properties/options.json b/test/fixtures/classes/no-accessing-super-properties/options.json new file mode 100644 index 0000000000..62d82f26d2 --- /dev/null +++ b/test/fixtures/classes/no-accessing-super-properties/options.json @@ -0,0 +1,3 @@ +{ + "throws": "cannot access super properties" +} diff --git a/test/fixtures/classes/no-calling-super-properties/actual.js b/test/fixtures/classes/no-calling-super-properties/actual.js new file mode 100644 index 0000000000..7e8774ef63 --- /dev/null +++ b/test/fixtures/classes/no-calling-super-properties/actual.js @@ -0,0 +1,5 @@ +class Test extends Foo { + constructor() { + super.test.whatever(); + } +} diff --git a/test/fixtures/classes/no-calling-super-properties/options.json b/test/fixtures/classes/no-calling-super-properties/options.json new file mode 100644 index 0000000000..62d82f26d2 --- /dev/null +++ b/test/fixtures/classes/no-calling-super-properties/options.json @@ -0,0 +1,3 @@ +{ + "throws": "cannot access super properties" +} diff --git a/test/fixtures/computed-property-names/method/actual.js b/test/fixtures/computed-property-names/method/actual.js new file mode 100644 index 0000000000..c8997817dc --- /dev/null +++ b/test/fixtures/computed-property-names/method/actual.js @@ -0,0 +1,5 @@ +var obj = { + [foobar]() { + return "foobar" + } +}; diff --git a/test/fixtures/computed-property-names/method/expected.js b/test/fixtures/computed-property-names/method/expected.js new file mode 100644 index 0000000000..a2d1eee068 --- /dev/null +++ b/test/fixtures/computed-property-names/method/expected.js @@ -0,0 +1,6 @@ +var obj = function (obj) { + obj[foobar] = function () { + return 'foobar'; + }; + return obj; +}({}); diff --git a/test/fixtures/constants/block-statement/actual.js b/test/fixtures/constants/block-statement/actual.js new file mode 100644 index 0000000000..e0b2b04ea0 --- /dev/null +++ b/test/fixtures/constants/block-statement/actual.js @@ -0,0 +1,4 @@ +for (let i in arr) { + const MULTIPLIER = 5; + console.log(arr[i] * MULTIPLIER); +} diff --git a/test/fixtures/constants/block-statement/expected.js b/test/fixtures/constants/block-statement/expected.js new file mode 100644 index 0000000000..31d62981de --- /dev/null +++ b/test/fixtures/constants/block-statement/expected.js @@ -0,0 +1,8 @@ +(function () { + for (var i in arr) { + (function () { + var MULTIPLIER = 5; + console.log(arr[i] * MULTIPLIER); + }()); + } +}()); diff --git a/test/fixtures/constants/no-assignment/actual.js b/test/fixtures/constants/no-assignment/actual.js new file mode 100644 index 0000000000..296ce9b558 --- /dev/null +++ b/test/fixtures/constants/no-assignment/actual.js @@ -0,0 +1,3 @@ +const MULTIPLIER = 5; + +MULTIPLIER = "overwrite"; diff --git a/test/fixtures/constants/no-assignment/options.json b/test/fixtures/constants/no-assignment/options.json new file mode 100644 index 0000000000..9b96d41ac9 --- /dev/null +++ b/test/fixtures/constants/no-assignment/options.json @@ -0,0 +1,3 @@ +{ + "throws": "MULTIPLIER is read-only" +} diff --git a/test/fixtures/constants/no-declaration/actual.js b/test/fixtures/constants/no-declaration/actual.js new file mode 100644 index 0000000000..ccb0ca0d05 --- /dev/null +++ b/test/fixtures/constants/no-declaration/actual.js @@ -0,0 +1,3 @@ +const MULTIPLIER = 5; + +var MULTIPLIER = "overwrite"; diff --git a/test/fixtures/constants/no-declaration/options.json b/test/fixtures/constants/no-declaration/options.json new file mode 100644 index 0000000000..9b96d41ac9 --- /dev/null +++ b/test/fixtures/constants/no-declaration/options.json @@ -0,0 +1,3 @@ +{ + "throws": "MULTIPLIER is read-only" +} diff --git a/test/fixtures/constants/program/actual.js b/test/fixtures/constants/program/actual.js new file mode 100644 index 0000000000..2570895af8 --- /dev/null +++ b/test/fixtures/constants/program/actual.js @@ -0,0 +1,5 @@ +const MULTIPLIER = 5; + +for (var i in arr) { + console.log(arr[i] * MULTIPLIER); +} diff --git a/test/fixtures/constants/program/expected.js b/test/fixtures/constants/program/expected.js new file mode 100644 index 0000000000..ab1e06254b --- /dev/null +++ b/test/fixtures/constants/program/expected.js @@ -0,0 +1,6 @@ +(function () { + var MULTIPLIER = 5; + for (var i in arr) { + console.log(arr[i] * MULTIPLIER); + } +}()); diff --git a/test/fixtures/errors/syntax/actual.js b/test/fixtures/errors/syntax/actual.js new file mode 100644 index 0000000000..36651f967c --- /dev/null +++ b/test/fixtures/errors/syntax/actual.js @@ -0,0 +1,3 @@ +arr.map(function () { + return $@!@#; +}); diff --git a/test/fixtures/errors/syntax/options.json b/test/fixtures/errors/syntax/options.json new file mode 100644 index 0000000000..3f3c5af1e7 --- /dev/null +++ b/test/fixtures/errors/syntax/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Line 2: Unexpected token ILLEGAL" +} diff --git a/test/fixtures/spread/method-call-array-literal/actual.js b/test/fixtures/spread/method-call-array-literal/actual.js new file mode 100644 index 0000000000..2d1a0bb716 --- /dev/null +++ b/test/fixtures/spread/method-call-array-literal/actual.js @@ -0,0 +1 @@ +f(...[1, 2, 3]); diff --git a/test/fixtures/spread/method-call-array-literal/expected.js b/test/fixtures/spread/method-call-array-literal/expected.js new file mode 100644 index 0000000000..987a197900 --- /dev/null +++ b/test/fixtures/spread/method-call-array-literal/expected.js @@ -0,0 +1 @@ +f.apply(null, [1, 2, 3]); diff --git a/test/index.js b/test/index.js index 9edc04584e..c0f17cb3b3 100644 --- a/test/index.js +++ b/test/index.js @@ -7,6 +7,14 @@ var humanise = function (val) { return val.replace(/-/g, " "); }; +var readFile = function (filename) { + if (fs.existsSync(filename)) { + return fs.readFileSync(filename); + } else { + return ""; + } +}; + var fixturesDir = __dirname + "/fixtures"; _.each(fs.readdirSync(fixturesDir), function (suiteName) { @@ -24,14 +32,26 @@ _.each(fs.readdirSync(fixturesDir), function (suiteName) { test(humanise(taskName), function () { var actualLoc = taskDir + "/actual.js"; - var actual = fs.readFileSync(actualLoc, "utf8"); - var expect = fs.readFileSync(taskDir + "/expected.js", "utf8"); + var actual = readFile(actualLoc); + var expect = readFile(taskDir + "/expected.js"); var taskOptsLoc = taskDir + "/options.json"; var taskOpts = _.merge({ filename: actualLoc }, _.cloneDeep(suiteOpts)); if (fs.existsSync(taskOptsLoc)) _.merge(taskOpts, require(taskOptsLoc)); - transform.test(actual, expect, taskOpts); + var test = function () { + transform.test(actual, expect, taskOpts); + }; + + var throwMsg = taskOpts.throws; + if (throwMsg) { + // internal api doesn't have this option but it's best not to pollute + // the options object with useless options + delete taskOpts.throws; + assert.throws(test, new RegExp(throwMsg)); + } else { + test(); + } }); }); });