-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_server.js
61 lines (57 loc) · 1.38 KB
/
test_server.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
var jsc = require('jscoverage');
require = jsc.require(module);
var LS = require('./index',true);
var http = require('http');
var expect = require('expect.js');
process.on('exit',jsc.coverage);
// case start
var config = {
port:54321,
root:__dirname
}
var serv = LS.createServer(config);
// load controller
serv.router({
'/test' : function(req,res,config){
res.json(req.getRouter());
},
'/':function(req,res,config){
res.json({path:req.url});
}
}).start(function(){
log.info('server start');
});
describe('SERVER TEST',function(){
describe("req functions",function(){
it('#getRouter',function(done){
var opt = {
host: 'localhost',
port: '54321',
path : '/test/act/1/2/3'
};
http.get(opt,function(res){
res.getPost(function(data){
var res = JSON.parse(data.toString());
expect(res.controller).to.be('test');
expect(res.action).to.be('act');
expect(res.param.length).to.be(3);
done();
},true)
});
});
it('#router dispatch',function(done){
var opt = {
host: 'localhost',
port: '54321',
path : '/'
};
http.get(opt,function(res){
res.getPost(function(data){
var res = JSON.parse(data.toString());
expect(res.path).to.be('/');
done();
},true);
});
});
});
});