-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
84 lines (69 loc) · 2.23 KB
/
test.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
83
84
'use strict';
var EventEmitter = require('events').EventEmitter
, File = require('bigpipe/lib/file')
, BigPipe = require('bigpipe')
, assume = require('assume')
, http = require('http')
, domain = require('./')
, bigpipe, file, options;
describe('BigPipe - Plugin domain', function () {
describe('is module', function () {
it('which exports name domain', function () {
assume(domain.name).to.be.a('string');
assume(domain.name).to.equal('domain');
});
it('which exports server side plugin', function () {
assume(domain.server).to.be.a('function');
assume(domain.server.length).to.equal(2);
});
});
describe('server side plugin', function () {
beforeEach(function () {
options = function get() {
return {
hostname: 'localhost',
protocol: 'http',
pathname: '/test',
port: 8080
};
};
file = new File;
bigpipe = new BigPipe;
});
afterEach(function () {
file = bigpipe = null;
});
it('waits for register event', function (done) {
domain.server(bigpipe, options);
assume(bigpipe._compiler._events).to.have.property('register');
bigpipe._compiler.emit('register', file, done);
});
it('supports pathname configurations', function (done) {
var location = file.location;
options = function get() {
return '/test';
};
domain.server(bigpipe, options);
bigpipe._compiler.emit('register', file, function () {
assume(bigpipe._compiler.buffer).to.have.property('/test'+ location);
assume(bigpipe._compiler.buffer['/test'+ location]).to.equal(file);
done();
});
});
it('exposes the compiled core library under the same domain', function (done) {
this.timeout(3E4);
bigpipe = BigPipe.createServer({
plugins: [ domain ],
domain: options(),
listen: false
});
bigpipe.listen(8080, function () {
assume(bigpipe._compiler.buffer).to.have.property('/test/bigpipe.js');
http.get('http://localhost:8080/test/bigpipe.js', function(res) {
assume(res.statusCode).to.equal(200);
done();
}).on('error', done);
});
});
});
});