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

Be able to use check-example.js in c2cgeoportal checks #4996

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions buildtools/check-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ const arg = process.argv[2];
if (!arg) {
throw new Error('Please provide a HTML file as the first argument');
}
const screenshotPath = `${arg}.png`;
const url = `http://localhost:3000/${arg}`;
const screenshot = !arg.startsWith('http');
const screenshotPath = screenshot ? `${arg}.png` : undefined;
const url = screenshot ? `http://localhost:3000/${arg}` : arg;

const OSMImage = fs.readFileSync(path.resolve(__dirname, 'osm.png'));
try {
const OSMImage = fs.readFileSync(path.resolve(__dirname, 'osm.png'));
} catch (e) {
// Ignore
}

const requestsURL = new Set();
const start = new Date();
Expand All @@ -35,15 +40,19 @@ function loaded(page, browser) {
} else {
// @ts-ignore
console.log(`Check finished in ${(new Date() - start) / 1000} seconds`);
page.screenshot({
path: screenshotPath
}).then(() => {
console.log(`Screenshot saved at: ${screenshotPath}`);
if (screenshot) {
page.screenshot({
path: screenshotPath
}).then(() => {
console.log(`Screenshot saved at: ${screenshotPath}`);
browser.close();
}, e => {
console.log(`Screenshot error: ${e}`);
process.exit(2);
});
} else {
browser.close();
}, e => {
console.log(`Screenshot error: ${e}`);
process.exit(2);
});
}
}
}, 500);
}
Expand Down