forked from jupyterlab/jupyterlab-module-federation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchrome-example-test.js
73 lines (62 loc) · 1.93 KB
/
chrome-example-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* A puppeteer test that launches an example app and makes sure
* there are no console errors or uncaught errors prior to a sentinal
* string being printed.
*/
const puppeteer = require('puppeteer');
const inspect = require('util').inspect;
const URL = process.argv[2];
async function main() {
/* eslint-disable no-console */
console.info('Starting Chrome Headless');
const browser = await puppeteer.launch({
args: ['--no-sandbox']
});
const page = await browser.newPage();
let errored = false;
const handleMessage = async msg => {
const text = msg.text();
if (msg.type() === 'error') {
console.log(`ERROR>> ${text}`);
errored = true;
} else {
console.log(`>> ${text}`);
}
const lower = text.toLowerCase();
if (lower === 'example started!' || lower === 'test complete!') {
await browser.close();
if (errored) {
console.error('\n\n***\nExample test failed!\n***\n\n');
process.exit(1);
}
console.info('Example test complete!');
return;
}
};
function handleError(err) {
console.error(err);
errored = true;
}
page.on('console', handleMessage);
page.on('error', handleError);
console.info('Navigating to page:', URL);
await page.goto(URL);
console.info('Waiting for page to load...');
// Wait for the local file to redirect on notebook >= 6.0. Refs:
// https://jupyter-notebook.readthedocs.io/en/stable/changelog.html?highlight=redirect
// https://stackoverflow.com/q/46948489/425458
await page.waitForNavigation();
const html = await page.content();
if (inspect(html).indexOf('jupyter-config-data') === -1) {
console.error('Error loading JupyterLab page:');
console.error(html);
}
console.info('Page loaded');
}
// Stop the process if an error is raised in the async function.
process.on('unhandledRejection', up => {
if (String(up).indexOf('Target closed') === -1) {
throw up;
}
});
main();