This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathpool.test.js
More file actions
88 lines (78 loc) · 2.6 KB
/
Copy pathpool.test.js
File metadata and controls
88 lines (78 loc) · 2.6 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
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
'use strict';
var sinon = require('sinon'),
assert = require('chai').assert,
q = require('q'),
Browser = require('../lib/browser'),
Pool = require('../lib/browser-pool/pool');
describe('UnlimitedPool', function() {
beforeEach(function() {
this.config = {
browsers: {
id: {browserName: 'id'}
}
};
this.sinon = sinon.sandbox.create();
this.browser = sinon.stub(new Browser(this.config, 'id'));
this.browser.launch.returns(q());
this.browser.quit.returns(q());
this.sinon.stub(Browser.prototype, '__constructor')
.returns(this.browser);
this.pool = new Pool(this.config);
this.requestBrowser = function() {
return this.pool.getBrowser('id');
};
});
afterEach(function() {
this.sinon.restore();
});
it('should create new browser when requested', function() {
var _this = this;
return this.requestBrowser()
.then(function() {
assert.calledWith(Browser.prototype.__constructor, _this.config, 'id');
});
});
it('should launch a browser', function() {
var _this = this;
return this.requestBrowser()
.then(function() {
assert.calledOnce(_this.browser.launch);
});
});
it('should quit a browser when freed', function() {
var _this = this;
return this.requestBrowser()
.then(function(browser) {
return _this.pool.freeBrowser(browser);
})
.then(function() {
assert.calledOnce(_this.browser.quit);
});
});
// SIGHUP, SIGINT and SIGTERM are handled in the same way
// so we will test only one of them
describe('on signal', function() {
var defer;
beforeEach(function() {
defer = q.defer();
this.sinon.stub(process, 'exit', defer.resolve.bind(defer));
});
it('should quit a browser on SIGHUP', function() {
var _this = this;
return this.requestBrowser()
.then(function() {
process.emit('SIGHUP');
})
.then(function() {
assert.calledOnce(_this.browser.quit);
});
});
it('should exit on SIGHUP', function() {
return this.requestBrowser()
.then(function() {
process.emit('SIGHUP');
return assert.becomes(defer.promise, 128 + 1);
});
});
});
});