Skip to content

Commit

Permalink
Be able to use check-example.js in c2cgeoportal checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jul 8, 2019
1 parent 801b31d commit 3b0a7b7
Showing 1 changed file with 20 additions and 11 deletions.
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

0 comments on commit 3b0a7b7

Please sign in to comment.