forked from yahoo/react-stickynode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
322 lines (305 loc) · 10 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// jscs:disable maximumLineLength
'use strict';
var fs = require('fs');
var path = require('path');
module.exports = function (grunt) {
// autoload installed tasks
[
'grunt-atomizer',
'grunt-contrib-clean',
'grunt-contrib-connect',
'grunt-contrib-jshint',
'grunt-contrib-watch',
'grunt-babel',
'grunt-shell',
'grunt-webpack'
].forEach(function (packageName) {
var moduleTasks = path.resolve(__dirname, '..', 'node_modules', packageName, 'tasks');
if (!fs.existsSync(moduleTasks)) {
moduleTasks = path.resolve(process.cwd(), 'node_modules', packageName, 'tasks');
}
if (fs.existsSync(moduleTasks)) {
grunt.loadTasks(moduleTasks);
} else {
grunt.log.error(moduleTasks + ' could not be found.');
}
});
// configurable paths
var env = process.env;
var projectConfig = {
src: 'src',
dist: 'dist',
tmp: 'tmp',
unit: 'tests/unit',
functional: 'tests/functional',
spec: 'tests/spec',
coverage_dir: grunt.option('coverage_dir') || 'artifacts',
test_results_dir: grunt.option('test_results_dir') || 'artifacts'
};
env.XUNIT_FILE = projectConfig.test_results_dir + '/xunit.xml';
grunt.initConfig({
project: projectConfig,
clean: {
dist: {
files: [
{
dot: true,
src: ['<%= project.dist %>']
}
]
},
tmp: {
files: [
{
dot: true,
src: ['<%= project.tmp %>']
}
]
},
functional: {
files: [
{
dot: true,
src: [
'<%= project.functional %>/bundle.js',
'<%= project.functional %>/css/atomic.css',
'<%= project.functional %>/console.js',
'<%= project.functional %>/*-functional.js'
]
}
]
}
},
// atomizer
atomizer: {
// used by functional tests
functional: {
files: [{
src: ['<%= project.src %>/*.jsx', 'tests/**/*.jsx', 'tests/**/*.html'],
dest: 'tests/functional/css/atomic.css'
}]
}
},
// react
// compiles jsx to js
babel: {
dist: {
options: {
sourceMap: false
},
files: [
{
expand: true,
cwd: '<%= project.src %>',
src: ['**/*.*'],
dest: '<%= project.dist %>/',
extDot: 'last',
ext: '.js'
}
]
},
functional: {
options: {
sourceMap: false
},
files: [
{
expand: true,
src: ['<%= project.functional %>/**/*.jsx'],
extDot: 'last',
ext: '.js'
}
]
},
unit: {
files: [
{
expand: true,
src: [
'<%= project.unit %>/**/*.*'
],
dest: '<%= project.tmp %>',
extDot: 'last',
ext: '.js'
}
]
}
},
// shell
// shell commands to run protractor and istanbul
shell: {
istanbul: {
options: {
execOptions: {
env: env
}
},
command: 'node tests/helpers/rAF.js node_modules/istanbul/lib/cli.js cover --dir <%= project.coverage_dir %> ' +
'-- ./node_modules/mocha/bin/_mocha <%= project.tmp %>/<%= project.unit %> ' +
'--recursive --reporter xunit-file'
},
mocha: {
command: './node_modules/mocha/bin/mocha <%= project.tmp %>/<%= project.unit %> ' +
'--recursive --reporter spec'
}
},
// webpack
// create js rollup with webpack module loader for functional tests
webpack: {
functional: {
entry: './<%= project.functional %>/bootstrap.js',
output: {
path: './<%= project.functional %>/'
},
module: {
loaders: [
{ test: /\.css$/, loader: 'style!css' },
{ test: /\.jsx$/, loader: require.resolve('babel-loader') },
{ test: /\.json$/, loader: 'json-loader'}
]
}
}
},
// connect
// setup server for functional tests
connect: {
functional: {
options: {
port: 9999,
base: ['<%= project.functional %>', '.']
}
},
functionalOpen: {
options: {
port: 9999,
base: ['<%= project.functional %>', '.'],
open: {
target: 'http://127.0.0.1:9999/tests/functional/page.html'
}
}
}
},
watch: {
functional: {
files: [
'<%= project.src%>/*.jsx',
'<%= project.functional%>/*.jsx',
'<%= project.functional%>/*.html'
],
tasks: ['dist', 'functional-debug']
}
},
'saucelabs-mocha': {
all: {
options: {
testname: 'react-i13n func test',
urls: [
'http://127.0.0.1:9999/tests/functional/page.html'
],
build: process.env.TRAVIS_BUILD_NUMBER,
sauceConfig: {
'record-video': true,
'capture-html': false,
'record-screenshots': false
},
throttled: 3,
browsers: [
{
browserName: 'internet explorer',
platform: 'Windows 7',
version: '9'
},
{
browserName: 'internet explorer',
platform: 'Windows 8',
version: '10'
},
{
browserName: 'internet explorer',
platform: 'Windows 8.1',
version: '11'
},
{
browserName: 'chrome',
platform: 'Windows 7',
version: '37'
},
{
browserName: 'firefox',
platform: 'Windows 7',
version: '32'
},
{
browserName: 'iphone',
platform: 'OS X 10.9',
version: '7.1'
},
{
browserName: 'android',
platform: 'Linux',
version: '4.4'
},
{
browserName: 'safari',
platform: 'OS X 10.9',
version: '7'
}
]
}
}
}
});
grunt.loadNpmTasks('grunt-saucelabs');
// register custom tasks
// functional
// 2. run atomizer functional
// 3. compile jsx to js in tests/functional/
// 4. copy files to tests/functional/
// 5. use webpack to create a js bundle to tests/functional/
// 6. get local ip address and available port then store in grunt config
// 7. set up local server to run functional tests
// 9. run protractor
grunt.registerTask('functional', [
'atomizer:functional',
'babel:functional',
'webpack:functional',
'connect:functional',
'saucelabs-mocha',
'clean:functional'
]);
// similar to functional, but don't run protractor, just open the test page
grunt.registerTask('functional-debug', [
'atomizer:functional',
'babel:functional',
'webpack:functional',
'connect:functionalOpen',
'watch:functional'
]);
// cover
// 1. clean tmp/
// 2. compile jsx to js in tmp/
// 3. run istanbul cover in tmp/ using mocha command
// 4. clean tmp/
grunt.registerTask('cover', [
'clean:tmp',
'clean:dist',
'babel:unit',
'babel:dist',
'shell:istanbul',
'clean:tmp'
]);
grunt.registerTask('unit', [
'clean:tmp',
'clean:dist',
'babel:unit',
'babel:dist',
'shell:mocha'
]);
// dist
// 1. clean dist/
// 2. compile jsx to js in dist/
grunt.registerTask('dist', ['clean:dist', 'babel:dist']);
grunt.registerTask('test', ['clean:dist', 'babel:dist', 'clean:tmp', 'babel:unit']);
// default
grunt.registerTask('default', ['dist']);
};