browserstack/browserstack-local-nodejs

Throws no error and does not start with proxy enabled

Closed this issue · 5 comments

When trying to start the app (see example below) with proxyHost and proxyPort it will fail. If I add the folder it never starts but also does not fail (no error message given).

Expected Behavior

That it would load correctly without an error or some kind of error in return when specifying f (folder).

Actual Behavior

If I add proxyHost and proxyPort

  const bs_local_args = {
    key: "***",
    localIdentifier: "testing",

    // Never proceeds with the following settings:
    proxyHost: "localhost",
    proxyPort: PORT,

    // If I omit the folder with the proxy settings it returns "LocalError: No output received"
    // f: "/Users/adriaan/folder"
  };
It fails with LocalError: No output received
Started node server
Error: LocalError: No output received
    at /Users/adriaan/node_modules/browserstack-local/lib/Local.js:62:20
    at ChildProcess.exithandler (child_process.js:286:7)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) {
  name: 'LocalError',
  message: 'No output received',
  extra: undefined
}
/Users/adriaan/node_modules/browserstack-local/lib/Local.js:65
          callback(new LocalError(data['message']['message']));
                                                 ^

TypeError: Cannot read property 'message' of undefined
    at /Users/adriaan/node_modules/browserstack-local/lib/Local.js:65:50
    at ChildProcess.exithandler (child_process.js:286:7)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

If I uncommend the folder line, it will not start without any error.

Platform details

  1. browserstack-local-nodejs version: 1.4.5
  2. node version: 12.14.0
  3. os type and version: mac os x Catalina

Details

This is a minimal version of the bug:

const browserstack = require("browserstack-local");
const url = require("url");
const http = require("http");
const PORT = 8080;

(async () => {
  http
    .createServer(req => {
      const { pathname } = url.parse(req.url);
      console.log("Request:", pathname);
    })
    .listen(PORT, () => {
      console.log("Started node server");
    });

  const bs_local = new browserstack.Local();

  const bs_local_args = {
    key: "***",
    localIdentifier: "testing",
    forceLocal: "true",

    // Never proceeds with the following settings:
    proxyHost: "localhost",
    proxyPort: PORT,

    // If I omit the folder with the proxy settings it returns "LocalError: No output received"
    // f: "/Users/adriaan/folder"
  };

  bs_local.start(bs_local_args, function(error) {
    if (error) return console.error("Error:", error);
    console.log("Running BrowserStackLocal", bs_local.isRunning());
    bs_local.stop(function() {
      console.log("Stopped BrowserStackLocal");
    });
  });
})();

Hi @adriaanvanrossum,

could you try to updating bs_local_args with

const bs_local_args = {
    key: "***",
    localIdentifier: "testing",
    forceLocal: "true",

    // update here
    'local-proxy-host': "localhost",
    'local-proxy-port': PORT,

    f: "/Users/adriaan/folder"
  };

This indeed works! Thanks a lot.

If I create a PR for README.md with above new params, will it be merged?

Feel free to create a PR for the same