@@ -45,63 +45,65 @@ describe('test/aop-runtime.test.ts', () => {
4545 } ) ;
4646
4747 it ( 'should work' , async ( ) => {
48- const ctx = new EggTestContext ( ) ;
49- const hello = await CoreTestHelper . getObject ( Hello , ctx ) ;
50- const callTrace = await CoreTestHelper . getObject ( CallTrace ) ;
51- const msg = await hello . hello ( 'aop' ) ;
52- const traceMsg = callTrace . msgs ;
53- assert ( msg === 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))' ) ;
54- assert . deepStrictEqual ( traceMsg , [
55- {
56- className : 'CrosscutAdvice' ,
57- methodName : 'beforeCall' ,
58- id : 233 ,
59- name : 'aop' ,
60- } ,
61- {
62- className : 'PointcutAdvice' ,
63- methodName : 'beforeCall' ,
64- id : 233 ,
65- name : 'aop' ,
66- } ,
67- {
68- className : 'CrosscutAdvice' ,
69- methodName : 'afterReturn' ,
70- id : 233 ,
71- name : 'withPointAroundParam(withCrosscutAroundParam(aop))' ,
72- result : 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))' ,
73- } ,
74- {
75- className : 'PointcutAdvice' ,
76- methodName : 'afterReturn' ,
77- id : 233 ,
78- name : 'withPointAroundParam(withCrosscutAroundParam(aop))' ,
79- result : 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))' ,
80- } ,
81- {
82- className : 'CrosscutAdvice' ,
83- methodName : 'afterFinally' ,
84- id : 233 ,
85- name : 'withPointAroundParam(withCrosscutAroundParam(aop))' ,
86- } ,
87- {
88- className : 'PointcutAdvice' ,
89- methodName : 'afterFinally' ,
90- id : 233 ,
91- name : 'withPointAroundParam(withCrosscutAroundParam(aop))' ,
92- } ,
93- ] ) ;
48+ await EggTestContext . mockContext ( async ( ) => {
49+ const hello = await CoreTestHelper . getObject ( Hello ) ;
50+ const callTrace = await CoreTestHelper . getObject ( CallTrace ) ;
51+ const msg = await hello . hello ( 'aop' ) ;
52+ const traceMsg = callTrace . msgs ;
53+ assert ( msg === 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))' ) ;
54+ assert . deepStrictEqual ( traceMsg , [
55+ {
56+ className : 'CrosscutAdvice' ,
57+ methodName : 'beforeCall' ,
58+ id : 233 ,
59+ name : 'aop' ,
60+ } ,
61+ {
62+ className : 'PointcutAdvice' ,
63+ methodName : 'beforeCall' ,
64+ id : 233 ,
65+ name : 'aop' ,
66+ } ,
67+ {
68+ className : 'CrosscutAdvice' ,
69+ methodName : 'afterReturn' ,
70+ id : 233 ,
71+ name : 'withPointAroundParam(withCrosscutAroundParam(aop))' ,
72+ result : 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))' ,
73+ } ,
74+ {
75+ className : 'PointcutAdvice' ,
76+ methodName : 'afterReturn' ,
77+ id : 233 ,
78+ name : 'withPointAroundParam(withCrosscutAroundParam(aop))' ,
79+ result : 'withCrossAroundResult(withPointAroundResult(hello withPointAroundParam(withCrosscutAroundParam(aop))))' ,
80+ } ,
81+ {
82+ className : 'CrosscutAdvice' ,
83+ methodName : 'afterFinally' ,
84+ id : 233 ,
85+ name : 'withPointAroundParam(withCrosscutAroundParam(aop))' ,
86+ } ,
87+ {
88+ className : 'PointcutAdvice' ,
89+ methodName : 'afterFinally' ,
90+ id : 233 ,
91+ name : 'withPointAroundParam(withCrosscutAroundParam(aop))' ,
92+ } ,
93+ ] ) ;
94+ } ) ;
9495 } ) ;
9596
9697 it ( 'mock should work' , async ( ) => {
97- const ctx = new EggTestContext ( ) ;
98- const hello = await CoreTestHelper . getObject ( Hello , ctx ) ;
99- let helloMocked = false ;
100- mm ( Hello . prototype , 'hello' , async ( ) => {
101- helloMocked = true ;
98+ await EggTestContext . mockContext ( async ( ) => {
99+ const hello = await CoreTestHelper . getObject ( Hello ) ;
100+ let helloMocked = false ;
101+ mm ( Hello . prototype , 'hello' , async ( ) => {
102+ helloMocked = true ;
103+ } ) ;
104+ await hello . hello ( 'aop' ) ;
105+ assert ( helloMocked === true ) ;
102106 } ) ;
103- await hello . hello ( 'aop' ) ;
104- assert ( helloMocked === true ) ;
105107 } ) ;
106108 } ) ;
107109
0 commit comments