16
16
*/
17
17
import { it , expect } from './fixtures' ;
18
18
19
- it ( 'expose binding should work' , async ( { browser} ) => {
20
- const context = await browser . newContext ( ) ;
19
+ it ( 'expose binding should work' , async ( { context} ) => {
21
20
let bindingSource ;
22
21
await context . exposeBinding ( 'add' , ( source , a , b ) => {
23
22
bindingSource = source ;
@@ -29,11 +28,9 @@ it('expose binding should work', async ({browser}) => {
29
28
expect ( bindingSource . page ) . toBe ( page ) ;
30
29
expect ( bindingSource . frame ) . toBe ( page . mainFrame ( ) ) ;
31
30
expect ( result ) . toEqual ( 11 ) ;
32
- await context . close ( ) ;
33
31
} ) ;
34
32
35
- it ( 'should work' , async ( { browser, server} ) => {
36
- const context = await browser . newContext ( ) ;
33
+ it ( 'should work' , async ( { context, server} ) => {
37
34
await context . exposeFunction ( 'add' , ( a , b ) => a + b ) ;
38
35
const page = await context . newPage ( ) ;
39
36
await page . exposeFunction ( 'mul' , ( a , b ) => a * b ) ;
@@ -44,11 +41,9 @@ it('should work', async ({browser, server}) => {
44
41
} ) ;
45
42
const result = await page . evaluate ( '(async () => ({ mul: await mul(9, 4), add: await add(9, 4), sub: await sub(9, 4), addHandle: await addHandle(5, 6) }))()' ) ;
46
43
expect ( result ) . toEqual ( { mul : 36 , add : 13 , sub : 5 , addHandle : 11 } ) ;
47
- await context . close ( ) ;
48
44
} ) ;
49
45
50
- it ( 'should throw for duplicate registrations' , async ( { browser, server} ) => {
51
- const context = await browser . newContext ( ) ;
46
+ it ( 'should throw for duplicate registrations' , async ( { context, server} ) => {
52
47
await context . exposeFunction ( 'foo' , ( ) => { } ) ;
53
48
await context . exposeFunction ( 'bar' , ( ) => { } ) ;
54
49
let error = await context . exposeFunction ( 'foo' , ( ) => { } ) . catch ( e => e ) ;
@@ -59,11 +54,9 @@ it('should throw for duplicate registrations', async ({browser, server}) => {
59
54
await page . exposeFunction ( 'baz' , ( ) => { } ) ;
60
55
error = await context . exposeFunction ( 'baz' , ( ) => { } ) . catch ( e => e ) ;
61
56
expect ( error . message ) . toContain ( 'Function "baz" has been already registered in one of the pages' ) ;
62
- await context . close ( ) ;
63
57
} ) ;
64
58
65
- it ( 'should be callable from-inside addInitScript' , async ( { browser, server} ) => {
66
- const context = await browser . newContext ( ) ;
59
+ it ( 'should be callable from-inside addInitScript' , async ( { context, server} ) => {
67
60
let args = [ ] ;
68
61
await context . exposeFunction ( 'woof' , function ( arg ) {
69
62
args . push ( arg ) ;
@@ -74,11 +67,9 @@ it('should be callable from-inside addInitScript', async ({browser, server}) =>
74
67
args = [ ] ;
75
68
await page . reload ( ) ;
76
69
expect ( args ) . toEqual ( [ 'context' , 'page' ] ) ;
77
- await context . close ( ) ;
78
70
} ) ;
79
71
80
- it ( 'exposeBindingHandle should work' , async ( { browser} ) => {
81
- const context = await browser . newContext ( ) ;
72
+ it ( 'exposeBindingHandle should work' , async ( { context} ) => {
82
73
let target ;
83
74
await context . exposeBinding ( 'logme' , ( source , t ) => {
84
75
target = t ;
@@ -90,5 +81,4 @@ it('exposeBindingHandle should work', async ({browser}) => {
90
81
} ) ;
91
82
expect ( await target . evaluate ( x => x . foo ) ) . toBe ( 42 ) ;
92
83
expect ( result ) . toEqual ( 17 ) ;
93
- await context . close ( ) ;
94
84
} ) ;
0 commit comments