Skip to content

Commit

Permalink
feat: allow installing chrome/chromedriver by milestone and version p…
Browse files Browse the repository at this point in the history
…refix (#10720)
  • Loading branch information
OrKoN committed Aug 10, 2023
1 parent 0c59e9a commit bec2357
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 48 deletions.
26 changes: 23 additions & 3 deletions packages/browsers/src/CLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ export class CLI {
'$0 install chrome@latest',
'Install the latest available build for the Chrome browser.'
);
yargs.example(
'$0 install chrome@canary',
'Install the latest available build for the Chrome Canary browser.'
);
yargs.example(
'$0 install chrome@115',
'Install the latest available build for Chrome 115.'
);
yargs.example(
'$0 install chromedriver@canary',
'Install the latest available build for ChromeDriver Canary.'
);
yargs.example(
'$0 install chromedriver@115',
'Install the latest available build for ChromeDriver 115.'
);
yargs.example(
'$0 install chromedriver@115.0.5790',
'Install the latest available patch (115.0.5790.X) build for ChromeDriver.'
);
yargs.example(
'$0 install chromium@1083080',
'Install the revision 1083080 of the Chromium browser.'
Expand Down Expand Up @@ -201,15 +221,15 @@ export class CLI {
default: false,
});
yargs.example(
'$0 launch chrome@1083080',
'Launch the Chrome browser identified by the revision 1083080.'
'$0 launch chrome@115.0.5790.170',
'Launch Chrome 115.0.5790.170'
);
yargs.example(
'$0 launch firefox@112.0a1',
'Launch the Firefox browser identified by the milestone 112.0a1.'
);
yargs.example(
'$0 launch chrome@1083080 --detached',
'$0 launch chrome@115.0.5790.170 --detached',
'Launch the browser but detach the sub-processes.'
);
yargs.example(
Expand Down
45 changes: 22 additions & 23 deletions packages/browsers/src/browser-data/browser-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,28 @@ export async function resolveBuildId(
`${tag} is not supported for ${browser}. Use 'latest' instead.`
);
}
case Browser.CHROME:
case Browser.CHROME: {
switch (tag as BrowserTag) {
case BrowserTag.LATEST:
return await chrome.resolveBuildId(
platform,
ChromeReleaseChannel.CANARY
);
return await chrome.resolveBuildId(ChromeReleaseChannel.CANARY);
case BrowserTag.BETA:
return await chrome.resolveBuildId(
platform,
ChromeReleaseChannel.BETA
);
return await chrome.resolveBuildId(ChromeReleaseChannel.BETA);
case BrowserTag.CANARY:
return await chrome.resolveBuildId(
platform,
ChromeReleaseChannel.CANARY
);
return await chrome.resolveBuildId(ChromeReleaseChannel.CANARY);
case BrowserTag.DEV:
return await chrome.resolveBuildId(
platform,
ChromeReleaseChannel.DEV
);
return await chrome.resolveBuildId(ChromeReleaseChannel.DEV);
case BrowserTag.STABLE:
return await chrome.resolveBuildId(
platform,
ChromeReleaseChannel.STABLE
);
return await chrome.resolveBuildId(ChromeReleaseChannel.STABLE);
default:
const result = await chrome.resolveBuildId(tag);
if (result) {
return result;
}
}
case Browser.CHROMEDRIVER:
switch (tag as BrowserTag) {
return tag;
}
case Browser.CHROMEDRIVER: {
switch (tag) {
case BrowserTag.LATEST:
case BrowserTag.CANARY:
return await chromedriver.resolveBuildId(ChromeReleaseChannel.CANARY);
Expand All @@ -111,7 +103,14 @@ export async function resolveBuildId(
return await chromedriver.resolveBuildId(ChromeReleaseChannel.DEV);
case BrowserTag.STABLE:
return await chromedriver.resolveBuildId(ChromeReleaseChannel.STABLE);
default:
const result = await chromedriver.resolveBuildId(tag);
if (result) {
return result;
}
}
return tag;
}
case Browser.CHROMIUM:
switch (tag as BrowserTag) {
case BrowserTag.LATEST:
Expand Down
61 changes: 58 additions & 3 deletions packages/browsers/src/browser-data/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,66 @@ export async function getLastKnownGoodReleaseForChannel(
).channels[channel];
}

export async function getLastKnownGoodReleaseForMilestone(
milestone: string
): Promise<{version: string; revision: string} | undefined> {
const data = (await getJSON(
new URL(
'https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone.json'
)
)) as {
milestones: Record<string, {version: string; revision: string}>;
};
return data.milestones[milestone] as
| {version: string; revision: string}
| undefined;
}

export async function getLastKnownGoodReleaseForBuild(
/**
* @example `112.0.23`,
*/
buildPrefix: string
): Promise<{version: string; revision: string} | undefined> {
const data = (await getJSON(
new URL(
'https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build.json'
)
)) as {
builds: Record<string, {version: string; revision: string}>;
};
return data.builds[buildPrefix] as
| {version: string; revision: string}
| undefined;
}

export async function resolveBuildId(
_platform: BrowserPlatform,
channel: ChromeReleaseChannel
): Promise<string> {
return (await getLastKnownGoodReleaseForChannel(channel)).version;
): Promise<string>;
export async function resolveBuildId(
channel: string
): Promise<string | undefined>;
export async function resolveBuildId(
channel: ChromeReleaseChannel | string
): Promise<string | undefined> {
if (
Object.values(ChromeReleaseChannel).includes(
channel as ChromeReleaseChannel
)
) {
return (
await getLastKnownGoodReleaseForChannel(channel as ChromeReleaseChannel)
).version;
}
if (channel.match(/^\d+$/)) {
// Potentially a milestone.
return (await getLastKnownGoodReleaseForMilestone(channel))?.version;
}
if (channel.match(/^\d+\.\d+\.\d+$/)) {
// Potentially a build prefix without the patch version.
return (await getLastKnownGoodReleaseForBuild(channel))?.version;
}
return;
}

export function resolveSystemExecutablePath(
Expand Down
10 changes: 3 additions & 7 deletions packages/browsers/src/browser-data/chromedriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
import path from 'path';

import {getLastKnownGoodReleaseForChannel} from './chrome.js';
import {BrowserPlatform, ChromeReleaseChannel} from './types.js';
import {BrowserPlatform} from './types.js';

function folder(platform: BrowserPlatform): string {
switch (platform) {
Expand Down Expand Up @@ -63,8 +62,5 @@ export function relativeExecutablePath(
return path.join('chromedriver-' + folder(platform), 'chromedriver.exe');
}
}
export async function resolveBuildId(
channel: ChromeReleaseChannel
): Promise<string> {
return (await getLastKnownGoodReleaseForChannel(channel)).version;
}

export {resolveBuildId} from './chrome.js';
9 changes: 9 additions & 0 deletions packages/browsers/test/src/chrome/chrome-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
resolveDownloadUrl,
relativeExecutablePath,
resolveSystemExecutablePath,
resolveBuildId,
} from '../../../lib/cjs/browser-data/chrome.js';

describe('Chrome', () => {
Expand Down Expand Up @@ -117,4 +118,12 @@ describe('Chrome', () => {
);
}, new Error(`Unable to detect browser executable path for 'canary' on linux.`));
});

it('should resolve milestones', async () => {
assert.strictEqual(await resolveBuildId('115'), '115.0.5790.170');
});

it('should resolve build prefix', async () => {
assert.strictEqual(await resolveBuildId('115.0.5790'), '115.0.5790.170');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {BrowserPlatform} from '../../../lib/cjs/browser-data/browser-data.js';
import {
resolveDownloadUrl,
relativeExecutablePath,
resolveBuildId,
} from '../../../lib/cjs/browser-data/chromedriver.js';

describe('ChromeDriver', () => {
Expand All @@ -47,6 +48,14 @@ describe('ChromeDriver', () => {
);
});

it('should resolve milestones', async () => {
assert.strictEqual(await resolveBuildId('115'), '115.0.5790.170');
});

it('should resolve build prefix', async () => {
assert.strictEqual(await resolveBuildId('115.0.5790'), '115.0.5790.170');
});

it('should resolve executable paths', () => {
assert.strictEqual(
relativeExecutablePath(BrowserPlatform.LINUX, '12372323'),
Expand Down
24 changes: 12 additions & 12 deletions test/TestExpectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,18 @@
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"]
},
{
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should evaluate before anything else on the page",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should work with CSP",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[evaluation.spec] Evaluation specs Page.removeScriptToEvaluateOnNewDocument *",
"platforms": ["darwin", "linux", "win32"],
Expand Down Expand Up @@ -4150,17 +4162,5 @@
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "chrome", "headless"],
"expectations": ["FAIL", "PASS"]
},
{
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should evaluate before anything else on the page",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should work with CSP",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
}
]

0 comments on commit bec2357

Please sign in to comment.