-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGruntfile.js
150 lines (132 loc) · 4.61 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
var path = require('path');
module.exports = function(grunt) {
var TEST_RUNNER = path.join(process.cwd(), 'test', 'test_runner');
var UNIT_TESTS = 'test/unit/**/*_test.js';
var INTEGRATION_TESTS = 'test/integration/**/*_test.js';
// NPM tasks, alphabetical
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-docco');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.initConfig({
// Clean
clean: {
docs: ['docs'],
coverage: ['test/coverage.html']
},
// Concat
concat: {
angular: {
src: ['lib/index.js', 'lib/http_adapter/angular.js', 'lib/wrappers/angular.js'],
dest: 'api-angular.js',
options: {
footer: 'TaggedApi.angularWrapper(angular, TaggedApi);'
}
},
vanilla: {
src: [
'lib/index.js',
'lib/http_adapter/vanilla.js'
],
dest: 'api-client.js'
}
},
// Documentation
docco: {
main: {
src: ['lib/**/*.js'],
options: {
output: 'docs/'
}
}
},
// Server-side mocha tests
mochaTest: {
// Runs all tests
unit: {
options: {
require: TEST_RUNNER,
reporter: 'spec',
ui: 'bdd',
timeout: 200,
recursive: true,
clearRequireCache: true
},
src: [UNIT_TESTS]
},
integration: {
options: {
require: TEST_RUNNER,
reporter: 'spec',
ui: 'bdd',
timeout: 10000, // Allow up to 10s for integration tests to fail
slow: 100, // Mark tests as slow if they take longer than 0.1s
recursive: true,
clearRequireCache: true
},
src: [INTEGRATION_TESTS]
},
// Instruments code for reporting test coverage
instrument: {
options: {
require: TEST_RUNNER,
reporter: 'spec',
ui: 'bdd',
timeout: 200,
recursive: true
},
src: [UNIT_TESTS]
},
// Reports test coverage
coverage: {
options: {
require: TEST_RUNNER,
reporter: 'html-cov',
ui: 'bdd',
timeout: 200,
recursive: true,
quiet: true,
captureFile: 'test/coverage.html'
},
src: [UNIT_TESTS]
}
},
uglify: {
angular: {
files: {
'api-angular-min.js': ['api-angular.js'],
'api-client-min.js': ['api-client.js']
}
}
},
// Watches filesystem for changes to run tasks automatically
watch: {
unit: {
options: {
spawn: false
},
files: [
'lib/**/*.js',
'test/**/*.js'
],
tasks: ['mochaTest:unit']
}
}
});
// Runs all tests
grunt.registerTask('test', 'Runs all unit and integration tests', ['mochaTest:unit', 'mochaTest:integration']);
// Runs all unit tests
grunt.registerTask('unit', 'Runs all unit tests', ['mochaTest:unit']);
// Runs all integration tests
grunt.registerTask('integration', 'Runs all integration tests', ['mochaTest:integration']);
// Generates test coverage report
grunt.registerTask('coverage', 'Generates unit test code coverage', ['clean:coverage', 'mochaTest:instrument', 'mochaTest:coverage']);
// Generates documentation
grunt.registerTask('docs', 'Generates documentation', ['clean:docs', 'docco:main']);
// Dev mode
grunt.registerTask('dev', 'Enables watchers for developing', ['watch:unit']);
// Build concatenated/minified version for browsers
grunt.registerTask('build', 'Builds concatenated/minified versions for browsers', ['concat', 'uglify']);
};