From feec588f951d8833e3b9758cde9f34c325837407 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 22 Apr 2020 15:33:36 +0100 Subject: [PATCH] chore: add test for npm package installing correctly (#5714) * chore: add test for npm package installing correctly This command packs up the module and installs it again to check we're correctly bundling everything we need to allow users to do a fresh install. * install realpath --- .travis.yml | 6 +++++- package.json | 6 ++++-- scripts/test-install.sh | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100755 scripts/test-install.sh diff --git a/.travis.yml b/.travis.yml index e9dee242e91cb..82919d48f00a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ addons: packages: # This is required to run new chrome on old trusty - libnss3 + # Needed for realpath which we use in npm run test-install + - realpath notifications: email: false cache: @@ -33,7 +35,9 @@ jobs: - "sh -e /etc/init.d/xvfb start" # populate .local-firefox for launcher tests - PUPPETEER_PRODUCT=firefox npm install - script: ./travis/chromium.sh + script: + - npm run test-install + - travis/chromium.sh - node_js: "10.19.0" dist: trusty env: diff --git a/package.json b/package.json index 83179a83a13c7..d6b20d7f24aa9 100644 --- a/package.json +++ b/package.json @@ -30,14 +30,16 @@ "bundle": "npm run tsc && npx browserify -r ./index.js:puppeteer -o utils/browser/puppeteer-web.js", "test-types": "node utils/doclint/generate_types && tsc --version && tsc -p utils/doclint/generate_types/test/", "unit-bundle": "mocha --config mocha-config/browser-bundle-tests.js", - "update-protocol-d-ts": "node utils/protocol-types-generator" + "update-protocol-d-ts": "node utils/protocol-types-generator", + "test-install": "scripts/test-install.sh" }, "files": [ "lib/", "Errors.js", "DeviceDescriptors.js", "index.js", - "install.js" + "install.js", + "typescript-if-required.js" ], "author": "The Chromium Authors", "license": "Apache-2.0", diff --git a/scripts/test-install.sh b/scripts/test-install.sh new file mode 100755 index 0000000000000..02016ea925cee --- /dev/null +++ b/scripts/test-install.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh +set -e + +# Pack the module into a tarball +npm pack +tarball="$(realpath puppeteer-*.tgz)" +cd "$(mktemp -d)" +# 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')" +rm "${tarball}"