Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 52519d4

Browse files
committed
chore(travis): speed up the build
- parallelize the tasks - cache requests (e2e tests) This reduces the time from ~18min to ~12min. It makes the output little messy. We could buffer output of each task and display it once it's fully finished, nicely. I think giving instant feedback is better.
1 parent 78728df commit 52519d4

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ before_script:
1313
- ./lib/sauce/sauce_connect_setup.sh
1414
- npm install -g grunt-cli
1515
- grunt package
16-
- grunt webserver > /dev/null &
1716
- ./lib/sauce/sauce_connect_block.sh
1817

1918
script:
20-
- grunt test --reporters dots --browsers SL_Chrome
19+
- grunt parallel:travis --reporters dots --browsers SL_Chrome

Gruntfile.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = function(grunt) {
77
grunt.loadNpmTasks('grunt-contrib-copy');
88
grunt.loadNpmTasks('grunt-contrib-connect');
99
grunt.loadNpmTasks('grunt-contrib-compress');
10+
grunt.loadNpmTasks('grunt-parallel');
1011
grunt.loadTasks('lib/grunt');
1112

1213
var NG_VERSION = util.getVersion();
@@ -21,6 +22,20 @@ module.exports = function(grunt) {
2122
grunt.initConfig({
2223
NG_VERSION: NG_VERSION,
2324

25+
parallel: {
26+
travis: {
27+
options: {
28+
stream: true,
29+
},
30+
tasks: [
31+
util.parallelTask('test:modules'),
32+
util.parallelTask('test:jquery'),
33+
util.parallelTask('test:jqlite'),
34+
util.parallelTask('test:e2e')
35+
]
36+
}
37+
},
38+
2439
connect: {
2540
devserver: {
2641
options: {
@@ -40,7 +55,24 @@ module.exports = function(grunt) {
4055
}
4156
}
4257
},
43-
testserver: {}
58+
testserver: {
59+
options: {
60+
middleware: function(connect, options){
61+
return [
62+
function(req, resp, next) {
63+
// cache get requests to speed up tests on travis
64+
if (req.method === 'GET') {
65+
resp.setHeader('Cache-control', 'public, max-age=3600');
66+
}
67+
68+
next();
69+
},
70+
connect.favicon('images/favicon.ico'),
71+
connect.static(options.base)
72+
];
73+
}
74+
}
75+
}
4476
},
4577

4678

karma-shared.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = function(config) {
55
logLevel: config.LOG_INFO,
66
logColors: true,
77
browsers: ['Chrome'],
8+
runnerPort: 0,
89

910
// config for Travis CI
1011
sauceLabs: {

lib/grunt/utils.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ module.exports = {
3333
var browsers = grunt.option('browsers');
3434
var reporters = grunt.option('reporters');
3535
var noColor = grunt.option('no-colors');
36+
var port = grunt.option('port');
3637
var p = spawn('node', ['node_modules/karma/bin/karma', 'start', config,
3738
singleRun ? '--single-run=true' : '',
3839
reporters ? '--reporters=' + reporters : '',
3940
browsers ? '--browsers=' + browsers : '',
40-
noColor ? '--no-colors' : ''
41+
noColor ? '--no-colors' : '',
42+
port ? '--port=' + port : ''
4143
]);
4244
p.stdout.pipe(process.stdout);
4345
p.stderr.pipe(process.stderr);
@@ -170,5 +172,24 @@ module.exports = {
170172
}
171173
next();
172174
};
173-
}
175+
},
176+
177+
parallelTask: function(name) {
178+
var args = [name, '--port=' + this.lastParallelTaskPort];
179+
180+
if (grunt.option('browsers')) {
181+
args.push('--browsers=' + grunt.option('browsers'));
182+
}
183+
184+
if (grunt.option('reporters')) {
185+
args.push('--reporters=' + grunt.option('reporters'));
186+
}
187+
188+
this.lastParallelTaskPort++;
189+
190+
191+
return {grunt: true, args: args};
192+
},
193+
194+
lastParallelTaskPort: 9876
174195
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"grunt-contrib-compress": "0.4.1",
1010
"grunt-contrib-connect": "0.1.2",
1111
"grunt-contrib-copy": "0.4.1",
12+
"grunt-parallel": "~0.2.0",
1213
"jasmine-node": "1.2.3",
1314
"q": "~0.9.2",
1415
"q-fs": "0.1.36",

0 commit comments

Comments
 (0)