/
e2e.options.port.js
81 lines (69 loc) · 2.37 KB
/
e2e.options.port.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
"use strict";
var browserSync = require("../../../index");
var utils = require("../../../lib/utils");
var assert = require("chai").assert;
var sinon = require("sinon");
describe("E2E `port` option", function () {
it("Calls cb with Error if port detection errors", function (done) {
browserSync.reset();
var config = {
logLevel: "silent",
server: "test/fixtures",
online: false,
open: false
};
sinon.stub(utils, "getPorts").yields(new Error("Some error about a port"));
sinon.stub(utils, "fail", function (override, errMessage, cb) {
assert.instanceOf(errMessage, Error);
utils.getPorts.restore();
utils.fail.restore();
cb();
});
browserSync(config, function () {
done();
});
});
it("sets extra port option for socket in proxy mode", function (done) {
browserSync.reset();
var stub = sinon.stub(utils, "getPort");
stub.onCall(0).yields(null, 3000);
stub.onCall(1).yields(null, 3001);
var config = {
logLevel: "silent",
proxy: "localhost",
online: false,
open: false
};
browserSync(config, function (err, bs) {
bs.cleanup();
assert.equal(bs.options.get("port"), 3000);
assert.equal(stub.getCall(1).args[0], 3001);
assert.equal(bs.options.getIn(["socket", "port"]), 3001);
utils.getPort.restore();
done();
});
});
it("uses user-given extra port option for socket in proxy mode", function (done) {
browserSync.reset();
var stub = sinon.stub(utils, "getPort");
stub.onCall(0).yields(null, 3000);
stub.onCall(1).yields(null, 8001);
var config = {
logLevel: "silent",
proxy: "localhost",
socket: {
port: 8001
},
online: false,
open: false
};
browserSync(config, function (err, bs) {
bs.cleanup();
assert.equal(bs.options.get("port"), 3000);
assert.equal(stub.getCall(1).args[0], 8001);
assert.equal(bs.options.getIn(["socket", "port"]), 8001);
utils.getPort.restore();
done();
});
});
});