1+ /**
2+ * Copyright 2018 Google Inc. All Rights Reserved.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ import { ConsoleExporter , Exporter , Tracer , TracerImpl , Tracing } from '@opencensus/opencensus-core' ;
18+ import * as assert from 'assert' ;
19+
20+ import { TracingImpl } from '../src/trace/tracing' ;
21+
22+ describe ( 'Tracing' , ( ) => {
23+ /** Should create a Tracing instance */
24+ describe ( 'new Tracing()' , ( ) => {
25+ it ( 'should create a Tracer instance' , ( ) => {
26+ const tracing = new TracingImpl ( ) ;
27+ assert . ok ( tracing instanceof TracingImpl ) ;
28+ } ) ;
29+ } ) ;
30+
31+ /** Should get the singleton trancing instance. */
32+ describe ( 'static get instance()' , ( ) => {
33+ it ( 'should get the singleton trancing instance' , ( ) => {
34+ const tracing = TracingImpl . instance ;
35+ assert . ok ( tracing instanceof TracingImpl ) ;
36+ } ) ;
37+ } ) ;
38+
39+ /** Should return a started tracing instance */
40+ describe ( 'start()' , ( ) => {
41+ let tracingStarted : Tracing ;
42+ before ( ( ) => {
43+ const tracing = new TracingImpl ( ) ;
44+ tracingStarted = tracing . start ( ) ;
45+ } ) ;
46+ it ( 'should return a tracing instance' , ( ) => {
47+ assert . ok ( tracingStarted instanceof TracingImpl ) ;
48+ } ) ;
49+
50+ it ( 'the tracing was started' , ( ) => {
51+ assert . ok ( tracingStarted . tracer . active ) ;
52+ } ) ;
53+ } ) ;
54+
55+ /** Should stop the tracing instance */
56+ describe ( 'stop()' , ( ) => {
57+ it ( 'should stop the tracing instance' , ( ) => {
58+ const tracing = new TracingImpl ( ) ;
59+ tracing . start ( ) ;
60+ tracing . stop ( ) ;
61+ assert . ok ( ! tracing . tracer . active ) ;
62+ } ) ;
63+ } ) ;
64+
65+ /** Should get the tracer instance */
66+ describe ( 'get tracer()' , ( ) => {
67+ it ( 'should get the tracer instance' , ( ) => {
68+ const tracing = new TracingImpl ( ) ;
69+ tracing . start ( ) ;
70+ const tracer = tracing . tracer ;
71+ assert . ok ( tracer instanceof TracerImpl ) ;
72+ } ) ;
73+ } ) ;
74+
75+ /** Should get the exporter instance */
76+ describe ( 'get exporter()' , ( ) => {
77+ it ( 'should get the exporter instance' , ( ) => {
78+ const tracing = new TracingImpl ( ) ;
79+ tracing . start ( ) ;
80+ const exporter = tracing . exporter ;
81+ assert . ok ( exporter instanceof ConsoleExporter ) ;
82+ } ) ;
83+ } ) ;
84+
85+ /** Should get the exporter instance */
86+ describe ( 'registerExporter()' , ( ) => {
87+ it ( 'should register the exporter on tracer' , ( ) => {
88+ const tracing = new TracingImpl ( ) ;
89+ tracing . start ( ) ;
90+ const exporter = tracing . exporter ;
91+ tracing . registerExporter ( exporter ) ;
92+ assert . equal ( tracing . tracer . eventListeners . length , 2 ) ;
93+ } ) ;
94+ } ) ;
95+ } ) ;
0 commit comments