-
Notifications
You must be signed in to change notification settings - Fork 28
/
detect-port.test.js
91 lines (80 loc) · 1.99 KB
/
detect-port.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
85
86
87
88
89
90
91
/* ================================================================
* detect-port by xdf(xudafeng[at]126.com)
*
* first created at : Tue Mar 17 2015 00:16:10 GMT+0800 (CST)
*
* ================================================================
* Copyright xdf
*
* Licensed under the MIT License
* You may not use this file except in compliance with the License.
*
* ================================================================ */
'use strict';
const detectPort = require('..');
describe('detect port test', () => {
it('callback with occupied port', done => {
const _port = 80;
detectPort(_port, (err, port) => {
if (err) {
console.log(err);
}
port.should.within(_port, 65535);
done();
});
});
it('callback with string arg', done => {
const _port = '8080';
detectPort(_port, (err, port) => {
if (err) {
console.log(err);
}
port.should.within(parseInt(_port, 10), 65535);
done();
});
});
it('callback with wrong arguments', done => {
detectPort('oooo', err => {
err.should.containEql('wrong type of arguments');
done();
});
});
it('generator usage', function *() {
const _port = 8080;
try {
const port = yield detectPort(_port);
port.should.within(_port, 65535);
} catch (err) {
console.log(err);
}
});
it('promise usage', done => {
const _port = 8080;
detectPort(_port)
.then(port => {
port.should.within(_port, 65535);
done();
})
.catch(err => {
console.log(err);
done();
});
});
it('promise with wrong arguments', done => {
detectPort()
.then(() => {
done();
})
.catch(err => {
err.should.containEql('wrong number of arguments');
done();
});
});
it('generator with wrong arguments', function *() {
try {
yield detectPort('oooo');
} catch (err) {
err.should.containEql('wrong type of arguments');
}
});
});