added bin dir
This commit is contained in:
parent
b26a5e902c
commit
777fe83257
23
bin/README.md
Normal file
23
bin/README.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
Testrunner prerequisites
|
||||||
|
========================
|
||||||
|
|
||||||
|
npm install puppeteer
|
||||||
|
|
||||||
|
|
||||||
|
testrunner.js
|
||||||
|
-------------
|
||||||
|
start from iwmlib directory with node testrunner
|
||||||
|
|
||||||
|
defined in package.json
|
||||||
|
"testrunner": "node bin/testrunner.js"
|
||||||
|
|
||||||
|
or in vscode, defined in launch.json like
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "testrunner",
|
||||||
|
"program": "${workspaceFolder}\\bin\\testrunner.js"
|
||||||
|
}
|
||||||
|
|
||||||
|
iterates all doctest.html files that are listed in index.html
|
||||||
|
create a screenshot of all pages
|
70
bin/singleshot.js
Normal file
70
bin/singleshot.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* test one single page, make a screenshot and log errors to
|
||||||
|
* console
|
||||||
|
* (c) 2019 - Leibniz-Insitut für Wissensmedien
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const puppeteer = require('puppeteer');
|
||||||
|
const fs = require("fs")
|
||||||
|
const path = require("path")
|
||||||
|
const start_dir = process.cwd()
|
||||||
|
|
||||||
|
|
||||||
|
// const start_file = path.join(start_dir,"lib","frames.html")
|
||||||
|
const start_file = path.join(start_dir,"lib","pixi","badge.html")
|
||||||
|
|
||||||
|
function sleep(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
const events = ["error","pageerror"]
|
||||||
|
function logPageEvent(event){
|
||||||
|
if(event !== undefined){
|
||||||
|
console.log(event.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function makeScreenshot(href){
|
||||||
|
|
||||||
|
const browser = await puppeteer.launch({
|
||||||
|
// headless: false,
|
||||||
|
// loglevel : 0,
|
||||||
|
args : [
|
||||||
|
'–allow-file-access-from-files',
|
||||||
|
],});
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
await page.setViewport({width: 1024,height : 624})
|
||||||
|
for (var i = 0; i < events.length; i++) {
|
||||||
|
page.on(events[i],logPageEvent)
|
||||||
|
}
|
||||||
|
page.once("load",logPageEvent)
|
||||||
|
|
||||||
|
// await Promise.all([ page.coverage.startJSCoverage() ]);
|
||||||
|
await page.goto(href)
|
||||||
|
// const jsCoverage = await Promise.all([ page.coverage.stopJSCoverage() ]);
|
||||||
|
|
||||||
|
const fname = path.parse(href).name
|
||||||
|
|
||||||
|
if (fname != "index"){
|
||||||
|
image_url = href.replace(fname + ".html" ,"thumbnails/" + fname + ".png")
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
image_url = href.replace(fname + ".html" ,"thumbnail.png")
|
||||||
|
}
|
||||||
|
image_url = image_url.replace("file:///","")
|
||||||
|
console.log(image_url)
|
||||||
|
// console.log(jsCoverage)
|
||||||
|
|
||||||
|
page.removeAllListeners()
|
||||||
|
|
||||||
|
await page.screenshot({path: image_url});
|
||||||
|
await browser.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
(async function(){
|
||||||
|
|
||||||
|
await makeScreenshot(start_file)
|
||||||
|
}
|
||||||
|
)()
|
109
bin/testrunner.js
Normal file
109
bin/testrunner.js
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* make screenshots and log errors to
|
||||||
|
* console
|
||||||
|
* (c) 2019 - Leibniz-Insitut für Wissensmedien
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
const puppeteer = require('puppeteer');
|
||||||
|
const fs = require("fs")
|
||||||
|
const path = require("path")
|
||||||
|
const start_dir = process.cwd()
|
||||||
|
const start_file = path.join(start_dir,"lib","index.html")
|
||||||
|
|
||||||
|
const start_file_uri = path.join("file:///", start_file )
|
||||||
|
|
||||||
|
// define events and log them
|
||||||
|
const events = ["error","pageerror"]
|
||||||
|
function logPageEvent(event){
|
||||||
|
if (event !== undefined){
|
||||||
|
console.log(event.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function makeScreenshot(href){
|
||||||
|
|
||||||
|
const browser = await puppeteer.launch({args: [
|
||||||
|
'–allow-file-access-from-files',
|
||||||
|
],});
|
||||||
|
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
await page.setViewport({width: 1024,height : 624})
|
||||||
|
|
||||||
|
// register events
|
||||||
|
for (var i = 0; i < events.length; i++) {
|
||||||
|
page.on(events[i],logPageEvent)
|
||||||
|
}
|
||||||
|
page.once("load",logPageEvent)
|
||||||
|
|
||||||
|
await page.goto(href)
|
||||||
|
const fname = path.parse(href).name
|
||||||
|
|
||||||
|
if (fname != "index"){
|
||||||
|
image_url = href.replace(fname + ".html" ,"thumbnails/" + fname + ".png")
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
image_url = href.replace(fname + ".html" ,"thumbnail.png")
|
||||||
|
}
|
||||||
|
image_url = image_url.replace("file:///","")
|
||||||
|
|
||||||
|
page.removeAllListeners()
|
||||||
|
|
||||||
|
await page.screenshot({path: image_url});
|
||||||
|
await browser.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* collect all navigational links in all documents
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
|
||||||
|
async function collectLinks(href,reflist)
|
||||||
|
{
|
||||||
|
const browser = await puppeteer.launch();
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
|
||||||
|
await page.goto(href)
|
||||||
|
let hrefs = await page.$$('a.wrapper')
|
||||||
|
|
||||||
|
for (var i=0; i < hrefs.length; i++) {
|
||||||
|
let hrefValue = await hrefs[i].getProperty('href')
|
||||||
|
let linkText = await hrefValue.jsonValue();
|
||||||
|
if (!linkText.startsWith("file:"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(linkText.endsWith("#")) continue;
|
||||||
|
if(linkText.endsWith("index.html")){
|
||||||
|
await collectLinks(linkText,reflist)
|
||||||
|
}
|
||||||
|
reflist.push(linkText)
|
||||||
|
}
|
||||||
|
|
||||||
|
await browser.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
(async function(){
|
||||||
|
var reflist = []
|
||||||
|
let linkText = "file:///" + start_file.replace(/\\/g,"/")
|
||||||
|
reflist.push(linkText)
|
||||||
|
await collectLinks(start_file_uri,reflist)
|
||||||
|
|
||||||
|
// sort by path length to get depth first
|
||||||
|
reflist.sort(function(a,b){
|
||||||
|
let al = a.split("/").length
|
||||||
|
let bl = b.split("/").length
|
||||||
|
|
||||||
|
if (al < bl) {return 1 }
|
||||||
|
if (al > bl) {return -1 }
|
||||||
|
if (al == bl) {return 0 }
|
||||||
|
})
|
||||||
|
for (var i=0;i<reflist.length; i++) {
|
||||||
|
await makeScreenshot(reflist[i])
|
||||||
|
console.log(i,reflist[i])
|
||||||
|
}
|
||||||
|
})()
|
Loading…
Reference in New Issue
Block a user