1
- import { masterSelection } from '#3p/ampcontext-integration' ;
1
+ import { IntegrationAmpContext , masterSelection } from '#3p/ampcontext-integration' ;
2
2
3
3
describes . fakeWin ( '#masterSelect' , { } , ( env ) => {
4
4
it ( 'should allow sharing between configured networks' , ( ) =>
@@ -11,54 +11,48 @@ describes.sandboxed('IntegrationAmpContext aliases', {}, (env) => {
11
11
let context ;
12
12
13
13
beforeEach ( ( ) => {
14
- // Create a minimal context object that implements the needed methods
15
- context = {
16
- master_ : env . sandbox . stub ( ) . returns ( 'master-window' ) ,
17
- isMaster_ : env . sandbox . stub ( ) . returns ( true ) ,
18
- computeInMasterFrame : env . sandbox . stub ( ) ,
19
- } ;
20
-
21
- // Apply the getters from IntegrationAmpContext prototype
22
- Object . defineProperty ( context , 'coordinator' , {
23
- get ( ) {
24
- return this . master_ ( ) ;
25
- } ,
26
- } ) ;
27
- Object . defineProperty ( context , 'isCoordinator' , {
28
- get ( ) {
29
- return this . isMaster_ ( ) ;
30
- } ,
31
- } ) ;
32
- context . computeInCoordinatingFrame = function ( global , taskId , work , cb ) {
33
- return this . computeInMasterFrame ( global , taskId , work , cb ) ;
34
- } ;
14
+ context = Object . create ( IntegrationAmpContext . prototype ) ;
15
+ context . master_ = env . sandbox . stub ( ) . returns ( 'test-master-window' ) ;
16
+ context . isMaster_ = env . sandbox . stub ( ) . returns ( true ) ;
17
+ context . computeInMasterFrame = env . sandbox . stub ( ) ;
35
18
} ) ;
36
19
37
20
it ( 'should delegate coordinator to master' , ( ) => {
38
21
const result = context . coordinator ;
22
+
39
23
expect ( context . master_ ) . to . have . been . calledOnce ;
40
- expect ( result ) . to . equal ( 'master-window' ) ;
24
+ expect ( result ) . to . equal ( 'test- master-window' ) ;
41
25
} ) ;
42
26
43
27
it ( 'should delegate isCoordinator to isMaster' , ( ) => {
44
28
const result = context . isCoordinator ;
29
+
45
30
expect ( context . isMaster_ ) . to . have . been . calledOnce ;
46
31
expect ( result ) . to . equal ( true ) ;
47
32
} ) ;
48
33
49
- it ( 'should delegate computeInCoordinatingFrame to computeInMasterFrame' , ( ) => {
50
- const global = { test : 'global' } ;
34
+ it ( 'should execute computeInCoordinatingFrame method' , ( ) => {
35
+ const masterWindow = { __ampMasterTasks : { } } ;
36
+ const global = {
37
+ context : {
38
+ master : masterWindow ,
39
+ isMaster : true ,
40
+ } ,
41
+ } ;
51
42
const taskId = 'test-task' ;
52
- const work = ( ) => { } ;
53
- const cb = ( ) => { } ;
43
+ let workCalled = false ;
44
+ const work = ( done ) => {
45
+ workCalled = true ;
46
+ done ( 'result' ) ;
47
+ } ;
48
+ let callbackResult ;
49
+ const cb = ( result ) => {
50
+ callbackResult = result ;
51
+ } ;
54
52
55
53
context . computeInCoordinatingFrame ( global , taskId , work , cb ) ;
56
54
57
- expect ( context . computeInMasterFrame ) . to . have . been . calledOnceWith (
58
- global ,
59
- taskId ,
60
- work ,
61
- cb
62
- ) ;
55
+ expect ( workCalled ) . to . be . true ;
56
+ expect ( callbackResult ) . to . equal ( 'result' ) ;
63
57
} ) ;
64
58
} ) ;
0 commit comments