From f6b0c5f4149ee139fb1807ac62d20240130e28df Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Tue, 19 Oct 2021 01:16:23 -0600 Subject: [PATCH] Add trivial puppeteer test. Fixes #199. --- docs/development/test.html | 3 ++- web-test/.eslintrc.js | 8 +++++++ web-test/.npmrc | 2 ++ web-test/README.md | 4 ++++ web-test/index.js | 49 ++++++++++++++++++++++++++++++++++++++ web-test/package.json | 19 +++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 web-test/.eslintrc.js create mode 100644 web-test/.npmrc create mode 100644 web-test/README.md create mode 100644 web-test/index.js create mode 100644 web-test/package.json diff --git a/docs/development/test.html b/docs/development/test.html index 85e5fa41..0618552f 100644 --- a/docs/development/test.html +++ b/docs/development/test.html @@ -45,6 +45,7 @@

Parser Generator for JavaScript

Development +
PASS
@@ -57,6 +58,6 @@

Parser Generator for JavaScript

diff --git a/web-test/.eslintrc.js b/web-test/.eslintrc.js new file mode 100644 index 00000000..22e2516d --- /dev/null +++ b/web-test/.eslintrc.js @@ -0,0 +1,8 @@ +"use strict"; + +module.exports = { + parserOptions: { + // Puppeteer is *much* nicer to use with async/await. + ecmaVersion: 2017, + }, +}; diff --git a/web-test/.npmrc b/web-test/.npmrc new file mode 100644 index 00000000..4c1bf779 --- /dev/null +++ b/web-test/.npmrc @@ -0,0 +1,2 @@ +engine-strict=true +package-lock=false diff --git a/web-test/README.md b/web-test/README.md new file mode 100644 index 00000000..8b2a1978 --- /dev/null +++ b/web-test/README.md @@ -0,0 +1,4 @@ +Rudimentary puppeteer test for peggy. Separated into a directory so that +puppeteer (and it's Chromium instance) don't get installed in CI. + +If we decide to run these tests in CI later, this can be moved into the tools directory. diff --git a/web-test/index.js b/web-test/index.js new file mode 100644 index 00000000..93c711e6 --- /dev/null +++ b/web-test/index.js @@ -0,0 +1,49 @@ +"use strict"; + +const puppeteer = require("puppeteer"); +const path = require("path"); + +const TOP = `file://${path.resolve( + __dirname, "..", "docs", "development", "test.html", +)}`; + +async function main() { + let done = null; + const donePromise = new Promise((resolve, reject) => { + done = { resolve, reject }; + }); + const browser = await puppeteer.launch({ + slowMo: 100, + headless: false, + defaultViewport: null, + }); + const pages = await browser.pages(); + const page = (pages.length > 0) ? pages[0] : await browser.newPage(); + page + .on("console", message => { + const txt = message.text(); + switch (txt) { + case "PASS": + done.resolve(); + break; + case "FAIL": + done.reject(); + break; + default: { + const type = message + .type() + .toUpperCase(); + console.log(`${type}: ${txt}`); + } + } + }) + .on("pageerror", ({ message }) => console.log(`ERROR: ${message}`)) + .on("requestfailed", request => console.log( + `FAIL: ${request.failure().errorText} ${request.url()}`, + )); + await page.goto(TOP, { waitUntil: "load" }); + await donePromise; + await browser.close(); +} + +main().catch(console.error); diff --git a/web-test/package.json b/web-test/package.json new file mode 100644 index 00000000..66201825 --- /dev/null +++ b/web-test/package.json @@ -0,0 +1,19 @@ +{ + "name": "peggy-web-test", + "version": "0.0.0", + "private": true, + "description": "Test peggy for the web in the browser", + "main": "index.js", + "scripts": { + "test": "node index.js" + }, + "keywords": [], + "author": "Joe Hildebrand ", + "license": "MIT", + "devDependencies": { + "puppeteer": "^10.4.0" + }, + "engines": { + "node": ">=10" + } +}