1
1
const assert = require ( 'assert' ) ;
2
2
const puppeteer = require ( 'puppeteer' ) ;
3
3
const inspect = require ( 'util' ) . inspect ;
4
+ const URL = process . argv [ 2 ] ;
4
5
5
- function getUrl ( ) {
6
- return process . argv [ 2 ] ;
6
+ function testGitExtension ( html ) {
7
+ // Test git icons are present
8
+ assert ( html . includes ( '--jp-icon-git-clone' ) , 'Could not find git clone icon.' ) ;
9
+ assert ( html . includes ( '--jp-icon-git-pull' ) , 'Could not find git pull icon.' ) ;
10
+ assert ( html . includes ( '--jp-icon-git-push' ) , 'Could not find git push icon.' ) ;
7
11
}
8
12
9
- function testJupyterLabPage ( html ) {
13
+ async function main ( ) {
14
+ /* eslint-disable no-console */
15
+ console . info ( 'Starting Chrome Headless' ) ;
16
+
17
+ const browser = await puppeteer . launch ( { args : [ '--no-sandbox' ] } ) ;
18
+ const page = await browser . newPage ( ) ;
19
+
20
+ console . info ( 'Navigating to page:' , URL ) ;
21
+ await page . goto ( URL ) ;
22
+ console . info ( 'Waiting for page to load...' ) ;
23
+
24
+ // Wait for the local file to redirect on notebook >= 6.0
25
+ await page . waitForNavigation ( ) ;
26
+
27
+ const html = await page . content ( ) ;
10
28
if ( inspect ( html ) . indexOf ( 'jupyter-config-data' ) === - 1 ) {
11
29
console . error ( 'Error loading JupyterLab page:' ) ;
12
30
console . error ( html ) ;
13
31
}
14
- }
15
32
16
- async function testApplication ( page ) {
17
33
const el = await page . waitForSelector ( '#browserTest' , { timeout : 100000 } ) ;
18
34
console . log ( 'Waiting for application to start...' ) ;
35
+ let testError = null ;
19
36
20
- await page . waitForSelector ( '.completed' ) ;
21
-
37
+ try {
38
+ await page . waitForSelector ( '.completed' ) ;
39
+ } catch ( e ) {
40
+ testError = e ;
41
+ }
22
42
const textContent = await el . getProperty ( 'textContent' ) ;
23
43
const errors = JSON . parse ( await textContent . jsonValue ( ) ) ;
24
44
25
45
for ( let error of errors ) {
26
46
console . error ( `Parsed an error from text content: ${ error . message } ` , error ) ;
27
- throw error ;
28
47
}
29
- }
30
48
31
- function testGitExtension ( html ) {
32
- // Test git icons are present
33
- assert ( html . includes ( '--jp-icon-git-clone' ) , 'Could not find git clone icon.' ) ;
34
- assert ( html . includes ( '--jp-icon-git-pull' ) , 'Could not find git pull icon.' ) ;
35
- assert ( html . includes ( '--jp-icon-git-push' ) , 'Could not find git push icon.' ) ;
36
- }
37
-
38
- async function main ( ) {
39
- console . info ( 'Starting Chrome Headless' ) ;
40
-
41
- const URL = getUrl ( ) ;
42
- const browser = await puppeteer . launch ( { args : [ '--no-sandbox' ] } ) ;
43
- const page = await browser . newPage ( ) ;
44
-
45
- console . info ( 'Navigating to page:' , URL ) ;
46
- await page . goto ( URL ) ;
47
- console . info ( 'Waiting for page to load...' ) ;
48
-
49
- const html = await page . content ( ) ;
50
- testJupyterLabPage ( html ) ;
51
-
52
- await testApplication ( page ) ;
53
49
testGitExtension ( html ) ;
54
50
55
51
await browser . close ( ) ;
52
+
53
+ if ( testError ) {
54
+ throw testError ;
55
+ }
56
56
console . info ( 'Chrome test complete' ) ;
57
57
}
58
58
@@ -61,4 +61,4 @@ process.on('unhandledRejection', up => {
61
61
throw up ;
62
62
} ) ;
63
63
64
- main ( ) ;
64
+ main ( ) ;
0 commit comments