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
This commit is contained in:
Jack Franklin 2020-04-22 15:33:36 +01:00 committed by GitHub
parent 1615c9c9d5
commit feec588f95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -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:

View File

@ -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",

15
scripts/test-install.sh Executable file
View File

@ -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}"