Skip to content

Commit 375b3b0

Browse files
Address comments
1 parent aa8270a commit 375b3b0

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

lib/webdriveragent.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,10 @@ export class WebDriverAgent {
353353
* @returns `true` if source is fresh (all required files exist), `false` otherwise
354354
*/
355355
async isSourceFresh(): Promise<boolean> {
356-
const existsPromises = ['Resources', `Resources${path.sep}WebDriverAgent.bundle`].map(
356+
const existsPromises = ['Resources', path.join('Resources', 'WebDriverAgent.bundle')].map(
357357
(subPath) => fs.exists(path.resolve(this.bootstrapPath, subPath)),
358358
);
359-
return (await Promise.all(existsPromises)).some((v) => v === false);
359+
return (await Promise.all(existsPromises)).every((v) => v === true);
360360
}
361361

362362
/**
@@ -527,14 +527,14 @@ export class WebDriverAgent {
527527
}
528528

529529
private toUrl(value: string): URL {
530+
// Treat values without `://` as host/path inputs and normalize to http.
531+
if (!value.includes(URL_PROTOCOL_SEPARATOR)) {
532+
return new URL(`http://${value}`);
533+
}
530534
try {
531535
return new URL(value);
532-
} catch (err) {
533-
// Keep compatibility with legacy parser behavior for values like "localhost:8100".
534-
if (!value.includes(URL_PROTOCOL_SEPARATOR)) {
535-
return new URL(`http://${value}`);
536-
}
537-
throw err;
536+
} catch {
537+
throw new Error(`Invalid URL: ${value}`);
538538
}
539539
}
540540

test/unit/webdriveragent-specs.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,24 @@ describe('WebDriverAgent', function () {
208208
expect(agent.noSessionProxy.scheme).to.eql('https');
209209
}
210210
});
211+
212+
it('should accept scheme-less webDriverAgentUrl values', function () {
213+
const args = Object.assign({}, fakeConstructorArgs);
214+
args.webDriverAgentUrl = 'localhost:8100/aabbccdd';
215+
const agent = new WebDriverAgent(args);
216+
expect(agent.url.href).to.eql('http://localhost:8100/aabbccdd');
217+
(agent as any).setupProxies('mysession');
218+
if (agent.jwproxy) {
219+
expect(agent.jwproxy.scheme).to.eql('http');
220+
}
221+
});
222+
223+
it('should throw for invalid webDriverAgentUrl with explicit scheme', function () {
224+
const args = Object.assign({}, fakeConstructorArgs);
225+
args.webDriverAgentUrl = 'http://';
226+
const agent = new WebDriverAgent(args);
227+
expect(() => agent.url).to.throw();
228+
});
211229
});
212230

213231
describe('setupCaching()', function () {

0 commit comments

Comments
 (0)