Skip to content

Commit

Permalink
Merge branch 'alexturpin'
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Nov 20, 2016
2 parents 42bab46 + 8dd9f01 commit 3aced70
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/internal-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = function (bs) {
var open = bs.options.get("open");

if (mode === "proxy" || mode === "server" || open === "ui" || open === "ui-external") {
utils.openBrowser(data.url, bs.options);
utils.openBrowser(data.url, bs.options, bs);
}

// log about any file watching
Expand Down
6 changes: 6 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ module.exports.callbacks = {
logger.info("{cyan:Reloading Browsers...");
}
},
/**
*
*/
"browser:error": function () {
logger.error("Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the {cyan:open} option to {cyan:false})");
},
/**
* @param {BrowserSync} bs
* @param data
Expand Down
19 changes: 12 additions & 7 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ var utils = {
* Open the page in browser
* @param {String} url
* @param {Object} options
* @param {BrowserSync} bs
*/
openBrowser: function (url, options) {
openBrowser: function (url, options, bs) {

var open = options.get("open");
var browser = options.get("browser");
Expand All @@ -155,22 +156,23 @@ var utils = {
if (browser !== "default") {
if (utils.isList(browser)) {
browser.forEach(function (browser) {
utils.open(url, browser);
utils.open(url, browser, bs);
});
} else {
utils.open(url, browser); // single
utils.open(url, browser, bs); // single
}
} else {
utils.open(url);
utils.open(url, null, bs);
}
}
},
/**
* Wrapper for open module - for easier stubbin'
* Wrapper for opn module
* @param url
* @param name
* @param bs
*/
open: function (url, name) {
open: function (url, name, bs) {
var options = (function () {
if (_.isString(name)) {
return {app: name};
Expand All @@ -180,7 +182,10 @@ var utils = {
}
return {};
})();
require("opn")(url, options);
var opn = require("opn");
opn(url, options).catch(function() {
bs.events.emit("browser:error");
});
},
/**
* @param {Boolean} kill
Expand Down
6 changes: 4 additions & 2 deletions test/specs/e2e/e2e.options.open.browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ describe("E2E browser option with app args", function () {
var stub = sinon.spy(utils, "open");
var opnPath = require.resolve("opn");
require(opnPath);
var opnStub = require("sinon").stub(require.cache[opnPath], "exports");
var opnStub = require("sinon").stub(require.cache[opnPath], "exports")
.returns({catch: function(){}});

browserSync(config, function (err, bs) {
bs.cleanup();
Expand Down Expand Up @@ -126,7 +127,8 @@ describe("E2E browser option with app args", function () {
var stub = sinon.spy(utils, "open");
var opnPath = require.resolve("opn");
require(opnPath);
var opnStub = require("sinon").stub(require.cache[opnPath], "exports");
var opnStub = require("sinon").stub(require.cache[opnPath], "exports")
.returns({catch: function(){}});

browserSync(config, function (err, bs) {
bs.cleanup();
Expand Down
6 changes: 4 additions & 2 deletions test/specs/e2e/e2e.options.open.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ describe("E2E OPEN options with external", function () {
stub = sinon.spy(utils, "open");
opnPath = require.resolve("opn");
require(opnPath);
opnStub = require("sinon").stub(require.cache[opnPath], "exports");
opnStub = require("sinon").stub(require.cache[opnPath], "exports")
.returns({catch: function(){}});
bs = browserSync(config, done).instance;
});

Expand Down Expand Up @@ -81,7 +82,8 @@ describe("E2E OPEN options with UI + snippet", function () {
stub = sinon.spy(utils, "open");
opnPath = require.resolve("opn");
require(opnPath);
opnStub = require("sinon").stub(require.cache[opnPath], "exports");
opnStub = require("sinon").stub(require.cache[opnPath], "exports")
.returns({catch: function(){}});
bs = browserSync(config, done).instance;
});

Expand Down

0 comments on commit 3aced70

Please sign in to comment.