From 3e50abbbd7e87fb02e4c5d42ee9e71e60a10f2fc Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Fri, 18 Dec 2015 14:29:54 +0100 Subject: [PATCH 1/6] Add karma-typescript-preprocessor dependency --- frontend/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/package.json b/frontend/package.json index 0114ed2b1f..fdf9088668 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -31,6 +31,7 @@ "karma-mocha": "~0.1.3", "karma-ng-html2js-preprocessor": "^0.1.2", "karma-phantomjs-launcher": "~0.1.4", + "karma-typescript-preprocessor": "0.0.21", "karma-webpack": "^1.5.0", "mocha": "~1.18.2", "mocha-jenkins-reporter": "^0.1.2", From e3aa0afe73327af112b8a7211542ab24b24fc7c8 Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Fri, 18 Dec 2015 14:46:21 +0100 Subject: [PATCH 2/6] Use TypeScript in routing test --- .../app/components/config/{routing.test.js => routing.test.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontend/app/components/config/{routing.test.js => routing.test.ts} (100%) diff --git a/frontend/app/components/config/routing.test.js b/frontend/app/components/config/routing.test.ts similarity index 100% rename from frontend/app/components/config/routing.test.js rename to frontend/app/components/config/routing.test.ts From c55e6ad3683ec9298ed2ee2cd330d47914947f2a Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Fri, 18 Dec 2015 14:49:42 +0100 Subject: [PATCH 3/6] Add Sinon type definitions --- frontend/tsd.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/tsd.json b/frontend/tsd.json index 97939e7ce6..5d7b5e8471 100644 --- a/frontend/tsd.json +++ b/frontend/tsd.json @@ -13,6 +13,9 @@ }, "angular-ui-router/angular-ui-router.d.ts": { "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" + }, + "sinon/sinon.d.ts": { + "commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe" } } } From 0c98734617225b902328898cb70bf44910f3e8a9 Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Fri, 18 Dec 2015 14:56:16 +0100 Subject: [PATCH 4/6] Add karma-typescript-preprocessor configuration --- frontend/karma.conf.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/frontend/karma.conf.js b/frontend/karma.conf.js index 8784e9d370..0afdabee33 100644 --- a/frontend/karma.conf.js +++ b/frontend/karma.conf.js @@ -73,7 +73,8 @@ module.exports = function(config) { 'tests/unit/tests/**/*test.js', 'tests/unit/tests/legacy-tests.js', - 'app/components/**/*.test.js' + 'app/components/**/*.test.js', + 'app/components/**/*.test.ts' ], @@ -88,11 +89,29 @@ module.exports = function(config) { preprocessors: { '/templates/**/*.html': ['ng-html2js'], '../app/assets/javascripts/*.js': ['coverage'], - 'app/**/*.js': ['webpack'] // coverage disabled + 'app/**/*.js': ['webpack'], + 'app/components/**/*.test.ts': ['typescript'] }, ngHtml2JsPreprocessor: { module: 'openproject.templates' }, + typescriptPreprocessor: { + options: { + sourceMap: false, + target: 'ES5', + module: 'amd', + noImplicitAny: false, + noResolve: true, + removeComments: true, + concatenateOutput: false + }, + typings: [ + 'typings/tsd.d.ts' + ], + transformPath: function(path) { + return path.replace(/\.ts$/, '.js'); + } + }, // test results reporter to use From 420515a7209300a2bd86982bb20851d8bd479684 Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Fri, 18 Dec 2015 15:52:05 +0100 Subject: [PATCH 5/6] Add test necessary type definitions --- .../app/components/config/routing.test.ts | 19 ++++++++++++------- frontend/karma.conf.js | 8 +++++++- frontend/tsd.json | 16 ++++++++++++++-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/frontend/app/components/config/routing.test.ts b/frontend/app/components/config/routing.test.ts index 2278d10029..9766b58f7f 100644 --- a/frontend/app/components/config/routing.test.ts +++ b/frontend/app/components/config/routing.test.ts @@ -26,8 +26,13 @@ // See doc/COPYRIGHT.rdoc for more details. // ++ +var expect = chai.expect; + describe('Routing', function () { - var $rootScope, $state, mockState = { go: function () {} }; + var $rootScope, $state, mockState = { + go: function () { + } + }; beforeEach(angular.mock.module('openproject', function ($provide) { $provide.value('$state', mockState); @@ -39,14 +44,14 @@ describe('Routing', function () { describe('when the project id is set', function () { var toState, toParams, - spy = sinon.spy(mockState, 'go'), - broadcast = function () { - $rootScope.$broadcast('$stateChangeStart', toState, toParams); - }; + spy = sinon.spy(mockState, 'go'), + broadcast = function () { + $rootScope.$broadcast('$stateChangeStart', toState, toParams); + }; beforeEach(function () { - toState = { name: 'work-packages.list' }; - toParams = { projectPath: 'my_project', projects: null }; + toState = {name: 'work-packages.list'}; + toParams = {projectPath: 'my_project', projects: null}; }); it('sets the projects path segment to "projects" ', function () { diff --git a/frontend/karma.conf.js b/frontend/karma.conf.js index 0afdabee33..59269bdc69 100644 --- a/frontend/karma.conf.js +++ b/frontend/karma.conf.js @@ -106,7 +106,13 @@ module.exports = function(config) { concatenateOutput: false }, typings: [ - 'typings/tsd.d.ts' + 'typings/tsd.d.ts', + 'typings/angularjs/angular.d.ts', + 'typings/sinon/sinon.d.ts', + 'typings/jquery/jquery.d.ts', + 'typings/mocha/mocha.d.ts', + 'typings/chai/chai.d.ts', + 'typings/angularjs/angular-mocks.d.ts' ], transformPath: function(path) { return path.replace(/\.ts$/, '.js'); diff --git a/frontend/tsd.json b/frontend/tsd.json index 5d7b5e8471..bb3e0149d9 100644 --- a/frontend/tsd.json +++ b/frontend/tsd.json @@ -6,16 +6,28 @@ "bundle": "typings/tsd.d.ts", "installed": { "jquery/jquery.d.ts": { - "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" + "commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe" }, "angularjs/angular.d.ts": { - "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" + "commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe" }, "angular-ui-router/angular-ui-router.d.ts": { "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" }, "sinon/sinon.d.ts": { "commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe" + }, + "mocha/mocha.d.ts": { + "commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe" + }, + "assertion-error/assertion-error.d.ts": { + "commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe" + }, + "chai/chai.d.ts": { + "commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe" + }, + "angularjs/angular-mocks.d.ts": { + "commit": "40c60850ad6c8175a62d5ab48c4e016ea5b3dffe" } } } From bba4544f93b7d32c4770a93ad2e88d27a61a7976 Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Fri, 18 Dec 2015 15:55:44 +0100 Subject: [PATCH 6/6] Use arrow syntax instead of function keyword --- .../app/components/config/routing.test.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/frontend/app/components/config/routing.test.ts b/frontend/app/components/config/routing.test.ts index 9766b58f7f..e4b2bee759 100644 --- a/frontend/app/components/config/routing.test.ts +++ b/frontend/app/components/config/routing.test.ts @@ -28,38 +28,37 @@ var expect = chai.expect; -describe('Routing', function () { +describe('Routing', () => { var $rootScope, $state, mockState = { - go: function () { - } + go: () => {} }; - beforeEach(angular.mock.module('openproject', function ($provide) { + beforeEach(angular.mock.module('openproject', ($provide) => { $provide.value('$state', mockState); })); - beforeEach(inject(function (_$rootScope_) { + beforeEach(inject((_$rootScope_) => { $rootScope = _$rootScope_; })); - describe('when the project id is set', function () { + describe('when the project id is set', () => { var toState, toParams, spy = sinon.spy(mockState, 'go'), - broadcast = function () { + broadcast = () => { $rootScope.$broadcast('$stateChangeStart', toState, toParams); }; - beforeEach(function () { + beforeEach(() => { toState = {name: 'work-packages.list'}; toParams = {projectPath: 'my_project', projects: null}; }); - it('sets the projects path segment to "projects" ', function () { + it('sets the projects path segment to "projects" ', () => { broadcast(); expect(toParams.projects).to.equal('projects'); }); - it('routes to the given state', function () { + it('routes to the given state', () => { broadcast(); expect(spy.withArgs(toState, toParams).called).to.be.true; });