Skip to content

Commit 58edb91

Browse files
author
kfb
committed
chore(tests) add karma to 'watch' and 'build' tasks
1 parent f049e21 commit 58edb91

7 files changed

Lines changed: 132 additions & 8 deletions

File tree

config.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
"dist" : "dist",
55

66
"paths" : {
7-
"scripts" : "src/+(app|common)/**/*.js",
8-
"templates" : [
7+
"scripts": [
8+
"src/+(app|common)/**/*.js",
9+
"!src/+(app|common)/**/*.spec.js"
10+
],
11+
"templates": [
912
"src/app/**/*.tpl.html",
1013
"src/common/**/*.tpl.html"
1114
],
1215
"sass" : "src/+(sass|app|common)/**/*",
1316
"assets" : "src/assets/**",
14-
"html" : "src/index.html"
17+
"html" : "src/index.html",
18+
"tests" : "src/+(app|common)/**/*.spec.js"
1519
},
1620

17-
"vendor_files" : {
21+
"vendor_files": {
1822
"js": [
1923
"vendor/angular/angular.js",
2024
"vendor/angular-ui-router/release/angular-ui-router.js",
@@ -25,5 +29,7 @@
2529
"assets": [
2630
"vendor/bootstrap-sass-official/vendor/assets/fonts/**/*"
2731
]
28-
}
32+
},
33+
34+
"mocks": "vendor/angular-mocks/angular-mocks.js"
2935
}

gulpfile.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,39 @@ gulp.task('html', ['html:replace'], function () {
177177

178178

179179

180+
// Karma
181+
// ============
182+
var testFiles = [
183+
config.build + '/vendor/**/*.js',
184+
config.build + '/+(app|common)/**/*.js',
185+
config.mocks,
186+
config.paths.tests
187+
];
188+
189+
gulp.task('test:run', ['vendor:assets'] , function() {
190+
// Be sure to return the stream
191+
return gulp.src(testFiles)
192+
.pipe(plugins.karma({
193+
configFile: 'karma.conf.js',
194+
action: 'run'
195+
}));
196+
});
197+
198+
gulp.task('test:watch', ['vendor:assets'], function() {
199+
gulp.src(testFiles)
200+
.pipe(plugins.karma({
201+
configFile: 'karma.conf.js',
202+
action: 'watch'
203+
}));
204+
});
205+
206+
207+
180208
// Set up Watch
181209
// ============
182210

183211
// Add files to Watch
184-
gulp.task('watch', ['styles:sass', 'scripts:lint', 'scripts:html2js', 'assets:img', 'vendor:js', 'vendor:assets', 'html:inject'], function () {
212+
gulp.task('watch', ['styles:sass', 'scripts:lint', 'scripts:html2js', 'assets:img', 'vendor:js', 'vendor:assets', 'test:watch', 'html:inject'], function () {
185213
require('./server.js')(server);
186214

187215
// watch for JS changes
@@ -253,7 +281,7 @@ gulp.task('clean', function () {
253281
// ===============
254282

255283
gulp.task('build', ['clean'], function () {
256-
gulp.start('styles:sass', 'scripts:lint', 'scripts:html2js', 'vendor:js', 'vendor:assets', 'assets:img', 'html:inject');
284+
gulp.start('styles:sass', 'scripts:lint', 'scripts:html2js', 'vendor:js', 'vendor:assets', 'test:run', 'assets:img', 'html:inject');
257285
});
258286

259287
gulp.task('compile', ['build'], function () {

karma.conf.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = function ( karma ) {
2+
karma.set({
3+
frameworks: [ 'jasmine' ],
4+
plugins: [ 'karma-jasmine', 'karma-firefox-launcher', 'karma-chrome-launcher', 'karma-phantomjs-launcher' ],
5+
/**
6+
* How to report, by default.
7+
*/
8+
reporters: 'dots',
9+
/**
10+
* The list of browsers to launch to test on. This includes only "Firefox" by
11+
* default, but other browser names include:
12+
* Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
13+
*
14+
* Note that you can also use the executable name of the browser, like "chromium"
15+
* or "firefox", but that these vary based on your operating system.
16+
*
17+
* You may also leave this blank and manually navigate your browser to
18+
* http://localhost:9018/ when you're running tests. The window/tab can be left
19+
* open and the tests will automatically occur there during the build. This has
20+
* the aesthetic advantage of not launching a browser every time you save.
21+
*/
22+
browsers: [
23+
'Chrome'
24+
]
25+
});
26+
};

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@
3636
"gulp-ruby-sass": "~0.3.0",
3737
"gulp-size": "~0.1.2",
3838
"gulp-uglify": "~0.2.0",
39-
"gulp-util": "~2.2.14"
39+
"gulp-util": "~2.2.14",
40+
"karma-script-launcher": "^0.1.0",
41+
"karma-chrome-launcher": "^0.1.2",
42+
"karma-firefox-launcher": "^0.1.3",
43+
"karma-html2js-preprocessor": "^0.1.0",
44+
"karma-jasmine": "^0.1.5",
45+
"requirejs": "^2.1.11",
46+
"karma-requirejs": "^0.2.1",
47+
"karma-coffee-preprocessor": "^0.1.3",
48+
"karma-phantomjs-launcher": "^0.1.2",
49+
"karma": "^0.10.9",
50+
"gulp-karma": "0.0.2"
4051
}
4152
}

src/app/about/about.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Tests sit right alongside the file they are testing, which is more intuitive
3+
* and portable than separating `src` and `test` directories. Additionally, the
4+
* build process will exclude all `.spec.js` files from the build
5+
* automatically.
6+
*/
7+
describe( 'home module', function() {
8+
beforeEach( module( 'ngDevstack' ) );
9+
beforeEach( module( 'ngDevstack.about' ) );
10+
beforeEach(inject(function($rootScope, $controller) {
11+
$controller('AboutCtrl', {$scope: $rootScope.$new()});
12+
}));
13+
14+
it( 'should load', inject( function() {
15+
expect( true ).toBeTruthy();
16+
}));
17+
});
18+

src/app/app.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
describe( 'AppCtrl', function() {
2+
describe( 'isCurrentUrl', function() {
3+
var AppCtrl, $location, $scope;
4+
5+
beforeEach( module( 'ngDevstack' ) );
6+
7+
beforeEach( inject( function( $controller, _$location_, $rootScope ) {
8+
$location = _$location_;
9+
$scope = $rootScope.$new();
10+
AppCtrl = $controller( 'AppCtrl', { $location: $location, $scope: $scope });
11+
}));
12+
13+
it( 'should pass a dummy test', inject( function() {
14+
expect( AppCtrl ).toBeTruthy();
15+
}));
16+
});
17+
});
18+

src/app/home/home.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Tests sit right alongside the file they are testing, which is more intuitive
3+
* and portable than separating `src` and `test` directories. Additionally, the
4+
* build process will exclude all `.spec.js` files from the build
5+
* automatically.
6+
*/
7+
describe( 'home module', function() {
8+
beforeEach( module( 'ngDevstack' ) );
9+
beforeEach( module( 'ngDevstack.home' ) );
10+
beforeEach(inject(function($rootScope, $controller) {
11+
$controller('HomeCtrl', {$scope: $rootScope.$new()});
12+
}));
13+
14+
it( 'should load', inject( function() {
15+
expect( true ).toBeTruthy();
16+
}));
17+
});

0 commit comments

Comments
 (0)