@@ -17,35 +17,39 @@ describe("lazy compilation", () => {
17
17
18
18
const { page, browser } = await runBrowser ( ) ;
19
19
20
- const pageErrors = [ ] ;
21
- const consoleMessages = [ ] ;
22
-
23
- page
24
- . on ( "console" , ( message ) => {
25
- consoleMessages . push ( message . text ( ) ) ;
26
- } )
27
- . on ( "pageerror" , ( error ) => {
28
- pageErrors . push ( error ) ;
20
+ try {
21
+ const pageErrors = [ ] ;
22
+ const consoleMessages = [ ] ;
23
+
24
+ page
25
+ . on ( "console" , ( message ) => {
26
+ consoleMessages . push ( message . text ( ) ) ;
27
+ } )
28
+ . on ( "pageerror" , ( error ) => {
29
+ pageErrors . push ( error ) ;
30
+ } ) ;
31
+
32
+ await page . goto ( `http://127.0.0.1:${ port } /test.html` , {
33
+ waitUntil : "domcontentloaded" ,
34
+ } ) ;
35
+ await new Promise ( ( resolve ) => {
36
+ const interval = setInterval ( ( ) => {
37
+ if ( consoleMessages . includes ( "Hey." ) ) {
38
+ clearInterval ( interval ) ;
39
+
40
+ resolve ( ) ;
41
+ }
42
+ } , 100 ) ;
29
43
} ) ;
30
44
31
- await page . goto ( `http://127.0.0.1:${ port } /test.html` , {
32
- waitUntil : "domcontentloaded" ,
33
- } ) ;
34
- await new Promise ( ( resolve ) => {
35
- const interval = setInterval ( ( ) => {
36
- if ( consoleMessages . includes ( "Hey." ) ) {
37
- clearInterval ( interval ) ;
38
-
39
- resolve ( ) ;
40
- }
41
- } , 100 ) ;
42
- } ) ;
43
-
44
- expect ( consoleMessages ) . toMatchSnapshot ( "console messages" ) ;
45
- expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
46
-
47
- await browser . close ( ) ;
48
- await server . stop ( ) ;
45
+ expect ( consoleMessages ) . toMatchSnapshot ( "console messages" ) ;
46
+ expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
47
+ } catch ( error ) {
48
+ throw error ;
49
+ } finally {
50
+ await browser . close ( ) ;
51
+ await server . stop ( ) ;
52
+ }
49
53
} ) ;
50
54
51
55
it . skip ( `should work with multiple entries` , async ( ) => {
@@ -56,49 +60,53 @@ describe("lazy compilation", () => {
56
60
57
61
const { page, browser } = await runBrowser ( ) ;
58
62
59
- const pageErrors = [ ] ;
60
- const consoleMessages = [ ] ;
63
+ try {
64
+ const pageErrors = [ ] ;
65
+ const consoleMessages = [ ] ;
66
+
67
+ page
68
+ . on ( "console" , ( message ) => {
69
+ consoleMessages . push ( message . text ( ) ) ;
70
+ } )
71
+ . on ( "pageerror" , ( error ) => {
72
+ pageErrors . push ( error ) ;
73
+ } ) ;
61
74
62
- page
63
- . on ( "console" , ( message ) => {
64
- consoleMessages . push ( message . text ( ) ) ;
65
- } )
66
- . on ( "pageerror" , ( error ) => {
67
- pageErrors . push ( error ) ;
75
+ await page . goto ( `http://127.0.0.1:${ port } /test-one.html` , {
76
+ waitUntil : "domcontentloaded" ,
77
+ } ) ;
78
+ await new Promise ( ( resolve ) => {
79
+ const interval = setInterval ( ( ) => {
80
+ console . log ( consoleMessages ) ;
81
+ if ( consoleMessages . includes ( "One." ) ) {
82
+ clearInterval ( interval ) ;
83
+
84
+ resolve ( ) ;
85
+ }
86
+ } , 100 ) ;
87
+ } ) ;
88
+
89
+ await page . goto ( `http://127.0.0.1:${ port } /test-two.html` , {
90
+ waitUntil : "domcontentloaded" ,
91
+ } ) ;
92
+ await new Promise ( ( resolve ) => {
93
+ const interval = setInterval ( ( ) => {
94
+ console . log ( consoleMessages ) ;
95
+ if ( consoleMessages . includes ( "Two." ) ) {
96
+ clearInterval ( interval ) ;
97
+
98
+ resolve ( ) ;
99
+ }
100
+ } , 100 ) ;
68
101
} ) ;
69
102
70
- await page . goto ( `http://127.0.0.1:${ port } /test-one.html` , {
71
- waitUntil : "domcontentloaded" ,
72
- } ) ;
73
- await new Promise ( ( resolve ) => {
74
- const interval = setInterval ( ( ) => {
75
- console . log ( consoleMessages ) ;
76
- if ( consoleMessages . includes ( "One." ) ) {
77
- clearInterval ( interval ) ;
78
-
79
- resolve ( ) ;
80
- }
81
- } , 100 ) ;
82
- } ) ;
83
-
84
- await page . goto ( `http://127.0.0.1:${ port } /test-two.html` , {
85
- waitUntil : "domcontentloaded" ,
86
- } ) ;
87
- await new Promise ( ( resolve ) => {
88
- const interval = setInterval ( ( ) => {
89
- console . log ( consoleMessages ) ;
90
- if ( consoleMessages . includes ( "Two." ) ) {
91
- clearInterval ( interval ) ;
92
-
93
- resolve ( ) ;
94
- }
95
- } , 100 ) ;
96
- } ) ;
97
-
98
- expect ( consoleMessages ) . toMatchSnapshot ( "console messages" ) ;
99
- expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
100
-
101
- await browser . close ( ) ;
102
- await server . stop ( ) ;
103
+ expect ( consoleMessages ) . toMatchSnapshot ( "console messages" ) ;
104
+ expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
105
+ } catch ( error ) {
106
+ throw error ;
107
+ } finally {
108
+ await browser . close ( ) ;
109
+ await server . stop ( ) ;
110
+ }
103
111
} ) ;
104
112
} ) ;
0 commit comments