Skip to content

Commit d033358

Browse files
committed
fix(open): Allow open: 'ui' and open: 'ui-external' when in snippet mode - fixes #571
1 parent 6a2609f commit d033358

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

lib/internal-events.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ module.exports = function (bs) {
3838
*/
3939
"service:running": function (data) {
4040

41-
if (data.type !== "snippet") {
41+
var mode = bs.options.get("mode");
42+
var open = bs.options.get("open");
43+
44+
if (mode === "proxy" || mode === "server" || open === "ui" || open === "ui-external") {
4245
utils.openBrowser(data.url, bs.options);
4346
}
4447

lib/options.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,30 @@ module.exports.update = function (options) {
1919
setNamespace(item);
2020
fixSnippetOptions(item);
2121
setMiddleware(item);
22+
setOpen(item);
2223

2324
if (item.get("files") === false) {
2425
item.set("files", Immutable.List([]));
2526
}
2627

27-
if (!item.get("server") && !item.get("proxy")) {
28-
item.set("open", false);
29-
}
30-
3128
if (item.get("uiPort")) {
3229
item.setIn(["ui", "port"], item.get("uiPort"));
3330
}
3431
});
3532
};
3633

34+
/**
35+
* @param item
36+
*/
37+
function setOpen (item) {
38+
var open = item.get("open");
39+
if (item.get("mode") === "snippet") {
40+
if (open !== "ui" && open !== "ui-external") {
41+
item.set("open", false);
42+
}
43+
}
44+
}
45+
3746
/**
3847
* Set the running mode
3948
* @param item

test/specs/e2e/e2e.options.open.js

+31
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,34 @@ describe("E2E OPEN options with external", function () {
6464
require.cache[opnPath].exports.restore();
6565
});
6666
});
67+
68+
describe("E2E OPEN options with UI + snippet", function () {
69+
70+
var bs;
71+
var stub;
72+
var opnPath;
73+
var opnStub;
74+
75+
before(function (done) {
76+
browserSync.reset();
77+
var config = {
78+
logLevel: "silent",
79+
open: "ui"
80+
};
81+
stub = sinon.spy(utils, "open");
82+
opnPath = require.resolve("opn");
83+
require(opnPath);
84+
opnStub = require("sinon").stub(require.cache[opnPath], "exports");
85+
bs = browserSync(config, done).instance;
86+
});
87+
88+
after(function () {
89+
bs.cleanup();
90+
stub.restore();
91+
});
92+
93+
it("Opens the external address when specified in options", function () {
94+
sinon.assert.calledWith(opnStub, bs.options.getIn(["urls", "ui"]));
95+
require.cache[opnPath].exports.restore();
96+
});
97+
});

0 commit comments

Comments
 (0)