-
Notifications
You must be signed in to change notification settings - Fork 45
/
Gruntfile.js
executable file
·145 lines (129 loc) · 4.58 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
module.exports = function(grunt) {
'use strict';
var testMiddlewares = require('./test/server/middlewares.js');
var coverageDir = '.coverage';
//load npm tasks
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
eslint : {
dist : ['src/aja.js']
},
//mocha but from grunt-mocha-phantom-istanbul
mocha: {
options: {
urls: [
'http://localhost:9901/test/properties/index.html',
'http://localhost:9901/test/methods/index.html',
'http://localhost:9901/test/integration/index.html'
],
reporter: 'Spec',
run: true,
timeout: 10000
},
browser: {},
browsercov: {
options: {
coverage: {
coverageFile: coverageDir + '/data.json'
}
}
}
},
connect: {
test: {
options: {
hostname: 'localhost',
port: 9901,
base: '.',
middleware: function(connect, options, middlewares) {
return [connect.json(), connect.urlencoded()]
.concat(testMiddlewares)
.concat(middlewares);
},
}
},
testcov: {
options: {
hostname: 'localhost',
port: 9901,
base: '.',
middleware: function(connect, options, middlewares) {
//to serve instrumented code to the tests runners
var instrumentMiddleware = function(req, res, next) {
if (/aja\.js$/.test(req.url)) {
return res.end(grunt.file.read(coverageDir + '/instrument/src/aja.js'));
}
return next();
};
return [connect.json(), connect.urlencoded(), instrumentMiddleware]
.concat(testMiddlewares)
.concat(middlewares);
},
}
}
},
watch: {
test: {
files: '**/*.js',
tasks: ['mocha:browser'],
options: {
debounceDelay: 2000,
}
}
},
instrument: {
files: 'src/aja.js',
options: {
lazy: true,
basePath: '.coverage/instrument/'
}
},
makeReport: {
src: '.coverage/data.json',
options: {
type: 'html',
dir: '.coverage/reports',
},
},
uglify: {
dev: {
files: {
'src/aja.min.js': ['src/aja.js']
},
options: {
banner: "/**\n * <%= pkg.name %> <%= pkg.homepage %>\n * \n * @version <=%pkg.version%>\n * @author <%= pkg.author.name %> <<%= pkg.author.email %>> © <%= grunt.template.today('yyyy') %>\n * @license MIT\n**/",
sourceMap: true,
beautify: {
'max_line_len': 500
}
}
},
prod: {
files: {
'aja.min.js': ['src/aja.js']
}
}
},
jsdoc: {
dist: {
src: ['src/*.js', 'README.md'],
options: {
destination: 'doc',
private: false,
template: "node_modules/grunt-jsdoc/node_modules/ink-docstrap/template",
configure: "node_modules/grunt-jsdoc/node_modules/ink-docstrap/template/jsdoc.conf.json"
}
}
}
});
//run tests while developping
grunt.registerTask('devtest', ['connect:test', 'watch:test']);
//run just the tests
grunt.registerTask('test', ['eslint', 'connect:test', 'mocha:browser']);
//run the tests with code coverage
grunt.registerTask('testcov', ['connect:testcov', 'instrument', 'mocha:browsercov', 'makeReport']);
//build the package
grunt.registerTask('build', ['jsdoc:dist', 'uglify:dev', 'uglify:prod']);
};