Skip to content

Commit

Permalink
feat: add support for latest browser version
Browse files Browse the repository at this point in the history
Add support for `latest` browser version that, when used,
will make the hub automatically pick one of the agents that
has the latest (newest) browser versions.
  • Loading branch information
sf-v committed Jul 31, 2023
1 parent 57e50aa commit c47786a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/@best/agent-hub/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,32 @@ export class Hub extends EventEmitter {
return this.findAgentMatchingSpecs(remoteClient, { ignoreBusy: true }).length > 0;
}

findLatestAvailableBrowserVersion(browserName: string = ''): string {
let latestVersion: number = -1;

for (const agent of this.connectedAgents) {
const agentSpecs = agent.getSpecs();
agentSpecs.forEach((agentSpec) => {
if (agentSpec.name === browserName) {
const version = Number(agentSpec.version);
if (version > latestVersion) {
latestVersion = version;
}
}
});
}

return latestVersion.toString();
}

findAgentMatchingSpecs(remoteClient: RemoteClient, { ignoreBusy }: { ignoreBusy?: boolean } = {}): RemoteAgent[] {
const specs = remoteClient.getSpecs();
const agents: RemoteAgent[] = [];
if (specs) {
if (specs.version === 'latest') {
specs.version = this.findLatestAvailableBrowserVersion(specs.name);
}

for (const agent of this.connectedAgents) {
const matchesSpecs = matchSpecs(specs, agent.getSpecs() || []);
const matchesFilterCriteria = ignoreBusy ? !agent.isBusy() : true;
Expand Down
2 changes: 1 addition & 1 deletion packages/@best/utils/src/match-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import { BrowserSpec } from '@best/types';

export function matchSpecs(specs: BrowserSpec, runnerSpecs: BrowserSpec[]) {
return runnerSpecs.some(
({ name, version }) => specs.name === name && specs.version.toString() === version.toString(),
({ name, version }) => specs.name === name && ['latest', version.toString()].includes(specs.version.toString()),
);
}

0 comments on commit c47786a

Please sign in to comment.