forked from ruipgil/scraperjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
97 lines (87 loc) · 2.69 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
var testServer = require('./test/setupServer');
var MOCHA_TIMEOUT_S = 10,
MOCHA_TIMEOUT_MS = MOCHA_TIMEOUT_S * 1000,
MOCHA_OPTIONS = {
reporter: 'spec',
timeout: MOCHA_TIMEOUT_MS
},
COVERAGE_THRESHOLD = 95;
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-exec');
grunt.initConfig({
exec: {
coverage: {
command: 'istanbul cover ./node_modules/mocha/bin/_mocha -- -t ' + MOCHA_TIMEOUT_MS + ' --root src/ test/'
},
coveralls: {
command: 'istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -t ' + MOCHA_TIMEOUT_MS + ' --root src/ test/ && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js'
},
'check-coverage': {
command: 'istanbul check-coverage --lines ' + COVERAGE_THRESHOLD + ' --statements ' + COVERAGE_THRESHOLD + ' --functions ' + COVERAGE_THRESHOLD + ' --branches ' + COVERAGE_THRESHOLD + ' ./coverage/coverage.json'
}
},
clean: {
coverage: {
src: ['coverage/']
}
},
watch: {
common: {
files: ['src/**/*.js', 'test/**/*.js', 'Gruntfile.js'],
tasks: ['test']
}
},
jshint: {
all: ['src/**/*.js', 'test/**/*.js']
},
mochaTest: {
abstractScraper: {
src: 'test/AbstractScraper.js',
options: MOCHA_OPTIONS
},
staticScraper: {
src: 'test/StaticScraper.js',
options: MOCHA_OPTIONS
},
dynamicScraper: {
src: 'test/DynamicScraper.js',
options: MOCHA_OPTIONS
},
scraperPromise: {
src: 'test/ScraperPromise.js',
options: MOCHA_OPTIONS
},
router: {
src: 'test/Router.js',
options: MOCHA_OPTIONS
},
scraperError: {
src: 'test/ScraperError.js',
options: MOCHA_OPTIONS
},
all: {
src: ['test/AbstractScraper.js', 'test/StaticScraper.js', 'test/DynamicScraper.js', 'test/ScraperPromise.js', 'test/Router.js', 'test/ScraperError.js'],
options: MOCHA_OPTIONS
}
}
});
var server;
grunt.registerTask('serve', 'Starts express testing server', function() {
server = testServer(grunt);
});
grunt.registerTask('unserve', function() {
if (server) {
server.close();
}
});
grunt.registerTask('serve-and-test', ['serve', 'mochaTest:all', 'unserve']);
grunt.registerTask('coverage', ['clean', 'jshint', 'serve', 'exec:coverage', 'exec:check-coverage', 'unserve']);
grunt.registerTask('coveralls', ['clean', 'jshint', 'serve', 'exec:coveralls', 'exec:check-coverage', 'unserve']);
grunt.registerTask('unit', ['jshint', 'serve-and-test']);
grunt.registerTask('test', ['coverage']);
grunt.registerTask('watch-all', ['serve', 'watch', 'unserve']);
};