forked from peggyjs/peggy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add trivial puppeteer test. Fixes peggyjs#199.
- Loading branch information
Showing
6 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
engine-strict=true | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |