-
Notifications
You must be signed in to change notification settings - Fork 48
/
Gruntfile.js
125 lines (108 loc) · 4.17 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
module.exports = function (grunt) {
var fs = require('fs');
var path = require('path');
var reqConf = grunt.file.readJSON('lib/common/resolver/paths.json');
var lazoReqConf = grunt.file.readJSON('conf.json');
function getPaths(conf, env) {
var paths = grunt.util._.extend({}, conf.common, (conf[env] || conf.client));
for (var key in paths) {
paths[key] = paths[key].replace('{env}', (env || 'client'));
}
return paths;
}
grunt.registerTask('configure-intern', 'Create intern configuration for runner', function () {
var env = this.args[0] === 'client-local' ? 'client' : this.args[0];
var paths = getPaths(reqConf, env);
var specs = grunt.file.expand([
'test/unit/' + env + '/**/*.js',
'test/unit/client-server/**/*.js',
'!**/*.skip.js'
]);
specs = specs.map(function (spec) {
return spec.substr(0, spec.lastIndexOf('.js'));
});
var conf = grunt.config.get('intern');
conf[this.args[0]].options.suites = specs;
if (env === 'client' && this.args[0] !== 'client-local') {
conf[this.args[0]].options.config = 'test/unit/conf.client.phantomjs';
}
grunt.config.set('intern', conf);
});
// ci and local; if local or unsecure pull request uses phantomjs and selenium;
// if secure pull request then it uses sauce labs
grunt.registerTask('test', ['test-server', 'test-client']);
// local
grunt.registerTask('test-local', ['test-server', 'test-client-local']);
grunt.registerTask('test-server', ['configure-intern:server', 'intern:server']);
grunt.registerTask('test-client', function () {
var tasks = ['configure-intern:client', 'intern:client'];
// running locally; ci starts selenium before testing
if (!process.env.TRAVIS) {
tasks.unshift('exec:selenium-server');
}
grunt.task.run(tasks);
});
grunt.registerTask('test-client-local', ['exec:selenium-server', 'configure-intern:client-local', 'intern:client-local']);
grunt.initConfig({
requirejs: {
compile: {
options: {
include: reqConf.lib,
paths: getPaths(reqConf),
shim: lazoReqConf.requirejs.client.shim,
map: {
'*': {
'l': '/lib/client/loader.js',
// don't define 'bundler' in paths.json because
// it will result in a build error due to
// duplicate paths; 'bundler' path is set at run time
'bundler': 'lazoBundle'
}
},
outFileName: 'lib',
baseUrl: path.resolve('.'),
optimize: 'uglify2',
logLevel: 4,
out: 'lib/optimized/lib.js'
}
}
},
watch: {
test: {
files: ['lib/**/*.*', '!lib/vendor/**/*.*'],
tasks: ['castle'],
options: {
events: ['changed']
}
},
lib: {
files: ['lib/**/*.*', '!lib/**/server/**/*.*', '!lib/vendor/**/*.*'],
tasks: ['requirejs']
}
},
intern: {
'client-local': {
options: {
runType: 'runner',
config: 'test/unit/conf.client.local'
}
},
client: {
options: {
runType: 'runner',
config: 'test/unit/conf.client'
}
},
server: {
options: {
config: 'test/unit/conf.server'
}
}
},
exec: { 'selenium-server': 'node node_modules/selenium-server/bin/selenium &' }
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('intern');
grunt.loadNpmTasks('grunt-exec');
};