Skip to content

Commit e20d9dd

Browse files
committed
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 angular#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.
1 parent 3395624 commit e20d9dd

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

gulpfile.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,13 @@ gulp.task('test.js/ci', function (done) {
434434
gulp.task('test.dart/ci', function (done) {
435435
karma.start({configFile: __dirname + '/karma-dart.conf.js', singleRun: true, reporters: ['dots'], browsers: getBrowsersFromCLI()}, done);
436436
});
437+
gulp.task('test.transpiler.unittest', function (done) {
438+
return gulp.src('tools/transpiler/unittest/**/*.js')
439+
.pipe(jasmine())
440+
});
437441
gulp.task('ci', function(done) {
438442
runSequence(
443+
'test.transpiler.unittest',
439444
'test.js/ci',
440445
'test.dart/ci'
441446
);

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"node-uuid": "1.4.x"
2323
},
2424
"devDependencies": {
25+
"angular": "1.3.5",
2526
"bower": "^1.3.12",
2627
"canonical-path": "0.0.2",
2728
"del": "~1",
@@ -43,15 +44,14 @@
4344
"karma-cli": "^0.0.4",
4445
"karma-dart": "^0.2.8",
4546
"karma-jasmine": "^0.2.2",
47+
"lodash": "^2.4.1",
4648
"merge": "^1.2.0",
47-
"angular": "1.3.5",
4849
"minimatch": "^2.0.1",
49-
"lodash": "^2.4.1",
50-
"sprintf-js": "1.0.*",
51-
"q": "^1.0.1",
50+
"minimist": "1.1.x",
5251
"protractor": "1.6.x",
52+
"q": "^1.0.1",
5353
"run-sequence": "^0.3.6",
54-
"through2": "^0.6.1",
55-
"minimist": "1.1.x"
54+
"sprintf-js": "1.0.*",
55+
"through2": "^0.6.1"
5656
}
5757
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var compiler = require('../index');
2+
3+
// fixme: copied from top of gulpfile
4+
var OPTIONS = {
5+
sourceMaps: true,
6+
annotations: true, // parse annotations
7+
types: true, // parse types
8+
script: false, // parse as a module
9+
memberVariables: true, // parse class fields
10+
outputLanguage: 'dart'
11+
};
12+
13+
describe('transpile to dart', function(){
14+
15+
// https://github.com/angular/angular/issues/509
16+
it('should not interpolate inside old quotes', function(){
17+
var result = compiler.compile(OPTIONS, "test.js",
18+
"var a = 1;" +
19+
"var s1 = '${a}';" +
20+
"var s2 = `${a}`;");
21+
expect(result.js).toBe("library test;\n" +
22+
"var a = 1;\n" +
23+
// FIXME: this should escape the interpolation with backslash to fix the issue
24+
"var s1 = '${a}';\n" +
25+
"var s2 = '''${a}''';\n");
26+
})
27+
});

0 commit comments

Comments
 (0)