forked from John-Lin/ci
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
57 lines (48 loc) · 1.62 KB
/
test.js
File metadata and controls
57 lines (48 loc) · 1.62 KB
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
var fs = require('fs')
var data = require('./emoji.json')
var whitelist = require('./whitelist_files.json')
var allfiles = fs.list('.')
var buildFailed = false
var passed = function() { console.log("\x1B[92mPASSED\x1B[0m\n") }
var failed = function() {
console.log("\x1B[91mFAILED\x1B[0m\n")
buildFailed = true
}
console.log("\nTEST: all files")
console.log("- Every file other than the white listed ones should be .md files")
var invalidfiles = allfiles.filter(function(filename) { return !filename.match(/\.md$/) && whitelist.indexOf(filename) < 0 })
if( invalidfiles.length > 0 ) {
console.log(" Invalid - " + invalidfiles.join(", "))
failed()
} else {
passed()
}
var mdfiles = allfiles.filter(function(filename) { return filename.match(/\.md$/) && filename !== 'README.md' })
mdfiles.forEach(function(filename) {
var content = fs.read(filename).replace(/\s|<br>/gi, '')
console.log("TEST: " + filename + "\n")
var emoji = content.match(/\:\w+\:/g)
//
console.log("- Contains emoji codes & line breaks only")
if( emoji.join('').length == content.length ) {
passed()
} else {
failed()
}
//
console.log("- Emoji codes are valid")
var invalidemoji = emoji.filter(function(code){ return data.indexOf(code) < 0 })
if( invalidemoji.length == 0 ) {
passed()
} else {
console.log(" Invalid - " + invalidemoji.join(", "))
failed()
}
})
if(buildFailed) {
console.log(":cry: \x1B[91mNo good, something failed.\x1B[0m :boom:\n")
phantom.exit(buildFailed)
} else {
console.log(":sparkles: \x1B[96mWho's awesome? You're awesome!\x1B[0m :+1:\n")
phantom.exit()
}