@@ -20,6 +20,7 @@ import { Tracer } from '../src/trace/model/tracer';
2020describe ( 'Tracer' , ( ) => {
2121 let tracer : Tracer ;
2222 let listener : webTypes . SpanEventListener ;
23+ const options = { name : 'test' } ;
2324
2425 beforeEach ( ( ) => {
2526 tracer = new Tracer ( ) ;
@@ -30,19 +31,38 @@ describe('Tracer', () => {
3031 tracer . eventListeners = [ listener ] ;
3132 } ) ;
3233
34+ /** Should get/set the current RootSpan from tracer instance */
35+ describe ( 'get/set currentRootSpan()' , ( ) => {
36+ it ( 'should get the current RootSpan from tracer instance' , ( ) => {
37+ tracer . startRootSpan ( options , root => {
38+ expect ( root ) . toBeTruthy ( ) ;
39+ expect ( root ) . toBe ( tracer . currentRootSpan ) ;
40+ } ) ;
41+ } ) ;
42+ } ) ;
43+
3344 describe ( 'startRootSpan' , ( ) => {
34- it ( 'sets current root span and calls function with it' , ( ) => {
35- const onStartFn = jasmine . createSpy ( 'onStartFn' ) ;
45+ it ( 'should create a new RootSpan instance' , ( ) => {
46+ tracer . startRootSpan ( options , rootSpan => {
47+ expect ( rootSpan ) . toBeTruthy ( ) ;
48+ } ) ;
49+ } ) ;
50+ it ( 'sets current root span' , ( ) => {
3651 const oldRoot = tracer . currentRootSpan ;
3752
38- tracer . startRootSpan ( { name : 'root1' } , onStartFn ) ;
39-
40- expect ( onStartFn ) . toHaveBeenCalled ( ) ;
41- const onStartRoot = onStartFn . calls . argsFor ( 0 ) [ 0 ] ;
42- expect ( onStartRoot . name ) . toBe ( 'root1' ) ;
43- expect ( onStartRoot ) . not . toBe ( oldRoot ) ;
44- expect ( tracer . currentRootSpan ) . toBe ( onStartRoot ) ;
45- expect ( listener . onStartSpan ) . toHaveBeenCalledWith ( onStartRoot ) ;
53+ tracer . startRootSpan ( options , rootSpan => {
54+ expect ( rootSpan . name ) . toBe ( 'test' ) ;
55+ expect ( rootSpan ) . not . toBe ( oldRoot ) ;
56+ expect ( tracer . currentRootSpan ) . toBe ( rootSpan ) ;
57+ expect ( listener . onStartSpan ) . toHaveBeenCalledWith ( rootSpan ) ;
58+ } ) ;
59+ } ) ;
60+ it ( 'should create a new Zone and RootSpan an associated to the zone' , ( ) => {
61+ tracer . startRootSpan ( options , rootSpan => {
62+ expect ( rootSpan ) . toBeTruthy ( ) ;
63+ expect ( Zone . current ) . not . toBe ( Zone . root ) ;
64+ expect ( Zone . current . get ( 'data' ) . rootSpan ) . toBe ( rootSpan ) ;
65+ } ) ;
4666 } ) ;
4767 } ) ;
4868
@@ -55,14 +75,19 @@ describe('Tracer', () => {
5575 } ) ;
5676
5777 describe ( 'startChildSpan' , ( ) => {
78+ let rootSpanLocal : webTypes . Span ;
79+ let span : webTypes . Span ;
5880 it ( 'starts a child span of the current root span' , ( ) => {
59- spyOn ( tracer . currentRootSpan , 'startChildSpan' ) ;
60- tracer . startChildSpan ( { name : 'child1' , kind : webTypes . SpanKind . CLIENT } ) ;
61- expect ( tracer . currentRootSpan . startChildSpan ) . toHaveBeenCalledWith ( {
62- childOf : tracer . currentRootSpan ,
63- name : 'child1' ,
64- kind : webTypes . SpanKind . CLIENT ,
81+ tracer . startRootSpan ( options , rootSpan => {
82+ rootSpanLocal = rootSpan ;
83+ span = tracer . startChildSpan ( {
84+ name : 'child1' ,
85+ kind : webTypes . SpanKind . CLIENT ,
86+ } ) ;
6587 } ) ;
88+ expect ( span ) . toBeTruthy ( ) ;
89+ expect ( rootSpanLocal . numberOfChildren ) . toBe ( 1 ) ;
90+ expect ( rootSpanLocal . spans [ 0 ] ) . toBe ( span ) ;
6691 } ) ;
6792 } ) ;
6893
0 commit comments