-
Notifications
You must be signed in to change notification settings - Fork 1
/
collection.coffee
177 lines (144 loc) · 5.49 KB
/
collection.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
path= require 'path'
fs= require 'fs'
childProcess= require 'child_process'
EventEmitter= require('events').EventEmitter
Jasmine= require 'jasmine'
Reporter= require 'jasmine-terminal-reporter'
wanderer= require 'wanderer'
class Collection extends require './utility'
runJasmine: (specs,options={})->
runner= new EventEmitter
jasmine= new Jasmine
jasmine.addReporter new Reporter
showColors: true
isVerbose: options.verbose
includeStackTrace: options.stacktrace
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL= options.timeout
code= 0
wanderer.seek specs
.on 'data',(file)=>
filename= path.resolve process.cwd(),file
@deleteRequireCache require.resolve filename
jasmine.addSpecFile filename
.once 'end',->
code= 1 if jasmine.specFiles.length is 0
try
jasmine.execute()
catch error
console.error error?.stack?.toString() ? error?.message ? error
code= 1
jasmine.addReporter
specDone: (result)->
code= 1 if result.status is 'failed'
jasmineDone: ->
runner.emit 'close',code
runner
coverJasmine: (specs,options={})->
args= []
args.push 'node'
args.push require.resolve 'ibrik/bin/ibrik'
args.push 'cover'
args.push require.resolve '../jasminetea'
args.push '--'
args= args.concat process.argv[2...]
args.push '-C'
@log '$',args.join ' ' if options.debug?
[script,args...]= args
childProcess.spawn script,args,{stdio:'inherit',cwd:process.cwd(),env:process.env}
runProtractor: (specs,options={})->
runner= new EventEmitter
exitCode= 0
@webdriverUpdate(options).once 'close',=>
protractor= @protractor specs,options
protractor.stdout.on 'data',(buffer)->
# fix #1
exitCode= 1 if buffer.toString().match /Process exited with error code 1\n$/g
process.stdout.write buffer.toString()
protractor.stderr.on 'data',(buffer)->
process.stderr.write buffer.toString()
protractor.on 'error',(stack)->
console.error error?.stack?.toString() ? error?.message ? error
runner.emit 'close',1
protractor.once 'exit',(code)->
exitCode= 1 if code isnt 0
runner.emit 'close',exitCode
runner
protractor: (specs,options={})->
args= []
args.push 'node'
args.push require.resolve 'protractor/bin/protractor'
args.push require.resolve '../jasminetea' # module.exprots.config
if typeof options.e2e is 'string'
args.push argv for argv in options.e2e.replace(new RegExp('==','g'),'--').split /\s/
args.push '--specs'
args.push wanderer.seekSync(specs).join ','
# @log 'Arguments has been ignored',(chalk.underline(arg) for arg in options.args[1...]).join ' '
@log '$',args.join ' ' if options.debug?
[script,args...]= args
childProcess.spawn script,args,env:process.env
coverProtractor: (specs,options={})->
runner= new EventEmitter
@webdriverUpdate(options).once 'close',=>
args= []
args.push 'node'
args.push require.resolve 'ibrik/bin/ibrik'
args.push 'cover'
args.push require.resolve 'protractor/bin/protractor'
args.push '--'
args.push require.resolve '../jasminetea'# Use Jasminetea.config
args.push '--specs'
args.push wanderer.seekSync(specs).join ','
if typeof options.e2e is 'string'
args.push argv for argv in options.e2e.replace(new RegExp('==','g'),'--').split /\s/
@log '$',args.join ' ' if options.debug?
[script,args...]= args
child= childProcess.spawn script,args,{stdio:'inherit',cwd:process.cwd(),env:process.env}
child.on 'exit',(code)->
runner.emit 'close',code
runner
webdriverUpdate: (options={})->
args= []
args.push 'node'
args.push require.resolve 'protractor/bin/webdriver-manager'
args.push 'update'
args.push '--standalone'
@log '$',args.join ' ' if options.debug?
[script,args...]= args
childProcess.spawn script,args,stdio:'inherit'
deleteRequireCache: (id)=>
return if id.indexOf('node_modules') > -1
files= require.cache[id]
if files?
@deleteRequireCache file.id for file in files.children
delete require.cache[id]
report: (options={})->
exists_token= fs.existsSync path.join process.cwd(),'.coveralls.yml'
exists_token= process.env.COVERALLS_REPO_TOKEN? if not exists_token
if not exists_token
@log 'Skip post a coverage report. Cause not exists COVERALLS_REPO_TOKEN'
return @noop()
exists_coverage= fs.existsSync path.join process.cwd(),'coverage','lcov.info'
if not exists_coverage
@log 'Skip post a coverage report. Cause not exists ./coverage/lcov.info'
return @noop()
args= []
args.push 'cat'
args.push path.join process.cwd(),'coverage','lcov.info'
args.push '|'
args.push require.resolve 'coveralls/bin/coveralls.js'
@log '$',args.join ' ' if options.debug?
options=
cwd: process.cwd()
env: process.env
maxBuffer: 1000*1024
childProcess.exec args.join(' '),options,(error)=>
throw error if error?
@log 'Posted a coverage report.'
lint: (options={})->
args= [require.resolve 'coffeelint/bin/coffeelint']
args.push path.relative process.cwd(),file for file in wanderer.seekSync options.lint
@log '$',args.join ' ' if options.debug?
console.log ''
@log 'Lint by',options.lint.join(' or '),'...'
childProcess.spawn 'node',args,{stdio:'inherit',cwd:process.cwd()}
module.exports= Collection