@@ -26,75 +26,88 @@ let tracer = new TracerImpl();
2626
2727describe ( 'Span' , function ( ) {
2828 /**
29- * Should create, start and end a rootspan
29+ * Should create a span
3030 */
31- describe ( 'startSpan ()' , function ( ) {
32- it ( 'should create an span ' , function ( ) {
31+ describe ( 'new Span ()' , function ( ) {
32+ it ( 'should create a Span instance ' , function ( ) {
3333 const rootSpan = new RootSpanImpl ( tracer ) ;
34- assert . ok ( rootSpan instanceof SpanImpl ) ;
34+ const span = new SpanImpl ( rootSpan ) ;
35+ assert . ok ( span instanceof SpanImpl ) ;
36+ } ) ;
37+ } ) ;
3538
39+ /**
40+ * Should return the Trace ID
41+ */
42+ describe ( 'get traceId()' , function ( ) {
43+ it ( 'should return the trace id' , function ( ) {
44+ const rootSpan = new RootSpanImpl ( tracer ) ;
3645 rootSpan . start ( ) ;
37- const span = rootSpan . startSpan ( 'spanName' , 'typeSpan' ) ;
38- assert . ok ( span instanceof SpanImpl ) ;
39- assert . ok ( span . id ) ;
46+ const span = new SpanImpl ( rootSpan ) ;
47+ assert . equal ( span . traceId , rootSpan . traceId ) ;
4048 } ) ;
49+ } ) ;
4150
42- it ( 'should start a span' , function ( ) {
51+ /**
52+ * Should the trace context of span
53+ */
54+ describe ( 'get traceContext()' , function ( ) {
55+ it ( 'should the trace context of span' , function ( ) {
4356 const rootSpan = new RootSpanImpl ( tracer ) ;
4457 rootSpan . start ( ) ;
45- const span = rootSpan . startSpan ( 'spanName' , 'typeSpan' ) ;
46- span . start ( ) ;
47- assert . ok ( span . started ) ;
58+
59+ const span = new SpanImpl ( rootSpan ) ;
60+ const context = span . traceContext ;
61+
62+ assert . equal ( context . traceId , rootSpan . traceId ) ;
63+ assert . equal ( context . spanId , span . id ) ;
64+ assert . equal ( context . options , 1 ) ;
4865 } ) ;
66+ } ) ;
4967
50- it ( 'should end a span' , function ( ) {
68+ /**
69+ * Should start a span instance
70+ */
71+ describe ( 'start()' , function ( ) {
72+ it ( 'should start a span instance' , function ( ) {
5173 const rootSpan = new RootSpanImpl ( tracer ) ;
5274 rootSpan . start ( ) ;
53- const span = rootSpan . startSpan ( 'spanName' , 'typeSpan' ) ;
75+
76+ const span = new SpanImpl ( rootSpan ) ;
5477 span . start ( ) ;
55- span . end ( ) ;
56- assert . ok ( span . ended ) ;
78+
79+ assert . ok ( span . started ) ;
5780 } ) ;
5881 } ) ;
5982
6083 /**
61- * Should not start span after it ended
84+ * Should end a span instance
6285 */
63- describe ( 'Span checking after creation' , function ( ) {
64- it ( 'should not start span after it ended' , function ( ) {
65- const root = new RootSpanImpl ( tracer ) ;
66- root . start ( ) ;
67- const span = root . startSpan ( 'spanName' , 'typeSpan' ) ;
86+ describe ( 'end()' , function ( ) {
87+ it ( 'should end a span instance' , function ( ) {
88+ const rootSpan = new RootSpanImpl ( tracer ) ;
89+ rootSpan . start ( ) ;
90+
91+ const span = new SpanImpl ( rootSpan ) ;
6892 span . start ( ) ;
6993 span . end ( ) ;
7094
71- span . start ( ) ;
72- assert . equal ( span . ended , true ) ;
95+ assert . ok ( span . ended ) ;
7396 } ) ;
7497 } ) ;
7598
7699 /**
77- * Should an unique ID for spans
100+ * Should not end a span instance
78101 */
79- describe ( 'Span data' , function ( ) {
80- it ( 'should create an unique numeric span ID strings' , function ( ) {
81- const root = new RootSpanImpl ( tracer ) ;
82- root . start ( ) ;
83-
84- var numberOfSpansToCheck = 5 ;
85- for ( var i = 0 ; i < numberOfSpansToCheck ; i ++ ) {
86- var span = root . startSpan ( 'spanName' + i , 'typeSpan' + i ) ;
87- var spanId = span . id ;
88- assert . ok ( typeof spanId === 'string' ) ;
89- assert . ok ( spanId . match ( / \d + / ) ) ;
90- assert . ok ( Number ( spanId ) > 0 ) ;
91- assert . strictEqual ( Number ( spanId ) . toString ( ) , spanId ) ;
92- }
93- } ) ;
102+ describe ( 'end() before start the span' , function ( ) {
103+ it ( 'should not end a span instance' , function ( ) {
104+ const rootSpan = new RootSpanImpl ( tracer ) ;
105+ rootSpan . start ( ) ;
106+
107+ const span = new SpanImpl ( rootSpan ) ;
108+ span . end ( ) ;
94109
95- // TODO
96- it ( 'should truncate namespace' , function ( ) {
97- this . skip ( ) ;
110+ assert . ok ( ! span . ended ) ;
98111 } ) ;
99112 } ) ;
100113} ) ;
0 commit comments