-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathspec.js
82 lines (67 loc) · 2.08 KB
/
spec.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
var jasmine = require('jasmine-node/lib/jasmine'),
spawn = require('child_process').spawn,
util = require('util'),
http = require('http'),
sys = require('sys')
for(var key in jasmine)
global[key] = jasmine[key]
global.testReq = function(type, path, body, cb){
var local = http.createClient(9900, 'localhost')
var request = local.request(type, path)
if( typeof body == 'function' )
cb = body
else
request.write(body)
request.on('response', function (response) {
var chunks = []
response
.on('data', function(chunk) {
chunks.push(chunk)
})
.on('end', function(){
cb(response.statusCode, response.headers, chunks.join(''))
})
}).end()
}
var SpecRunner = {
run: function(){
var self = this
spawn('ls', ['-1', __dirname + '/spec']).stdout.on('data', function(res){
if ( process.argv[2] != undefined ) // `node spec.js basic`
self.allSpecs = [process.argv[2]]
else
self.allSpecs = res.toString().split("\n")
SpecRunner.runSpecsFor(self.allSpecs.shift(), self.nextSpec)
})
},
nextSpec: function(){
var spec = SpecRunner.allSpecs.shift()
if ( typeof spec != 'undefined' && spec != '' )
SpecRunner.runSpecsFor(spec, SpecRunner.nextSpec)
},
spawn: function(appName){
var cmd = 'node', ext = 'js'
if ( /coffee/.test(appName) )
ext = cmd = 'coffee'
return spawn(cmd, [__dirname + '/examples/' + appName + '/app' + '.' + ext])
},
runSpecsFor: function(appName, cb){
var app = SpecRunner.spawn(appName)
app.stdout.on('data', function(data){
data = data.toString()
var spec = __dirname + '/spec/' + appName
if ( /Picard boldly goes/.test(data) )
jasmine.executeSpecsInFolder(spec, function(runner, log){
app.kill('SIGHUP')
}, false, true)
else
util.print("\n" + data.replace("\n", '') + " ")
})
app.stderr.on('data', function(data){
sys.puts('fuck!')
sys.puts(data.toString())
})
app.on('exit', cb)
}
}
SpecRunner.run()