Skip to content

Commit a619692

Browse files
committed
browserify tests for karma
1 parent aa89861 commit a619692

File tree

3 files changed

+105
-8
lines changed

3 files changed

+105
-8
lines changed

gulpfile.js

+33-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var browserify = require('browserify')
44
, clean = require('gulp-clean')
55
, connect = require('gulp-connect')
66
, eslint = require('gulp-eslint')
7+
, glob = require('glob')
78
, gulp = require('gulp')
89
, mocha = require('gulp-mocha')
910
, ngmin = require('gulp-ngmin')
@@ -14,13 +15,26 @@ var browserify = require('browserify')
1415

1516
/*
1617
* Useful tasks:
17-
* - gulp fast: browserifies, no minification, does not start server.
18-
* - gupl watch: starts server, browserify & live reload on changes,
19-
* no minification.
20-
* - gulp: browserifies and minifies, does not start server.
18+
* - gulp fast:
19+
* - linting
20+
* - unit tests
21+
* - browserification
22+
* - no minification, does not start server.
23+
* - gulp watch:
24+
* - starts server with live reload enabled
25+
* - lints, unit tests, browserifies and live-reloads changes in browser
26+
* - no minification
27+
* - gulp:
28+
* - linting
29+
* - unit tests
30+
* - browserification
31+
* - minification and browserification of minified sources
32+
* - start server for e2e tests
33+
* - run Protractor End-to-end tests
34+
* - stop server immediately when e2e tests have finished
2135
*
22-
* At development time, you should usually just have run 'gulp watch' in the
23-
* background.
36+
* At development time, you should usually just have 'gulp watch' running in the
37+
* background all the time. Use 'gulp' before releases.
2438
*/
2539

2640
var liveReload = true;
@@ -48,7 +62,7 @@ gulp.task('unit', function () {
4862
.pipe(mocha({ reporter: 'dot' }));
4963
});
5064

51-
gulp.task('browserify', ['lint', 'unit'], function() {
65+
gulp.task('browserify', /*['lint', 'unit'],*/ function() {
5266
return browserify('./app/js/app.js')
5367
.bundle({ debug: true })
5468
.pipe(source('app.js'))
@@ -73,6 +87,18 @@ gulp.task('browserify-min', ['ngmin'], function() {
7387
.pipe(gulp.dest('./app/dist/'));
7488
});
7589

90+
gulp.task('browserify-tests', function() {
91+
var bundler = browserify();
92+
glob.sync('./test/unit/**/*.js')
93+
.forEach(function(file) {
94+
bundler.add(file);
95+
})
96+
return bundler
97+
.bundle({ debug: true })
98+
.pipe(source('browserified_tests.js'))
99+
.pipe(gulp.dest('./test/browserified'));
100+
});
101+
76102
gulp.task('server', ['browserify'], function() {
77103
connect.server({
78104
root: 'app',

karma.conf.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Karma configuration
2+
// Generated on Mon May 26 2014 23:07:02 GMT+0200 (CEST)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
11+
// frameworks to use
12+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
frameworks: ['mocha'],
14+
15+
16+
// list of files / patterns to load in the browser
17+
files: [
18+
'test/browserified/browserified_tests.js'
19+
],
20+
21+
22+
// list of files to exclude
23+
exclude: [
24+
],
25+
26+
27+
// preprocess matching files before serving them to the browser
28+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
29+
preprocessors: {
30+
},
31+
32+
33+
// test results reporter to use
34+
// possible values: 'dots', 'progress'
35+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
36+
reporters: ['progress'],
37+
38+
39+
// web server port
40+
port: 9876,
41+
42+
43+
// enable / disable colors in the output (reporters and logs)
44+
colors: true,
45+
46+
47+
// level of logging
48+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
49+
logLevel: config.LOG_INFO,
50+
51+
52+
// enable / disable watching file and executing tests whenever any file changes
53+
autoWatch: true,
54+
55+
56+
// start these browsers
57+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
58+
browsers: ['Chrome', 'Firefox'],
59+
60+
61+
// Continuous Integration mode
62+
// if true, Karma captures browsers, runs the tests and exits
63+
singleRun: false
64+
});
65+
};

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"devDependencies": {
1616
"browserify": "^3.44.2",
1717
"chai": "^1.9.1",
18+
"glob": "^4.0.0",
1819
"gulp": "^3.6.2",
1920
"gulp-clean": "^0.2.4",
2021
"gulp-connect": "^2.0.5",
@@ -24,9 +25,14 @@
2425
"gulp-protractor": "0.0.7",
2526
"gulp-streamify": "0.0.5",
2627
"gulp-uglify": "^0.2.1",
28+
"karma": "^0.12.16",
29+
"karma-chai": "^0.1.0",
30+
"karma-chrome-launcher": "^0.1.4",
31+
"karma-firefox-launcher": "^0.1.3",
32+
"karma-mocha": "^0.1.3",
33+
"karma-sinon": "^1.0.3",
2734
"mocha": "^1.18.2",
2835
"protractor": "^0.22.0",
29-
"sandboxed-module": "^0.3.0",
3036
"sinon": "^1.9.1",
3137
"sinon-chai": "^2.5.0",
3238
"vinyl-source-stream": "^0.1.1"

0 commit comments

Comments
 (0)