Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In check-examples.js allow all requests to urls that match page hostname #5112

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions buildtools/check-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
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;

const OSMImage = (() => {
try {
Expand Down Expand Up @@ -82,7 +83,8 @@ function loaded(page, browser) {
page.on('request', request => {
const url = request.url();
loaded(page, browser);
if (url.startsWith('http://localhost:3000/') ||
if (parse(url).host == parse(page_url).host ||
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 +103,7 @@ function loaded(page, browser) {
body: OSMImage,
});
} else {
request.abort();
request.abort('aborted');
}
});
page.on('requestfinished', async (request) => {
Expand Down Expand Up @@ -131,9 +133,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 +153,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