@@ -32,6 +32,7 @@ Enzyme.configure({ adapter: new Adapter() })
32
32
import { getWithTransaction } from '../../src/get-with-transaction'
33
33
import { ApmBase } from '@elastic/apm-rum'
34
34
import { createServiceFactory } from '@elastic/apm-rum-core'
35
+ import { getGlobalConfig } from '../../../../dev-utils/test-config'
35
36
36
37
function TestComponent ( apm ) {
37
38
const withTransaction = getWithTransaction ( apm )
@@ -51,26 +52,30 @@ function TestComponent(apm) {
51
52
}
52
53
53
54
describe ( 'withTransaction' , function ( ) {
55
+ const { serverUrl, serviceName } = getGlobalConfig ( ) . agentConfig
56
+ let apmBase , serviceFactory
57
+
58
+ beforeEach ( ( ) => {
59
+ serviceFactory = createServiceFactory ( )
60
+ apmBase = new ApmBase ( serviceFactory , false )
61
+ apmBase . init ( {
62
+ active : true ,
63
+ serverUrl,
64
+ serviceName,
65
+ disableInstrumentations : [ 'page-load' , 'error' ]
66
+ } )
67
+ } )
68
+
54
69
it ( 'should work if apm is disabled or not initialized' , function ( ) {
55
- TestComponent ( new ApmBase ( createServiceFactory ( ) , true ) )
56
- TestComponent ( new ApmBase ( createServiceFactory ( ) , false ) )
70
+ TestComponent ( new ApmBase ( serviceFactory , true ) )
71
+ TestComponent ( apmBase )
57
72
} )
58
73
59
74
it ( 'should start transaction for components' , function ( ) {
60
- const serviceFactory = createServiceFactory ( )
61
75
const transactionService = serviceFactory . getService ( 'TransactionService' )
62
-
63
- var apm = new ApmBase ( serviceFactory , false )
64
- apm . init ( {
65
- debug : true ,
66
- serverUrl : 'http://localhost:8200' ,
67
- serviceName : 'apm-agent-rum-react-integration-unit-test' ,
68
- sendPageLoadTransaction : false
69
- } )
70
-
71
76
spyOn ( transactionService , 'startTransaction' )
72
77
73
- TestComponent ( apm )
78
+ TestComponent ( apmBase )
74
79
expect ( transactionService . startTransaction ) . toHaveBeenCalledWith (
75
80
'test-transaction' ,
76
81
'test-type' ,
@@ -79,16 +84,33 @@ describe('withTransaction', function() {
79
84
} )
80
85
81
86
it ( 'should return WrappedComponent on falsy value and log warning' , function ( ) {
82
- const serviceFactory = createServiceFactory ( )
83
87
const loggingService = serviceFactory . getService ( 'LoggingService' )
84
-
85
88
spyOn ( loggingService , 'warn' )
86
89
87
- const withTransaction = getWithTransaction ( new ApmBase ( serviceFactory ) )
90
+ const withTransaction = getWithTransaction ( apmBase )
88
91
const comp = withTransaction ( 'test-name' , 'test-type' ) ( undefined )
89
92
expect ( comp ) . toBe ( undefined )
90
93
expect ( loggingService . warn ) . toHaveBeenCalledWith (
91
94
'test-name is not instrumented since component property is not provided'
92
95
)
93
96
} )
97
+
98
+ it ( 'should not instrument the route when rum is inactive' , ( ) => {
99
+ const transactionService = serviceFactory . getService ( 'TransactionService' )
100
+ spyOn ( transactionService , 'startTransaction' )
101
+
102
+ apmBase . config ( { active : false } )
103
+ TestComponent ( apmBase )
104
+
105
+ function Component ( ) {
106
+ return < h2 > Component</ h2 >
107
+ }
108
+ const withTransaction = getWithTransaction ( apmBase )
109
+
110
+ const WrappedComponent = withTransaction ( 'test-transaction' , 'test-type' ) (
111
+ Component
112
+ )
113
+ expect ( WrappedComponent ) . toEqual ( Component )
114
+ expect ( transactionService . startTransaction ) . not . toHaveBeenCalled ( )
115
+ } )
94
116
} )
0 commit comments