Skip to content

Commit

Permalink
Don't overwrite rest-url flag (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrique Gonzalez authored Jul 3, 2020
1 parent 50c2fd9 commit c0af3d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ export default class SauceLabs {
*/
.filter(([k]) => !k.match(/[A-Z]/g))
.map(([k, v]) => `--${k}=${v}`)

args.push(`--user=${this.username}`)
args.push(`--api-key=${this._accessKey}`)
args.push(`--rest-url=${restUrl}`)

if (!args.some(arg => arg.startsWith("--rest-url"))) {
args.push(`--rest-url=${restUrl}`)
}

const bin = SAUCE_CONNECT_DISTS.reduce((bin, [downloadUrl, ...args]) => {
bin.src(util.format(downloadUrl, sauceConnectVersion), ...args)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function getAPIHost (servers, basePath, options) {
* allows to set an arbitrary host (for internal use only)
*/
const apiUrl = options.host || servers[0].url
let host = DEFAULT_PROTOCOL + path.join(apiUrl.replace(DEFAULT_PROTOCOL, ''), basePath)
let host = DEFAULT_PROTOCOL + apiUrl.replace(DEFAULT_PROTOCOL, '') + basePath

/**
* allow short region handles to stay backwards compatible
Expand Down
14 changes: 14 additions & 0 deletions tests/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`startSauceConnect should not overwrite rest-url if given as a parameter 1`] = `
Array [
Array [
"/foo/bar",
Array [
"--tunnel-identifier=my-tunnel",
"--rest-url=https://us1.api.testobject.com/sc/rest/v1",
"--user=foo",
"--api-key=bar",
],
],
]
`;

exports[`startSauceConnect should start sauce connect with proper parsed args 1`] = `
Array [
Array [
Expand Down
10 changes: 10 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ describe('startSauceConnect', () => {
const res = await api.startSauceConnect({ tunnelIdentifier: 'my-tunnel' }).catch((err) => err)
expect(res).toEqual(new Error('Uuups'))
})

it('should not overwrite rest-url if given as a parameter', async () => {
const api = new SauceLabs({ user: 'foo', key: 'bar'})
setTimeout(() => stdoutEmitter.emit('data', 'Sauce Connect is up, you may start your tests'), 50)
await api.startSauceConnect({
tunnelIdentifier: 'my-tunnel',
restUrl: 'https://us1.api.testobject.com/sc/rest/v1'
})
expect(spawn.mock.calls).toMatchSnapshot()
})
})

afterEach(() => {
Expand Down

0 comments on commit c0af3d1

Please sign in to comment.