From e20d9dd07338a90cdf30210a919999e44dcd399f Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 4 Feb 2015 14:59:12 -0800 Subject: [PATCH] feature(build): add nodejs-based unit test for dart transpiler. This adds a unit test to the transpiler. Existing tests are themselves transpiled to ES5, which makes it impossible to do some kinds of assertions. For example, this will be useful to repro https://github.com/angular/angular/issues/509. In this change, the actual issue isn't fixed. It only adds the reproduction. It uses the jasmine test runner, since it's already used by the docs test. That uses version 1 of Jasmine, which isn't ideal, but I want to be consistent for now. I discussed with Tobias the possibility of switching to Mocha for these nodejs-based tests, and we might do that sometime later. --- gulpfile.js | 5 ++++ package.json | 14 +++++----- tools/transpiler/unittest/transpilertests.js | 27 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 tools/transpiler/unittest/transpilertests.js diff --git a/gulpfile.js b/gulpfile.js index da2fd6d81a..00a4e25288 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -434,8 +434,13 @@ gulp.task('test.js/ci', function (done) { gulp.task('test.dart/ci', function (done) { karma.start({configFile: __dirname + '/karma-dart.conf.js', singleRun: true, reporters: ['dots'], browsers: getBrowsersFromCLI()}, done); }); +gulp.task('test.transpiler.unittest', function (done) { + return gulp.src('tools/transpiler/unittest/**/*.js') + .pipe(jasmine()) +}); gulp.task('ci', function(done) { runSequence( + 'test.transpiler.unittest', 'test.js/ci', 'test.dart/ci' ); diff --git a/package.json b/package.json index 5f8b7f8c22..9805647c0a 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "node-uuid": "1.4.x" }, "devDependencies": { + "angular": "1.3.5", "bower": "^1.3.12", "canonical-path": "0.0.2", "del": "~1", @@ -43,15 +44,14 @@ "karma-cli": "^0.0.4", "karma-dart": "^0.2.8", "karma-jasmine": "^0.2.2", - "merge": "^1.2.0", - "angular": "1.3.5", - "minimatch": "^2.0.1", "lodash": "^2.4.1", - "sprintf-js": "1.0.*", - "q": "^1.0.1", + "merge": "^1.2.0", + "minimatch": "^2.0.1", + "minimist": "1.1.x", "protractor": "1.6.x", + "q": "^1.0.1", "run-sequence": "^0.3.6", - "through2": "^0.6.1", - "minimist": "1.1.x" + "sprintf-js": "1.0.*", + "through2": "^0.6.1" } } diff --git a/tools/transpiler/unittest/transpilertests.js b/tools/transpiler/unittest/transpilertests.js new file mode 100644 index 0000000000..4316dcc204 --- /dev/null +++ b/tools/transpiler/unittest/transpilertests.js @@ -0,0 +1,27 @@ +var compiler = require('../index'); + +// fixme: copied from top of gulpfile +var OPTIONS = { + sourceMaps: true, + annotations: true, // parse annotations + types: true, // parse types + script: false, // parse as a module + memberVariables: true, // parse class fields + outputLanguage: 'dart' +}; + +describe('transpile to dart', function(){ + + // https://github.com/angular/angular/issues/509 + it('should not interpolate inside old quotes', function(){ + var result = compiler.compile(OPTIONS, "test.js", + "var a = 1;" + + "var s1 = '${a}';" + + "var s2 = `${a}`;"); + expect(result.js).toBe("library test;\n" + + "var a = 1;\n" + + // FIXME: this should escape the interpolation with backslash to fix the issue + "var s1 = '${a}';\n" + + "var s2 = '''${a}''';\n"); + }) +});