Skip to content

Commit

Permalink
Switched over to using mocha/sinon/chai test framework stack with typ…
Browse files Browse the repository at this point in the history
…escript for testing
  • Loading branch information
zakhenry committed Jul 14, 2015
1 parent ad2d703 commit 6a85441
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 31 deletions.
17 changes: 0 additions & 17 deletions app/src/app/app.spec.js

This file was deleted.

28 changes: 28 additions & 0 deletions app/src/app/app.spec.ts
@@ -0,0 +1,28 @@
describe('Bootstrap', () => {

describe('isCurrentUrl', () => {

let AppCtrl, $location, $scope;

beforeEach(() => {

module('app');
});

beforeEach(()=> {
inject(($controller, _$location_, $rootScope) => {
$location = _$location_;
$scope = $rootScope.$new();
AppCtrl = $controller('app.controller', {$location: $location, $scope: $scope});
})
});

it('should pass a dummy test', () => {

expect(AppCtrl).to.be.ok;
});


});

});
46 changes: 40 additions & 6 deletions gulpfile.js
Expand Up @@ -57,14 +57,22 @@ var paths = {
return this.base + '/assets/images/**/*'
},
get tests(){
return this.base + '/**/*.spec.js'
return [
//@todo relax this to app/bower_components/**/*.d.ts and negate the typings files or even better allow resolution of duplicate typings files
'app/bower_components/**/dist/*.d.ts', //only read in the .d.ts files from bower distribution
'app/typings/**/*.d.ts', //get the local typings files
this.base + '/**/*.spec.ts'
]
}
},
dest: {
base: 'app/build',
get scripts(){
return this.base+ '/js'
},
get tests(){
return this.base+ '/tests'
},
get appStyles(){
return this.base + '/css/**/*.css'
},
Expand Down Expand Up @@ -93,7 +101,7 @@ gulp.task('clean', 'deletes all build files', [], function(cb) {
plugins.del([paths.dest.base], cb);
});

gulp.task('scripts', 'processes javascript & typescript files', [], function () {
gulp.task('scripts:app', 'processes javascript & typescript files', [], function () {

var tsFilter = plugins.filter('**/*.ts');
var jsFilter = plugins.filter('**/*.js');
Expand Down Expand Up @@ -131,6 +139,32 @@ gulp.task('scripts', 'processes javascript & typescript files', [], function ()
]);
});

gulp.task('scripts:test', 'processes javascript & typescript tests', [], function () {

var tsdFilter = plugins.filter('**/*.d.ts');

var tsResult = gulp.src(paths.src.tests)
//remove the typings references from tsd files @todo remove when tsd recursive resolution is complete https://github.com/DefinitelyTyped/tsd/issues/150
.pipe(tsdFilter)
.pipe(plugins.replace('/// <reference path="../typings/tsd.d.ts" />', ''))
.pipe(tsdFilter.restore())

.pipe(plugins.sourcemaps.init())

.pipe(plugins.typescript({
target: "ES5",
noExternalResolve: true,
typescript: require('typescript'),
declarationFiles: false
}, undefined, plugins.typescript.reporter.longReporter()))
;

return tsResult.js
.pipe(plugins.sourcemaps.write('./', {includeContent: false, sourceRoot: __dirname+'/app/src/'}))
.pipe(gulp.dest(paths.dest.tests))
;
});

gulp.task('templates-watch', 'watches template files for changes [not working]', ['templates'], browserSync.reload);
gulp.task('templates', 'builds template files', [], function(){
return gulp.src(paths.src.templates)
Expand Down Expand Up @@ -266,7 +300,7 @@ gulp.task('default', 'default task', ['build']);
gulp.task('build', 'runs build sequence for frontend', function (cb){
plugins.runSequence('clean',
//'bower:install',
['scripts', 'templates', 'styles', 'assets', 'bower:build'],
['scripts:app', 'templates', 'styles', 'assets', 'bower:build'],
'index',
cb);
});
Expand All @@ -290,7 +324,7 @@ gulp.task('watch', 'starts up browsersync server and runs task watchers', [], fu
});

gulp.watch(paths.src.templates, ['templates']);
gulp.watch(paths.src.scripts, ['scripts']);
gulp.watch(paths.src.scripts, ['scripts:app']);
gulp.watch(paths.src.styles, ['styles']);
gulp.watch(paths.src.assets, ['assets']);
gulp.watch(paths.src.base+'/index.html', ['index']);
Expand All @@ -299,7 +333,7 @@ gulp.task('watch', 'starts up browsersync server and runs task watchers', [], fu


gulp.task('test:app', 'unit test & report frontend coverage', [], function(cb){
plugins.runSequence('build', 'test:karma', cb);
plugins.runSequence('build', 'scripts:test', 'test:karma', cb);
});

gulp.task('test:karma', 'unit test the frontend', [], function(){
Expand All @@ -313,7 +347,7 @@ gulp.task('test:karma', 'unit test the frontend', [], function(){
.map(function(path){
return 'app/build/'+path;
})
.concat(plugins.globby.sync(paths.src.tests))
.concat(plugins.globby.sync(paths.dest.tests+'/**/*.js'))
;

testFiles.push('app/build/js/templates.js');
Expand Down
16 changes: 11 additions & 5 deletions karma.conf.js
@@ -1,14 +1,13 @@
module.exports = function(config) {
config.set({

frameworks: ['jasmine'],
plugins: ['karma-jasmine', 'karma-phantomjs-launcher', 'karma-coverage'],
frameworks: ['chai-as-promised', 'mocha', 'sinon', 'sinon-chai'],

preprocessors: {
'app/build/js/**/*.js': ['coverage']
'app/build/**/*.js': ['coverage']
},

reporters: ['progress', 'coverage'],
reporters: ['mocha', 'coverage'],

port: 9018,
runnerPort: 9100,
Expand All @@ -19,7 +18,14 @@ module.exports = function(config) {
'PhantomJS'
],

logLevel: config.LOG_INFO,
client: {
captureConsole: true,
mocha: {
bail: true
}
},

logLevel: config.LOG_DEBUG,

coverageReporter: {
// specify a common output directory
Expand Down
12 changes: 9 additions & 3 deletions package.json
Expand Up @@ -57,13 +57,18 @@
"gulp-util": "^3.0.4",
"gulp-watch": "^4.2.1",
"istanbul": "bryanforbes/istanbul#source-map-resolve",
"jasmine-before-all": "^0.1.0",
"jasmine-node": "^1.14.5",
"json5": "^0.4.0",
"karma": "^0.12.31",
"karma-chai": "^0.1.0",
"karma-chai-as-promised": "^0.1.2",
"karma-chai-plugins": "^0.6.0",
"karma-chrome-launcher": "^0.2.0",
"karma-coverage": "gotwarlost/karma-coverage.git#source-lookup",
"karma-jasmine": "^0.3.5",
"karma-mocha": "^0.2.0",
"karma-mocha-reporter": "^1.0.2",
"karma-phantomjs-launcher": "^0.1.4",
"karma-sinon": "^1.0.4",
"karma-sinon-chai": "^1.0.0",
"lodash": "^3.6.0",
"main-bower-files": "^2.6.2",
"merge2": "^0.3.6",
Expand All @@ -72,6 +77,7 @@
"run-sequence": "^1.0.2",
"sanitize-filename": "^1.3.0",
"selenium-webdriver": "^2.45.1",
"sinon": "^1.15.4",
"tsd": "^0.6.3",
"typescript": "^1.5.0-beta"
}
Expand Down

0 comments on commit 6a85441

Please sign in to comment.