Commit 9b7d4ec 1 parent c2cb9e7 commit 9b7d4ec Copy full SHA for 9b7d4ec
File tree 3 files changed +37
-6
lines changed
3 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -6,19 +6,30 @@ var debug = require('debug')('risingstack/trace')
6
6
7
7
var ConfigReader = require ( './utils/configReader' )
8
8
9
+ var traceNoop = {
10
+ report : function ( ) { } ,
11
+ reportError : function ( ) { } ,
12
+ getTransactionId : function ( ) { }
13
+ }
14
+
9
15
function Trace ( ) {
16
+ if ( process . env . NODE_ENV === 'test' ) {
17
+ return traceNoop
18
+ }
19
+
10
20
this . configReader = ConfigReader . create ( )
21
+
11
22
try {
12
23
this . config = this . configReader . getConfig ( )
13
24
} catch ( ex ) {
14
25
console . error ( format ( '%s trace: error: %s' , new Date ( ) , ex . message ) )
15
- return
26
+ return traceNoop
16
27
}
17
28
18
29
// warn the user if the newrelic agent is present as well
19
30
if ( require . cache . __NR_cache ) {
20
31
console . error ( 'Make sure to require Trace before New Relic, otherwise Trace won\'t start' )
21
- return
32
+ return traceNoop
22
33
}
23
34
24
35
this . agent = Agent . create ( {
Original file line number Diff line number Diff line change 1
1
var expect = require ( 'chai' ) . expect
2
+ var freshy = require ( 'freshy' )
2
3
3
4
var Agent = require ( './agent' )
4
5
var Instrumentation = require ( './instrumentations' )
5
6
var ConfigReader = require ( './utils/configReader' )
6
7
7
8
describe ( 'The trace module' , function ( ) {
9
+ beforeEach ( function ( ) {
10
+ freshy . unload ( './' )
11
+ } )
12
+
13
+ it ( 'doesn\'t start in NODE_ENV=test' , function ( ) {
14
+ this . sandbox . stub ( process , 'env' , {
15
+ NODE_ENV : 'test'
16
+ } )
17
+
18
+ var configReaderStub = this . sandbox . stub ( ConfigReader , 'create' )
19
+
20
+ var trace = require ( './' )
21
+ expect ( trace . report ) . to . be . a ( 'function' )
22
+ expect ( trace . reportError ) . to . be . a ( 'function' )
23
+ expect ( trace . getTransactionId ) . to . be . a ( 'function' )
24
+ expect ( configReaderStub ) . to . have . not . been . called
25
+ } )
26
+
8
27
it ( 'initializes' , function ( ) {
9
28
var fakeAgent = {
10
29
name : 'agent'
Original file line number Diff line number Diff line change 27
27
"scripts" : {
28
28
"preinstall" : " npm install node-gyp-install && node-gyp-install" ,
29
29
"lint" : " eslint lib example e2e" ,
30
- "test" : " NODE_ENV=test npm run test-unit && npm run test-e2e" ,
31
- "test-unit" : " NODE_ENV=test mocha $(find ./lib -name \" *.spec.js\" -not -path \" ./node_modules/*\" )" ,
32
- "test-cls" : " NODE_ENV=test mocha $(find ./lib -name \" *.spec.e2e.js\" -not -path \" ./node_modules/*\" )" ,
33
- "test-e2e" : " NODE_ENV=test node ./e2e | tap-spec" ,
30
+ "test" : " npm run test-unit && npm run test-e2e" ,
31
+ "test-unit" : " mocha $(find ./lib -name \" *.spec.js\" -not -path \" ./node_modules/*\" )" ,
32
+ "test-cls" : " mocha $(find ./lib -name \" *.spec.e2e.js\" -not -path \" ./node_modules/*\" )" ,
33
+ "test-e2e" : " node ./e2e | tap-spec" ,
34
34
"cover" : " istanbul cover _mocha $(find ./lib -name \" *.spec.js\" -not -path \" ./node_modules/*\" ); open coverage/lcov-report/index.html" ,
35
35
"changelog" : " conventional-changelog -p angular -o CHANGELOG.md -r 500" ,
36
36
"semantic-release" : " semantic-release pre && npm publish && semantic-release post"
70
70
"eslint-config-standard" : " 5.1.0" ,
71
71
"eslint-plugin-standard" : " 1.3.2" ,
72
72
"express" : " 4.13.4" ,
73
+ "fresh" : " 0.3.0" ,
73
74
"freshy" : " 1.0.2" ,
74
75
"ioredis" : " 1.15.1" ,
75
76
"istanbul" : " 0.4.2" ,
You can’t perform that action at this time.
0 commit comments