Skip to content

Commit

Permalink
Allow custom ports when usinge Sauce or remote grid
Browse files Browse the repository at this point in the history
Fixes jasmine#48.
  • Loading branch information
sgravrock committed Mar 2, 2024
1 parent 31fddf4 commit 58e60e4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ exception of the `url` will be used as `capabilties` sent to the grid hub url.
if no value is specified for the `url` then a default of
`http://localhost:4445/wd/hub` is used.

It's common for remote grids to support only a limited set of ports. Check your
remote grid's documentation to make sure that the port you're using is
supported. When using a remote grid, `jasmine-browser-runner` will run on port
5555 unless you use the `--port` command line option or specify a port in the
second parameter to`startServer`.

## Want more control?

```javascript
Expand Down
12 changes: 3 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,10 @@ module.exports = {
const useRemote = options.browser && options.browser.useRemoteSeleniumGrid;
let portRequest;

if (useSauce || useRemote) {
if (options.port) {
throw new Error(
"Can't specify a port when browser.useSauce or browser.useRemoteSeleniumGrid is true"
);
}

portRequest = 5555;
} else if (options.port) {
if (options.port) {
portRequest = options.port;
} else if (useSauce || useRemote) {
portRequest = 5555;
} else {
portRequest = 0;
}
Expand Down
43 changes: 37 additions & 6 deletions spec/indexSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('index', function() {
};
});

describe('When not using Sauce Connect', function() {
describe('When not using Sauce Connect or remote grid', function() {
it('uses the specified port', async function() {
const promise = runSpecs({ port: 12345 }, this.deps);
await this.waitForServerStart(promise);
Expand All @@ -51,6 +51,38 @@ describe('index', function() {
});
});

describe('When using remote grid', function() {
it('uses port 5555', async function() {
const promise = runSpecs(
{
browser: {
useRemoteSeleniumGrid: true,
},
},
this.deps
);
await this.waitForServerStart(promise);

expect(this.server.start).toHaveBeenCalledWith({ port: 5555 });
});

it('uses the specified port', async function() {
spyOn(console, 'warn');
const promise = runSpecs(
{
browser: {
useRemoteSeleniumGrid: true,
},
port: 1234,
},
this.deps
);
await this.waitForServerStart(promise);

expect(this.server.start).toHaveBeenCalledWith({ port: 1234 });
});
});

describe('When using Sauce Connect', function() {
it('uses port 5555', async function() {
const promise = runSpecs(
Expand All @@ -66,7 +98,8 @@ describe('index', function() {
expect(this.server.start).toHaveBeenCalledWith({ port: 5555 });
});

it('throws if a port is specified', async function() {
it('uses the specified port', async function() {
spyOn(console, 'warn');
const promise = runSpecs(
{
browser: {
Expand All @@ -76,11 +109,9 @@ describe('index', function() {
},
this.deps
);
await this.waitForServerStart(promise);

await expectAsync(promise).toBeRejectedWithError(
"Can't specify a port when browser.useSauce or browser.useRemoteSeleniumGrid is true"
);
expect(this.server.start).not.toHaveBeenCalled();
expect(this.server.start).toHaveBeenCalledWith({ port: 1234 });
});
});
});
Expand Down

0 comments on commit 58e60e4

Please sign in to comment.