Browse files

Added nodeunit tests

  • Loading branch information...
1 parent efac776 commit 0d323b36ed92d76e0feb2f8465df0d457118f17c @basarat basarat committed Feb 22, 2014
View
2 .gitignore
@@ -19,3 +19,5 @@ test/definitelytypedtest/reference.ts
!.gitignore
!tasks/ts.js
!tasks/ts-internal.js
+!test/expected/**/*.js
+!test/expected/**/*.map
View
13 Gruntfile.js
@@ -8,6 +8,8 @@ module.exports = function (grunt) {
'test/**/*.js',
'test/**/*.js.map',
'test/**/*.html.ts',
+ '!test/test.js',
+ '!test/expected/**/*'
]
},
jshint: {
@@ -38,6 +40,9 @@ module.exports = function (grunt) {
src: ['tasks/ts.ts']
}
},
+ nodeunit:{
+ tests:['test/test.js']
+ },
ts: {
options: { // override the main options, See : http://gruntjs.com/configuring-tasks#options
target: 'es3', // 'es3' (default) | 'es5'
@@ -48,7 +53,7 @@ module.exports = function (grunt) {
comments: false, // leave comments in compiled js code (true | false (default))
verbose: true // print the tsc command (true | false (default))
},
- dev: { // a particular target
+ work: { // a particular target
src: ['test/work/**/*.ts'], // The source typescript files, See : http://gruntjs.com/configuring-tasks#files
out: 'test/work/out.js', // If specified, generate an out.js file which is the merged js file
options: { // override the main options, See : http://gruntjs.com/configuring-tasks#options
@@ -198,12 +203,14 @@ module.exports = function (grunt) {
//grunt.loadNpmTasks('grunt-ts')
grunt.loadNpmTasks('grunt-contrib-clean');
- grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-tslint');
+ grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.registerTask('prep', ['clean', 'jshint:support']);
grunt.registerTask('build', ['prep', 'ts-internal:build', 'tslint:source']);
- grunt.registerTask('test', ['test_all']);
+ grunt.registerTask('test', ['test_all','nodeunit']);
+ grunt.registerTask('prepush', ['build','test']);
grunt.registerTask('default', ['test']);
grunt.registerTask('run', ['ts:amdloadersrc']);
View
1 package.json
@@ -53,6 +53,7 @@
"grunt-tslint": "~0.4.0",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-jshint": "~0.8.0",
+ "grunt-contrib-nodeunit": "~0.2.2",
"tslint-path-formatter": "~0.1.1",
"source-map-support": "~0.2.5",
"jshint-path-reporter": "~0.1.3"
View
28 test/expected/abtest/out.js
@@ -0,0 +1,28 @@
+var C = (function () {
+ function C() {
+ }
+ return C;
+})();
+var __extends = this.__extends || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+/// <reference path="reference.ts"/>
+var B = (function (_super) {
+ __extends(B, _super);
+ function B() {
+ _super.apply(this, arguments);
+ }
+ return B;
+})(C);
+/// <reference path="reference.ts"/>
+var A = (function (_super) {
+ __extends(A, _super);
+ function A() {
+ _super.apply(this, arguments);
+ }
+ return A;
+})(B);
+//# sourceMappingURL=out.js.map
View
1 test/expected/abtest/out.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"out.js","sourceRoot":"","sources":["c.ts","b.ts","a.ts","reference.ts"],"names":["C","C.constructor","B","B.constructor","A","A.constructor"],"mappings":"AAAA;IAAAA;;AAAWA,IAADA,SAACA;AAADA,CAACA,IAAA;;;;;;;ACAX,oCAAoC;AACpC;;IAAAE;;;AAAoBA,IAADA,SAACA;AAADA,CAACA,EAAJ,CAAC,EAAG;ACDpB,oCAAoC;AACpC;;IAAAE;;;AAAqBA,IAADA,SAACA;AAADA,CAACA,EAAL,CAAC,EAAI"}
View
7 test/expected/abtest/reference.ts
@@ -0,0 +1,7 @@
+/// <reference path="c.ts" />
+
+//grunt-start
+/// <reference path="b.ts" />
+//grunt-end
+
+/// <reference path="a.ts" />
View
15 test/expected/simple/js/zoo.d.ts
@@ -0,0 +1,15 @@
+declare class Animal {
+ public name: string;
+ constructor(name: string);
+ public move(meters: number): void;
+}
+declare class Snake extends Animal {
+ constructor(name: string);
+ public move(): void;
+}
+declare class Horse extends Animal {
+ constructor(name: string);
+ public move(): void;
+}
+declare var sam: Snake;
+declare var tom: Animal;
View
46 test/expected/simple/js/zoo.js
@@ -0,0 +1,46 @@
+var __extends = this.__extends || function (d, b) {
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
+ function __() { this.constructor = d; }
+ __.prototype = b.prototype;
+ d.prototype = new __();
+};
+var Animal = (function () {
+ function Animal(name) {
+ this.name = name;
+ }
+ Animal.prototype.move = function (meters) {
+ alert(this.name + " moved " + meters + "m.");
+ };
+ return Animal;
+})();
+
+var Snake = (function (_super) {
+ __extends(Snake, _super);
+ function Snake(name) {
+ _super.call(this, name);
+ }
+ Snake.prototype.move = function () {
+ alert("Slithering...");
+ _super.prototype.move.call(this, 5);
+ };
+ return Snake;
+})(Animal);
+
+var Horse = (function (_super) {
+ __extends(Horse, _super);
+ function Horse(name) {
+ _super.call(this, name);
+ }
+ Horse.prototype.move = function () {
+ alert("Galloping...");
+ _super.prototype.move.call(this, 45);
+ };
+ return Horse;
+})(Animal);
+
+var sam = new Snake("Sammy the Python");
+var tom = new Horse("Tommy the Palomino");
+
+sam.move();
+tom.move(34);
+//# sourceMappingURL=zoo.js.map
View
22 test/test.js
@@ -0,0 +1,22 @@
+var grunt = require('grunt');
+var fs = require('fs');
+var path = require('path');
+
+function testFile(test, path){
+ var actual = grunt.file.read('test/' + path);
+ var expected = grunt.file.read('test/expected/' + path);
+ test.equal(expected, actual);
+}
+
+module.exports.typescript = {
+ simple: function(test) {
+ testFile(test,'simple/js/zoo.js');
+ testFile(test,'simple/js/zoo.d.ts');
+ test.done();
+ },
+ abtest: function(test){
+ testFile(test,'abtest/reference.ts');
+ testFile(test,'abtest/out.js');
+ test.done();
+ }
+}

0 comments on commit 0d323b3

Please sign in to comment.