fix: check if executable exists (#11946)

This commit is contained in:
Alex Rudenko 2024-02-19 13:40:50 +01:00 committed by GitHub
parent 03ef7a62c2
commit e95a308c33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 8 deletions

View File

@ -140,15 +140,22 @@ export async function install(
options.platform,
options.buildId
);
if (existsSync(outputPath)) {
return new InstalledBrowser(
cache,
options.browser,
options.buildId,
options.platform
);
}
try {
if (existsSync(outputPath)) {
const installedBrowser = new InstalledBrowser(
cache,
options.browser,
options.buildId,
options.platform
);
if (!existsSync(installedBrowser.executablePath)) {
throw new Error(
`The browser folder (${outputPath}) exists but the executable (${installedBrowser.executablePath}) is missing`
);
}
return installedBrowser;
}
debugInstall(`Downloading binary from ${url}`);
try {
debugTime('download');

View File

@ -63,6 +63,35 @@ describe('Chrome install', () => {
);
});
it('can detect missing executables', async function () {
this.timeout(60000);
const expectedOutputPath = path.join(
tmpDir,
'chrome',
`${BrowserPlatform.LINUX}-${testChromeBuildId}`
);
fs.mkdirSync(expectedOutputPath, {recursive: true});
assert.strictEqual(fs.existsSync(expectedOutputPath), true);
async function installThatThrows(): Promise<Error | undefined> {
try {
await install({
cacheDir: tmpDir,
browser: Browser.CHROME,
platform: BrowserPlatform.LINUX,
buildId: testChromeBuildId,
});
return undefined;
} catch (err) {
return err as Error;
}
}
assert.strictEqual(
(await installThatThrows())?.message,
`The browser folder (${expectedOutputPath}) exists but the executable (${expectedOutputPath}/chrome-linux64/chrome) is missing`
);
assert.strictEqual(fs.existsSync(expectedOutputPath), true);
});
it('should download a buildId that is a zip archive', async function () {
this.timeout(60000);
const expectedOutputPath = path.join(