Skip to content

Commit a6bb88f

Browse files
committed
Merge pull request #433 from Swiip/karma
Remove gulp-karma for karma
2 parents c008729 + 8b27c21 commit a6bb88f

File tree

14 files changed

+196
-77
lines changed

14 files changed

+196
-77
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ matrix:
1111
- node_js: iojs
1212

1313
before_install:
14+
- export CHROME_BIN=chromium-browser
15+
- export DISPLAY=:99.0
16+
- sh -e /etc/init.d/xvfb start
17+
- gem install sass
1418
- npm install -g npm@latest
1519
- npm install -g bower
1620
- npm install -g gulp

app/files.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"staticFiles": [
33
".bowerrc",
44
".editorconfig",
5-
".jshintrc",
5+
66
"karma.conf.js",
77
"protractor.conf.js",
88

@@ -20,6 +20,7 @@
2020
],
2121
"templates": [
2222
".gitignore",
23+
".jshintrc",
2324

2425
"package.json",
2526
"bower.json",

app/src/preprocessors.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ module.exports = function(GulpAngularGenerator) {
7373
* Copy additional lint files if needed
7474
*/
7575
GulpAngularGenerator.prototype.lintCopies = function lintCopies() {
76-
if(this.props.jsPreprocessor.srcExtension === 'es6') {
77-
this.files.push({
78-
src: 'src/.jshintrc',
79-
dest: 'src/.jshintrc',
80-
template: false
81-
});
82-
}
83-
8476
if(this.props.jsPreprocessor.key === 'coffee') {
8577
this.files.push({
8678
src: 'coffeelint.json',

app/templates/.jshintrc renamed to app/templates/_.jshintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
<% if (props.jsPreprocessor.srcExtension === 'es6') { %>
3+
"esnext": true,
4+
<% } %>
25
"globalstrict": true,
36
"bitwise": true,
47
"camelcase": true,

app/templates/_karma.conf.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,49 @@
22

33
module.exports = function(config) {
44

5-
config.set({
5+
var configuration = {
66
autoWatch : false,
77

88
frameworks: ['jasmine'],
99

10+
ngHtml2JsPreprocessor: {
11+
stripPrefix: 'src/',
12+
moduleName: 'gulpAngular'
13+
},
14+
1015
<% if(props.jsPreprocessor.key === 'traceur') { %>
1116
browsers : ['Chrome'],
1217

1318
plugins : [
14-
'karma-chrome-launcher',
15-
'karma-jasmine'
16-
]
17-
<% } else {%>
19+
'karma-chrome-launcher',
20+
<% } else { %>
1821
browsers : ['PhantomJS'],
1922

2023
plugins : [
21-
'karma-phantomjs-launcher',
22-
'karma-jasmine'
23-
]
24+
'karma-phantomjs-launcher',
2425
<% } %>
25-
});
26+
'karma-jasmine',
27+
'karma-ng-html2js-preprocessor'
28+
],
29+
30+
preprocessors: {
31+
'src/**/*.html': ['ng-html2js']
32+
}
33+
};
34+
35+
// This block is needed to execute Chrome on Travis
36+
// If you ever plan to use Chrome and Travis, you can keep it
37+
// If not, you can safely remove it
38+
// https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076
39+
if(configuration.browsers[0] === 'Chrome' && process.env.TRAVIS) {
40+
configuration.customLaunchers = {
41+
'chrome-travis-ci': {
42+
base: 'Chrome',
43+
flags: ['--no-sandbox']
44+
}
45+
};
46+
configuration.browsers = ['chrome-travis-ci'];
47+
}
48+
49+
config.set(configuration);
2650
};

app/templates/_package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"gulp-minify-html": "~0.1.7",
3232
"gulp-inject": "~1.1.1",
3333
"gulp-protractor": "~0.0.12",
34-
"gulp-karma": "~0.0.4",
3534
"gulp-sourcemaps": "~1.3.0",
3635
<% if (props.cssPreprocessor.key === 'node-sass') { %>
3736
"gulp-sass": "~1.3.0",
@@ -73,12 +72,15 @@
7372
"merge-stream": "~0.1.7",
7473
"jshint-stylish": "~1.0.0",
7574
"wiredep": "~2.2.0",
75+
"karma": "~0.12.31",
7676
"karma-jasmine": "~0.3.1",
7777
<% if(props.jsPreprocessor.key === 'traceur') { %>
7878
"karma-chrome-launcher": "~0.1.7",
79-
<% } else {%>
79+
<% } else { %>
8080
"karma-phantomjs-launcher": "~0.1.4",
8181
<% } %>
82+
"karma-ng-html2js-preprocessor": "~0.1.2",
83+
"concat-stream": "~1.4.7",
8284
"require-dir": "~0.1.0",
8385
"browser-sync": "~2.1.4",
8486
"browser-sync-spa": "~1.0.1",

app/templates/gulp/_inject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function(options) {
2020
], { read: false });
2121
<% } %>
2222

23-
<% if (props.jsPreprocessor.srcExtension === 'ts') { %>
23+
<% if (props.jsPreprocessor.key === 'typescript') { %>
2424
var sortOutput = require('../' + options.tmp + '/sortOutput.json');
2525
<% } %>
2626

app/templates/gulp/_unit-tests.js

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,80 @@ var gulp = require('gulp');
55
var $ = require('gulp-load-plugins')();
66

77
var wiredep = require('wiredep');
8+
var karma = require('karma');
9+
var concat = require('concat-stream');
10+
var _ = require('lodash');
811

912
module.exports = function(options) {
10-
function runTests (singleRun) {
13+
function listFiles(callback) {
1114
var bowerDeps = wiredep({
1215
directory: 'bower_components',
13-
exclude: ['bootstrap-sass-official'],
16+
<% if(wiredepExclusions.length > 0) { %>
17+
exclude: [<%= wiredepExclusions.join(', ') %>],
18+
<% } %>
1419
dependencies: true,
1520
devDependencies: true
1621
});
1722

18-
var testFiles = bowerDeps.js.concat([
23+
var specFiles = [
24+
options.src + '/**/*.spec.js',
25+
options.src + '/**/*.mock.js'
26+
];
27+
28+
var htmlFiles = [
29+
options.src + '/**/*.html'
30+
];
31+
32+
var srcFiles = [
1933
<% if (props.jsPreprocessor.key === 'none') { %>
2034
options.src + '/{app,components}/**/*.js'
2135
<% } else if (props.jsPreprocessor.extension === 'js') { %>
22-
options.tmp + '/serve/app/index.js',
23-
options.src + '/{app,components}/**/*.spec.js',
24-
options.src + '/{app,components}/**/*.mock.js'
36+
options.tmp + '/serve/app/index.js'
2537
<% } else if (props.jsPreprocessor.key === 'typescript') { %>
2638
options.tmp + '/serve/{app,components}/**/!(index).js',
27-
options.tmp + '/serve/{app,components}/**/index.js',
28-
options.src + '/{app,components}/**/*.spec.js',
29-
options.src + '/{app,components}/**/*.mock.js'
39+
options.tmp + '/serve/{app,components}/**/index.js'
3040
<% } else { %>
31-
options.tmp + '/serve/{app,components}/**/*.js',
32-
options.src + '/{app,components}/**/*.spec.js',
33-
options.src + '/{app,components}/**/*.mock.js'
41+
options.tmp + '/serve/{app,components}/**/*.js'
42+
<% } %>
43+
].concat(specFiles.map(function(file) {
44+
return '!' + file;
45+
}));
46+
47+
<% if (props.jsPreprocessor.key === 'typescript') { %>
48+
var sortOutput = require('../' + options.tmp + '/sortOutput.json');
3449
<% } %>
35-
]);
3650

37-
return gulp.src(testFiles)
38-
.pipe($.karma({
39-
configFile: 'karma.conf.js',
40-
action: (singleRun)? 'run': 'watch'
51+
<% if (props.jsPreprocessor.key === 'typescript') { %>
52+
gulp.src(srcFiles, { read: false })
53+
.pipe($.order(sortOutput, {base: options.tmp + '/serve'}))
54+
<% } else if (props.jsPreprocessor.extension !== 'js') { %>
55+
gulp.src(srcFiles)
56+
.pipe($.angularFilesort()).on('error', options.errorHandler('AngularFilesort'))
57+
<% } else { %>
58+
gulp.src(srcFiles)
59+
<% } %>
60+
.pipe(concat(function(files) {
61+
callback(bowerDeps.js
62+
.concat(_.pluck(files, 'path'))
63+
.concat(htmlFiles)
64+
.concat(specFiles));
4165
}));
4266
}
4367

44-
gulp.task('test', ['scripts'], runTests.bind(this, true));
45-
gulp.task('test:auto', ['scripts'], runTests.bind(this, false));
68+
function runTests (singleRun, done) {
69+
listFiles(function(files) {
70+
karma.server.start({
71+
configFile: __dirname + '/../karma.conf.js',
72+
files: files,
73+
singleRun: singleRun
74+
}, done);
75+
});
76+
}
77+
78+
gulp.task('test', ['scripts'], function(done) {
79+
runTests(true, done);
80+
});
81+
gulp.task('test:auto', ['watch'], function(done) {
82+
runTests(false, done);
83+
});
4684
};

app/templates/src/.jshintrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/inception/test-inception.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('gulp-angular generator inception tests', function () {
7676
ui: prompts.ui.values.bootstrap,
7777
bootstrapComponents: prompts.bootstrapComponents.values['ui-bootstrap'],
7878
cssPreprocessor: prompts.cssPreprocessor.values.less,
79-
jsPreprocessor: prompts.jsPreprocessor.values['babel'],
79+
jsPreprocessor: prompts.jsPreprocessor.values.babel,
8080
htmlPreprocessor: prompts.htmlPreprocessor.values.haml
8181
}).then(function(generator) {
8282
gulpAngular = generator;
@@ -124,6 +124,32 @@ describe('gulp-angular generator inception tests', function () {
124124
});
125125
});
126126

127+
describe('with [no jquery, $http, Bootstrap, AngularStrap, ruby-sass, Traceur]', function () {
128+
before(function() {
129+
return inception.prepare({}, {
130+
ui: prompts.ui.values.bootstrap,
131+
bootstrapComponents: prompts.bootstrapComponents.values['angular-strap'],
132+
cssPreprocessor: prompts.cssPreprocessor.values['ruby-sass'],
133+
jsPreprocessor: prompts.jsPreprocessor.values.traceur
134+
}).then(function(generator) {
135+
gulpAngular = generator;
136+
});
137+
});
138+
139+
it('should pass build', function () {
140+
return inception.run(gulpAngular, 'build').should.be.fulfilled;
141+
});
142+
it('should pass test', function () {
143+
return inception.run(gulpAngular, 'test').should.be.fulfilled;
144+
});
145+
it('should pass protractor', function () {
146+
return inception.run(gulpAngular, 'protractor').should.be.fulfilled;
147+
});
148+
it('should pass protractor:dist', function () {
149+
return inception.run(gulpAngular, 'protractor:dist').should.be.fulfilled;
150+
});
151+
});
152+
127153
describe('with [src:src/angular/app e2e:tests/e2e dist:target/build/folder tmp:.tmp/folder] and default promps', function () {
128154
before(function() {
129155
return inception.prepare({

0 commit comments

Comments
 (0)