Skip to content

Commit

Permalink
In check-examples.js allow all requests to urls that match page hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-morvan committed Sep 11, 2019
1 parent dd0fdd2 commit f40940a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions buildtools/check-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
const path = require('path');
const fs = require('fs');
const puppeteer = require('puppeteer');
const parse = require('url-parse')

const arg = process.argv[2];
if (!arg) {
throw new Error('Please provide a HTML file as the first argument');
}
const screenshot = !arg.startsWith('http');
const screenshotPath = screenshot ? `${arg}.png` : undefined;
const url = screenshot ? `http://localhost:3000/${arg}` : arg;
const page_url = screenshot ? `http://localhost:3000/${arg}` : arg;

function hostnames_matches(url1, url2) {
const parsed_url1 = parse(url1);
const parsed_url2 = parse(url2);
return (
parsed_url1.protocol == parsed_url2.protocol &&
parsed_url1.host == parsed_url2.host
);
}

const OSMImage = (() => {
try {
Expand Down Expand Up @@ -82,7 +92,8 @@ function loaded(page, browser) {
page.on('request', request => {
const url = request.url();
loaded(page, browser);
if (url.startsWith('http://localhost:3000/') ||
if (hostnames_matches(url, page_url) ||
url.startsWith('http://localhost:3000/') ||
url.startsWith('https://geomapfish-demo-2-5.camptocamp.com/') ||
url.startsWith('https://wms.geo.admin.ch/')) {
requestsURL.add(url);
Expand All @@ -101,7 +112,7 @@ function loaded(page, browser) {
body: OSMImage,
});
} else {
request.abort();
request.abort('aborted');
}
});
page.on('requestfinished', async (request) => {
Expand Down Expand Up @@ -131,9 +142,7 @@ function loaded(page, browser) {
});
page.on('requestfailed', request => {
const url = request.url();
if (url.startsWith('http://localhost:3000/') ||
url.startsWith('https://geomapfish-demo-2-5.camptocamp.com/') ||
url.startsWith('https://wms.geo.admin.ch/')) {
if (request.failure().errorText != 'net::ERR_ABORTED') {
console.log(`Request failed on: ${url}`);
process.exit(2);
}
Expand All @@ -153,7 +162,7 @@ function loaded(page, browser) {
}
}
});
await page.goto(url).catch(error => {
await page.goto(page_url).catch(error => {
console.log(`Page load error: ${error}.`);
process.exit(2);
});
Expand Down

0 comments on commit f40940a

Please sign in to comment.