File tree 5 files changed +52
-4
lines changed
5 files changed +52
-4
lines changed Original file line number Diff line number Diff line change @@ -46,11 +46,11 @@ in the project root.
46
46
47
47
## Running the Test Suite
48
48
49
- You can run all test at once by calling ` yarn test ` in the project root or in individual sub packages.
49
+ You can run all test at once by calling ` yarn test ` in the project root or in individual sub packages. Note that you must run ` yarn build ` before the test command will work.
50
50
51
51
## Lint
52
52
53
- You can run all test at once by calling ` yarn lint ` in the project root or in individual sub packages.
53
+ You can run all test at once by calling ` yarn lint ` in the project root or in individual sub packages. Note that you must run ` yarn build ` before the lint command will work.
54
54
55
55
## Contributing Back Code
56
56
Original file line number Diff line number Diff line change 1
1
import { getCurrentHub , initAndBind , Integrations as CoreIntegrations } from '@sentry/core' ;
2
+ import { getGlobalObject } from '@sentry/utils' ;
2
3
3
4
import { BrowserOptions } from './backend' ;
4
5
import { BrowserClient , ReportDialogOptions } from './client' ;
@@ -76,6 +77,13 @@ export function init(options: BrowserOptions = {}): void {
76
77
if ( options . defaultIntegrations === undefined ) {
77
78
options . defaultIntegrations = defaultIntegrations ;
78
79
}
80
+ if ( options . release === undefined ) {
81
+ const window = getGlobalObject < Window > ( ) as any ;
82
+ // This supports the variable that sentry-webpack-plugin injects
83
+ if ( window . SENTRY_RELEASE && window . SENTRY_RELEASE . id ) {
84
+ options . release = window . SENTRY_RELEASE . id ;
85
+ }
86
+ }
79
87
initAndBind ( BrowserClient , options ) ;
80
88
}
81
89
Original file line number Diff line number Diff line change @@ -166,3 +166,19 @@ describe('SentryBrowser', () => {
166
166
} ) ;
167
167
} ) ;
168
168
} ) ;
169
+
170
+
171
+ describe ( 'SentryBrowser initialization' , ( ) => {
172
+ it ( 'should use window.SENTRY_RELEASE to set release on initialization if available' , ( ) => {
173
+ global . SENTRY_RELEASE = { id : 'foobar' } ;
174
+ init ( { dsn } ) ;
175
+ expect ( global . __SENTRY__ . hub . _stack [ 0 ] . client . getOptions ( ) . release ) . to . equal ( 'foobar' ) ;
176
+ // Manually tear down global set. Is there a nicer way to do this?
177
+ global . SENTRY_RELEASE = undefined ;
178
+ } ) ;
179
+ it ( 'should have initialization proceed as normal if window.SENTRY_RELEASE is not set' , ( ) => {
180
+ // This is mostly a happy-path test to ensure that the initialization doesn't throw an error.
181
+ init ( { dsn } ) ;
182
+ expect ( global . __SENTRY__ . hub . _stack [ 0 ] . client . getOptions ( ) . release ) . to . be . undefined ;
183
+ } ) ;
184
+ } )
Original file line number Diff line number Diff line change 1
1
import { getCurrentHub , initAndBind , Integrations as CoreIntegrations } from '@sentry/core' ;
2
2
import { getMainCarrier , setHubOnCarrier } from '@sentry/hub' ;
3
+ import { getGlobalObject } from '@sentry/utils' ;
3
4
import * as domain from 'domain' ;
4
5
5
6
import { NodeOptions } from './backend' ;
@@ -84,8 +85,16 @@ export function init(options: NodeOptions = {}): void {
84
85
options . dsn = process . env . SENTRY_DSN ;
85
86
}
86
87
87
- if ( options . release === undefined && process . env . SENTRY_RELEASE ) {
88
- options . release = process . env . SENTRY_RELEASE ;
88
+ if ( options . release === undefined ) {
89
+ const global = getGlobalObject < Window > ( ) as any ;
90
+ // Prefer env var over global
91
+ if ( process . env . SENTRY_RELEASE ) {
92
+ options . release = process . env . SENTRY_RELEASE ;
93
+ }
94
+ // This supports the variable that sentry-webpack-plugin injects
95
+ else if ( global . SENTRY_RELEASE && global . SENTRY_RELEASE . id ) {
96
+ options . release = global . SENTRY_RELEASE . id ;
97
+ }
89
98
}
90
99
91
100
if ( options . environment === undefined && process . env . SENTRY_ENVIRONMENT ) {
Original file line number Diff line number Diff line change @@ -238,3 +238,18 @@ describe('SentryNode', () => {
238
238
} ) ;
239
239
} ) ;
240
240
} ) ;
241
+
242
+ describe ( 'SentryNode initialization' , ( ) => {
243
+ test ( 'global.SENTRY_RELEASE is used to set release on initialization if available' , ( ) => {
244
+ global . SENTRY_RELEASE = { id : 'foobar' } ;
245
+ init ( { dsn } ) ;
246
+ expect ( global . __SENTRY__ . hub . _stack [ 0 ] . client . getOptions ( ) . release ) . toEqual ( 'foobar' ) ;
247
+ // Unsure if this is needed under jest.
248
+ global . SENTRY_RELEASE = undefined ;
249
+ } ) ;
250
+ test ( 'initialization proceeds as normal if global.SENTRY_RELEASE is not set' , ( ) => {
251
+ // This is mostly a happy-path test to ensure that the initialization doesn't throw an error.
252
+ init ( { dsn } ) ;
253
+ expect ( global . __SENTRY__ . hub . _stack [ 0 ] . client . getOptions ( ) . release ) . toBeUndefined ( ) ;
254
+ } ) ;
255
+ } )
You can’t perform that action at this time.
0 commit comments