Skip to content

Commit

Permalink
test: update chrome installation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Dec 12, 2023
1 parent 1820225 commit f028f03
Show file tree
Hide file tree
Showing 4 changed files with 430 additions and 2,254 deletions.
44 changes: 41 additions & 3 deletions test/func/docker/browser-utils/download-chromium.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
const fs = require('fs');
const os = require('os');
const path = require('path');
const downloadChromium = require('hermione-headless-chrome/lib/download-chromium-by-version');
const {pipeline} = require('stream');
const {promisify} = require('util');
const AdmZip = require('adm-zip');
const got = require('got');

downloadChromium(process.env.CHROME_VERSION, path.join(os.homedir(), 'chrome-cache'), 10)
.then(chromePath => console.log(chromePath));
const streamPipeline = promisify(pipeline);

const download = async (url) => {
// Create a temporary directory to store the downloaded file
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'chrome-download-'));

// Path for the downloaded zip file
const zipFilePath = path.join(tempDir, 'chrome-linux64.zip');

await streamPipeline(
got.stream(url),
fs.createWriteStream(zipFilePath)
);

return zipFilePath;
};

const extract = async (zipFilePath) => {
const zip = new AdmZip(zipFilePath);

const outPath = path.dirname(zipFilePath);

zip.extractAllTo(outPath);

return path.join(outPath, 'chrome-linux64');
};

(async () => {
// Available good versions of Chrome for testing: https://googlechromelabs.github.io/chrome-for-testing/known-good-versions.json
const CHROME_URL = 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.49/linux64/chrome-linux64.zip';

const chromeZipPath = await download(CHROME_URL);
const chromePath = await extract(chromeZipPath);

console.log(chromePath);
})();
4 changes: 1 addition & 3 deletions test/func/docker/browser-utils/install-chromium.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash

# The download script outputs progress messages, but we need only final path, hence we filter output here
CHROME_PATH=$(node ./download-chromium.js |& grep '^/home')
CHROME_PATH=$(dirname $CHROME_PATH)
CHROME_PATH=$(node ./download-chromium.js)
mkdir ~/browsers
mv $CHROME_PATH ~/browsers/chrome-linux
Loading

0 comments on commit f028f03

Please sign in to comment.