From e3174d5a39ff8b5e92c00fe3fa500897b5c7474e Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 6 Jan 2015 12:08:40 +1100 Subject: [PATCH] add esvalid validation to transformation tests --- package.json | 1 + test/_transformation-helper.js | 16 ++++++++++++++++ .../optional-async-to-generator/options.json | 1 + .../optional-bluebird-coroutines/options.json | 3 ++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e1a07c85ef..0cabfd6646 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "core-js": "^0.4.0", "estraverse": "1.8.0", "esutils": "1.1.6", + "esvalid": "^1.1.0", "fs-readdir-recursive": "0.1.0", "jshint": "^2.5.10", "lodash": "2.4.1", diff --git a/test/_transformation-helper.js b/test/_transformation-helper.js index 7a1bd97fdf..db754ac9ec 100644 --- a/test/_transformation-helper.js +++ b/test/_transformation-helper.js @@ -1,6 +1,7 @@ var genHelpers = require("./_generator-helpers"); var transform = require("../lib/6to5/transformation/transform"); var sourceMap = require("source-map"); +var esvalid = require("esvalid"); var Module = require("module"); var helper = require("./_helper"); var assert = require("assert"); @@ -48,8 +49,22 @@ var run = function (task, done) { var execCode = exec.code; var result; + var checkAst = function (result) { + if (opts.noCheckAst) return; + + var errors = esvalid.errors(result.ast.program); + if (errors.length) { + var msg = []; + _.each(errors, function (err) { + msg.push(err.message + " - " + JSON.stringify(err.node)); + }); + throw new Error(msg.join(". ")); + } + }; + if (execCode) { result = transform(execCode, getOpts(exec)); + checkAst(result); execCode = result.code; try { @@ -76,6 +91,7 @@ var run = function (task, done) { var expectCode = expect.code; if (!execCode || actualCode) { result = transform(actualCode, getOpts(actual)); + checkAst(result); actualCode = result.code; chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc); diff --git a/test/fixtures/transformation/optional-async-to-generator/options.json b/test/fixtures/transformation/optional-async-to-generator/options.json index d8694ba41c..9dbdefeeb0 100644 --- a/test/fixtures/transformation/optional-async-to-generator/options.json +++ b/test/fixtures/transformation/optional-async-to-generator/options.json @@ -1,3 +1,4 @@ { + "noCheckAst": true, "optional": ["asyncToGenerator"] } diff --git a/test/fixtures/transformation/optional-bluebird-coroutines/options.json b/test/fixtures/transformation/optional-bluebird-coroutines/options.json index 264ef8fbf1..beb0408342 100644 --- a/test/fixtures/transformation/optional-bluebird-coroutines/options.json +++ b/test/fixtures/transformation/optional-bluebird-coroutines/options.json @@ -1,3 +1,4 @@ { - "optional": ["bluebirdCoroutines"] + "optional": ["bluebirdCoroutines"], + "noCheckAst": true }