2020-04-22 14:33:36 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
set -e
|
|
|
|
|
2022-05-09 11:17:24 +00:00
|
|
|
# All tests are headed by a echo 'Test'.
|
|
|
|
# The general schema is:
|
|
|
|
# 1. Check we can install from the tarball.
|
|
|
|
# 2. The install script works and correctly exits without errors
|
|
|
|
# 3. Requiring/importing Puppeteer from Node works.
|
|
|
|
|
|
|
|
## Puppeter tests
|
|
|
|
|
|
|
|
echo "Setting up Puppeteer tests..."
|
2020-06-29 15:13:24 +00:00
|
|
|
ROOTDIR="$(pwd)"
|
2020-04-22 14:33:36 +00:00
|
|
|
npm pack
|
|
|
|
tarball="$(realpath puppeteer-*.tgz)"
|
2022-05-09 11:17:24 +00:00
|
|
|
|
|
|
|
echo "Testing... Chrome CommonJS"
|
2020-06-25 13:24:46 +00:00
|
|
|
TMPDIR="$(mktemp -d)"
|
|
|
|
cd $TMPDIR
|
2020-04-22 14:33:36 +00:00
|
|
|
npm install --loglevel silent "${tarball}"
|
|
|
|
node --eval="require('puppeteer')"
|
2022-05-09 11:17:24 +00:00
|
|
|
node --eval="require('puppeteer/lib/cjs/puppeteer/revisions.js');"
|
2022-02-10 10:59:24 +00:00
|
|
|
ls $TMPDIR/node_modules/puppeteer/.local-chromium/
|
2022-02-09 07:47:27 +00:00
|
|
|
|
2022-05-09 11:17:24 +00:00
|
|
|
echo "Testing... Chrome ES Modules"
|
|
|
|
TMPDIR="$(mktemp -d)"
|
|
|
|
cd $TMPDIR
|
|
|
|
echo '{"type":"module"}' >>$TMPDIR/package.json
|
|
|
|
npm install --loglevel silent "${tarball}"
|
|
|
|
node --input-type="module" --eval="import puppeteer from 'puppeteer'"
|
|
|
|
node --input-type="module" --eval="import 'puppeteer/lib/esm/puppeteer/revisions.js';"
|
|
|
|
node --input-type="module" --eval="
|
|
|
|
import puppeteer from 'puppeteer';
|
|
|
|
(async () => {
|
|
|
|
const browser = await puppeteer.launch();
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.goto('http://example.com');
|
|
|
|
await page.screenshot({ path: 'example.png' });
|
|
|
|
await browser.close();
|
|
|
|
})();
|
|
|
|
"
|
|
|
|
|
2022-06-09 17:00:50 +00:00
|
|
|
echo "Testing... Chrome ES Modules Destructuring"
|
|
|
|
TMPDIR="$(mktemp -d)"
|
|
|
|
cd $TMPDIR
|
|
|
|
echo '{"type":"module"}' >>$TMPDIR/package.json
|
|
|
|
npm install --loglevel silent "${tarball}"
|
|
|
|
node --input-type="module" --eval="import puppeteer from 'puppeteer'"
|
|
|
|
node --input-type="module" --eval="import 'puppeteer/lib/esm/puppeteer/revisions.js';"
|
|
|
|
node --input-type="module" --eval="
|
|
|
|
import { launch } from 'puppeteer';
|
|
|
|
(async () => {
|
|
|
|
const browser = await launch();
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.goto('http://example.com');
|
|
|
|
await page.screenshot({ path: 'example.png' });
|
|
|
|
await browser.close();
|
|
|
|
})();
|
|
|
|
"
|
|
|
|
|
2022-05-09 11:17:24 +00:00
|
|
|
echo "Testing... Chrome Webpack ES Modules"
|
|
|
|
TMPDIR="$(mktemp -d)"
|
|
|
|
cd $TMPDIR
|
|
|
|
echo '{"type": "module"}' >>$TMPDIR/package.json
|
|
|
|
npm install --loglevel silent "${tarball}"
|
|
|
|
npm install -D --loglevel silent webpack webpack-cli@4.9.2
|
|
|
|
echo 'export default {
|
|
|
|
mode: "production",
|
|
|
|
entry: "./index.js",
|
|
|
|
target: "node",
|
|
|
|
output: {
|
|
|
|
filename: "bundle.cjs",
|
|
|
|
},
|
|
|
|
};' >>$TMPDIR/webpack.config.js
|
|
|
|
echo "
|
|
|
|
import puppeteer from 'puppeteer';
|
|
|
|
(async () => {
|
|
|
|
const browser = await puppeteer.launch();
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.goto('http://example.com');
|
2022-09-21 08:16:54 +00:00
|
|
|
await page.\$('aria/example');
|
2022-05-09 11:17:24 +00:00
|
|
|
await page.screenshot({ path: 'example.png' });
|
|
|
|
await browser.close();
|
|
|
|
})();
|
|
|
|
" >>$TMPDIR/index.js
|
|
|
|
npx webpack
|
|
|
|
cp -r node_modules/puppeteer/.local-chromium .
|
|
|
|
rm -rf node_modules
|
|
|
|
node dist/bundle.cjs
|
|
|
|
|
|
|
|
echo "Testing... Firefox CommonJS"
|
2020-06-03 14:00:08 +00:00
|
|
|
TMPDIR="$(mktemp -d)"
|
|
|
|
cd $TMPDIR
|
|
|
|
PUPPETEER_PRODUCT=firefox npm install --loglevel silent "${tarball}"
|
|
|
|
node --eval="require('puppeteer')"
|
2022-05-09 11:17:24 +00:00
|
|
|
node --eval="require('puppeteer/lib/cjs/puppeteer/revisions.js');"
|
2020-08-10 08:22:31 +00:00
|
|
|
ls $TMPDIR/node_modules/puppeteer/.local-firefox/linux-*/firefox/firefox
|
2020-06-29 15:13:24 +00:00
|
|
|
|
2022-05-09 11:17:24 +00:00
|
|
|
echo "Testing... Firefox ES Modules"
|
|
|
|
TMPDIR="$(mktemp -d)"
|
|
|
|
cd $TMPDIR
|
|
|
|
echo '{"type":"module"}' >>$TMPDIR/package.json
|
|
|
|
PUPPETEER_PRODUCT=firefox npm install --loglevel silent "${tarball}"
|
|
|
|
node --input-type="module" --eval="import puppeteer from 'puppeteer'"
|
|
|
|
node --input-type="module" --eval="import 'puppeteer/lib/esm/puppeteer/revisions.js';"
|
|
|
|
ls $TMPDIR/node_modules/puppeteer/.local-firefox/linux-*/firefox/firefox
|
|
|
|
|
|
|
|
## Puppeteer Core tests
|
|
|
|
|
|
|
|
echo "Setting up Puppeteer Core tests..."
|
2020-06-29 15:13:24 +00:00
|
|
|
cd $ROOTDIR
|
2022-05-09 11:17:24 +00:00
|
|
|
rm "${tarball}"
|
2020-06-29 15:13:24 +00:00
|
|
|
node ./utils/prepare_puppeteer_core.js
|
|
|
|
npm pack
|
|
|
|
tarball="$(realpath puppeteer-core-*.tgz)"
|
2022-05-09 11:17:24 +00:00
|
|
|
|
|
|
|
echo "Testing... Puppeteer Core CommonJS"
|
2020-06-29 15:13:24 +00:00
|
|
|
TMPDIR="$(mktemp -d)"
|
|
|
|
cd $TMPDIR
|
|
|
|
npm install --loglevel silent "${tarball}"
|
|
|
|
node --eval="require('puppeteer-core')"
|
2022-05-09 11:17:24 +00:00
|
|
|
node --eval="require('puppeteer-core/lib/cjs/puppeteer/revisions.js');"
|
2020-06-29 15:13:24 +00:00
|
|
|
|
2022-05-09 11:17:24 +00:00
|
|
|
echo "Testing... Puppeteer Core ES Modules"
|
|
|
|
TMPDIR="$(mktemp -d)"
|
|
|
|
cd $TMPDIR
|
|
|
|
echo '{"type":"module"}' >>$TMPDIR/package.json
|
|
|
|
npm install --loglevel silent "${tarball}"
|
|
|
|
node --input-type="module" --eval="import puppeteer from 'puppeteer-core'"
|
|
|
|
node --input-type="module" --eval="import 'puppeteer-core/lib/esm/puppeteer/revisions.js';"
|
2022-09-08 12:45:16 +00:00
|
|
|
|
|
|
|
echo "Testing... Puppeteer Core launch with executablePath"
|
|
|
|
TMPDIR="$(mktemp -d)"
|
|
|
|
cd "$TMPDIR"
|
|
|
|
echo '{"type":"module"}' >> "$TMPDIR/package.json"
|
|
|
|
npm install --loglevel silent "${tarball}"
|
|
|
|
# The test tries to launch the node process because
|
|
|
|
# real browsers are not downloaded by puppeteer-core.
|
|
|
|
# The expected error is "Failed to launch the browser process"
|
|
|
|
# so the test verifies that it does not fail for other reasons.
|
|
|
|
node --input-type="module" --eval="
|
|
|
|
import puppeteer from 'puppeteer-core';
|
|
|
|
(async () => {
|
|
|
|
puppeteer.launch({
|
|
|
|
product: 'firefox',
|
|
|
|
executablePath: 'node'
|
|
|
|
}).catch(error => error.message.includes('Failed to launch the browser process') ? process.exit(0) : process.exit(1));
|
|
|
|
})();
|
|
|
|
"
|
|
|
|
node --input-type="module" --eval="
|
|
|
|
import puppeteer from 'puppeteer-core';
|
|
|
|
(async () => {
|
|
|
|
puppeteer.launch({
|
|
|
|
product: 'chrome',
|
|
|
|
executablePath: 'node'
|
|
|
|
}).catch(error => error.message.includes('Failed to launch the browser process') ? process.exit(0) : process.exit(1));
|
|
|
|
})();
|
|
|
|
"
|