-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathheadless-chrome
executable file
·70 lines (52 loc) · 2.08 KB
/
headless-chrome
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# Copyright 2019 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Run mocha-headless-chrome with the right settings.
A snapshot of Chrome that we update from time to time.
uribase='https://dl.google.com/linux/chrome/deb'
filename=$(
curl -s "${uribase}/dists/stable/main/binary-amd64/Packages.gz" | \
zcat | \
awk '$1 == "Filename:" && $2 ~ /google-chrome-stable/ {print $NF}')
echo "${filename##*/}"
wget "${uribase}/${filename}"
gsutil cp -a public-read google-chrome-stable_*.deb \
gs://chromeos-localmirror/secureshell/distfiles/
"""
import shutil
import sys
import libdot
CHROME_VERSION = "google-chrome-stable_108.0.5359.71-1"
def chrome_setup():
"""Download our copy of Chrome for headless testing."""
puppeteer = libdot.node.NODE_MODULES_DIR / "puppeteer"
download_dir = puppeteer / ".local-chromium"
chrome_dir = download_dir / CHROME_VERSION
chrome_bin = chrome_dir / "opt" / "google" / "chrome" / "chrome"
if chrome_bin.exists():
return chrome_bin
# Create a tempdir to unpack everything into.
tmpdir = chrome_dir.with_name(f"{chrome_dir.name}.tmp")
shutil.rmtree(tmpdir, ignore_errors=True)
tmpdir.mkdir(parents=True, exist_ok=True)
# Get the snapshot deb archive.
chrome_deb = tmpdir / "deb"
uri = f"{libdot.node.NODE_MODULES_BASE_URI}/{CHROME_VERSION}_amd64.deb"
libdot.fetch(uri, chrome_deb)
# Unpack the deb archive, then clean it all up.
libdot.run(["ar", "x", "deb", "data.tar.xz"], cwd=tmpdir)
libdot.unpack("data.tar.xz", cwd=tmpdir)
libdot.unlink(chrome_deb)
libdot.unlink(tmpdir / "data.tar.xz")
# Finally move the tempdir to the saved location.
tmpdir.rename(chrome_dir)
return chrome_bin
def main(argv):
"""The main func!"""
libdot.setup_logging()
libdot.node_and_npm_setup()
chrome_bin = chrome_setup()
libdot.node.run(["mocha-headless-chrome", "-e", chrome_bin] + argv)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))