summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/scripts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--remote/test/puppeteer/scripts/ensure-correct-devtools-protocol-package.ts84
-rwxr-xr-xremote/test/puppeteer/scripts/test-install.sh41
-rw-r--r--remote/test/puppeteer/scripts/tsconfig.json6
3 files changed, 131 insertions, 0 deletions
diff --git a/remote/test/puppeteer/scripts/ensure-correct-devtools-protocol-package.ts b/remote/test/puppeteer/scripts/ensure-correct-devtools-protocol-package.ts
new file mode 100644
index 0000000000..2d6a4a1d1b
--- /dev/null
+++ b/remote/test/puppeteer/scripts/ensure-correct-devtools-protocol-package.ts
@@ -0,0 +1,84 @@
+/**
+ * Copyright 2020 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * This script ensures that the pinned version of devtools-protocol in
+ * package.json is the right version for the current revision of Chromium that
+ * Puppeteer ships with.
+ *
+ * The devtools-protocol package publisher runs every hour and checks if there
+ * are protocol changes. If there are, it will be versioned with the revision
+ * number of the commit that last changed the .pdl files.
+ *
+ * Chromium branches/releases are figured out at a later point in time, so it's
+ * not true that each Chromium revision will have an exact matching revision
+ * version of devtools-protocol. To ensure we're using a devtools-protocol that
+ * is aligned with our revision, we want to find the largest package number
+ * that's <= the revision that Puppeteer is using.
+ *
+ * This script uses npm's `view` function to list all versions in a range and
+ * find the one closest to our Chromium revision.
+ */
+
+// eslint-disable-next-line import/extensions
+import { PUPPETEER_REVISIONS } from '../src/revisions';
+import { execSync } from 'child_process';
+
+import packageJson from '../package.json';
+
+const currentProtocolPackageInstalledVersion =
+ packageJson.dependencies['devtools-protocol'];
+
+/**
+ * Ensure that the devtools-protocol version is pinned.
+ */
+if (/^[^0-9]/.test(currentProtocolPackageInstalledVersion)) {
+ console.log(
+ `ERROR: devtools-protocol package is not pinned to a specific version.\n`
+ );
+ process.exit(1);
+}
+
+// find the right revision for our Chromium revision
+
+const command = `npm view "devtools-protocol@<=0.0.${PUPPETEER_REVISIONS.chromium}" version | tail -1`;
+
+console.log(
+ 'Checking npm for devtools-protocol revisions:\n',
+ `'${command}'`,
+ '\n'
+);
+
+const output = execSync(command, {
+ encoding: 'utf8',
+});
+
+const bestRevisionFromNpm = output.split(' ')[1].replace(/'|\n/g, '');
+
+if (currentProtocolPackageInstalledVersion !== bestRevisionFromNpm) {
+ console.log(`ERROR: bad devtools-protocol revision detected:
+
+ Current Puppeteer Chromium revision: ${PUPPETEER_REVISIONS.chromium}
+ Current devtools-protocol version in package.json: ${currentProtocolPackageInstalledVersion}
+ Expected devtools-protocol version: ${bestRevisionFromNpm}`);
+
+ process.exit(1);
+}
+
+console.log(
+ `Correct devtools-protocol version found (${bestRevisionFromNpm}).`
+);
+process.exit(0);
diff --git a/remote/test/puppeteer/scripts/test-install.sh b/remote/test/puppeteer/scripts/test-install.sh
new file mode 100755
index 0000000000..e59aa39d00
--- /dev/null
+++ b/remote/test/puppeteer/scripts/test-install.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env sh
+set -e
+
+ROOTDIR="$(pwd)"
+# Pack the module into a tarball
+npm pack
+tarball="$(realpath puppeteer-*.tgz)"
+TMPDIR="$(mktemp -d)"
+cd $TMPDIR
+# Check we can install from the tarball.
+# This emulates installing from npm and ensures that:
+# 1. we publish the right files in the `files` list from package.json
+# 2. The install script works and correctly exits without errors
+# 3. Requiring Puppeteer from Node works.
+npm install --loglevel silent "${tarball}"
+node --eval="require('puppeteer')"
+ls $TMPDIR/node_modules/puppeteer/.local-chromium/
+
+# Again for Firefox
+TMPDIR="$(mktemp -d)"
+cd $TMPDIR
+PUPPETEER_PRODUCT=firefox npm install --loglevel silent "${tarball}"
+node --eval="require('puppeteer')"
+rm "${tarball}"
+ls $TMPDIR/node_modules/puppeteer/.local-firefox/linux-*/firefox/firefox
+
+# Again for puppeteer-core
+cd $ROOTDIR
+node ./utils/prepare_puppeteer_core.js
+npm pack
+tarball="$(realpath puppeteer-core-*.tgz)"
+TMPDIR="$(mktemp -d)"
+cd $TMPDIR
+# Check we can install from the tarball.
+# This emulates installing from npm and ensures that:
+# 1. we publish the right files in the `files` list from package.json
+# 2. The install script works and correctly exits without errors
+# 3. Requiring Puppeteer Core from Node works.
+npm install --loglevel silent "${tarball}"
+node --eval="require('puppeteer-core')"
+
diff --git a/remote/test/puppeteer/scripts/tsconfig.json b/remote/test/puppeteer/scripts/tsconfig.json
new file mode 100644
index 0000000000..c8d842173c
--- /dev/null
+++ b/remote/test/puppeteer/scripts/tsconfig.json
@@ -0,0 +1,6 @@
+{
+ "extends": "../tsconfig.json",
+ "compilerOptions": {
+ "module": "CommonJS"
+ }
+}