Skip to content

Commit

Permalink
Add trivial puppeteer test. Fixes peggyjs#199.
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Oct 19, 2021
1 parent e271409 commit f6b0c5f
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/development/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ <h2>Parser Generator for JavaScript</h2>
<a href="index.html">Development</a>
</nav>

<div id='results'>PASS</div>
<div id="content">
<div id="mocha"></div>
</div>
Expand All @@ -57,6 +58,6 @@ <h2>Parser Generator for JavaScript</h2>
</div>
</body>
<script class="mocha-exec">
mocha.run();
mocha.run(failures => console.log(failures === 0 ? 'PASS' : 'FAIL'));
</script>
</html>
8 changes: 8 additions & 0 deletions web-test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";

module.exports = {
parserOptions: {
// Puppeteer is *much* nicer to use with async/await.
ecmaVersion: 2017,
},
};
2 changes: 2 additions & 0 deletions web-test/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
engine-strict=true
package-lock=false
4 changes: 4 additions & 0 deletions web-test/README.md
Original file line number Diff line number Diff line change
@@ -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.
49 changes: 49 additions & 0 deletions web-test/index.js
Original file line number Diff line number Diff line change
@@ -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);
19 changes: 19 additions & 0 deletions web-test/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"license": "MIT",
"devDependencies": {
"puppeteer": "^10.4.0"
},
"engines": {
"node": ">=10"
}
}

0 comments on commit f6b0c5f

Please sign in to comment.