This repository has been archived by the owner on Mar 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gruntfile.coffee
72 lines (62 loc) · 2.02 KB
/
Gruntfile.coffee
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
module.exports = (grunt) ->
# Project configuration.
grunt.initConfig
pkg: grunt.file.readJSON "package.json"
coffeelint:
app: [
"*.coffee"
"test/**/*.coffee"
]
options:
no_trailing_whitespace:
level: "ignore"
max_line_length:
value: 140
indentation:
value: 2
level: "error"
no_unnecessary_fat_arrows:
level: 'ignore'
mochaTest:
test:
options:
timeout: 30000
reporter: "spec"
require: ['coffee-errors'] #needed for right line numbers in errors
src: ["test/raspbee-test.coffee"]
# blanket is used to record coverage
testBlanket:
options:
reporter: "dot"
src: ["test/*"]
coverage:
options:
reporter: "html-cov"
quiet: true
captureFile: "coverage.html"
src: ["test/*"]
grunt.loadNpmTasks "grunt-coffeelint"
grunt.loadNpmTasks "grunt-mocha-test"
grunt.registerTask "blanket", ->
blanket = require "blanket"
blanket(
pattern: (file) ->
withoutPrefix = file.replace(/.*\/node_modules\/pimatic/, "")
return (not withoutPrefix.match 'node_modules') and (not withoutPrefix.match "/test/")
loader: "./node-loaders/coffee-script"
)
grunt.registerTask "clean-coverage", ->
fs = require "fs"
path = require "path"
replaceAll = (find, replace, str) ->
escapeRegExp = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")
str.replace(new RegExp(escapeRegExp(find), 'g'), replace)
file = "#{__dirname}/coverage.html"
html = fs.readFileSync(file).toString()
html = replaceAll path.dirname(__dirname), "", html
fs.writeFileSync file, html
# Default task(s).
grunt.registerTask "default", ["coffeelint", "mochaTest:test"]
grunt.registerTask "test", ["coffeelint", "mochaTest:test"]
grunt.registerTask "coverage",
["blanket", "mochaTest:testBlanket", "mochaTest:coverage", "clean-coverage"]