File tree Expand file tree Collapse file tree 6 files changed +84
-9
lines changed
dev-packages/browser-integration-tests
packages/integration-shims/src Expand file tree Collapse file tree 6 files changed +84
-9
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 1
1
import { expect } from '@playwright/test' ;
2
2
3
- import { sentryTest } from '../../utils/fixtures' ;
4
- import { getFirstSentryEnvelopeRequest , properEnvelopeRequestParser } from '../../utils/helpers' ;
3
+ import { sentryTest } from '../../../utils/fixtures' ;
4
+ import {
5
+ getFirstSentryEnvelopeRequest ,
6
+ properEnvelopeRequestParser ,
7
+ shouldSkipMetricsTest ,
8
+ } from '../../../utils/helpers' ;
5
9
6
10
sentryTest ( 'collects metrics' , async ( { getLocalTestUrl, page } ) => {
11
+ if ( shouldSkipMetricsTest ( ) ) {
12
+ sentryTest . skip ( ) ;
13
+ }
14
+
7
15
const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
8
16
9
17
const statsdBuffer = await getFirstSentryEnvelopeRequest < Uint8Array > ( page , url , properEnvelopeRequestParser ) ;
Original file line number Diff line number Diff line change
1
+ import * as Sentry from '@sentry/browser' ;
2
+
3
+ window . Sentry = Sentry ;
4
+
5
+ Sentry . init ( {
6
+ dsn :
'https://[email protected] /1337' ,
7
+ } ) ;
8
+
9
+ // This should not fail
10
+ Sentry . metrics . increment ( 'increment' ) ;
11
+ Sentry . metrics . distribution ( 'distribution' , 42 ) ;
12
+ Sentry . metrics . gauge ( 'gauge' , 5 ) ;
13
+ Sentry . metrics . set ( 'set' , 'nope' ) ;
Original file line number Diff line number Diff line change
1
+ import { expect } from '@playwright/test' ;
2
+
3
+ import { sentryTest } from '../../../utils/fixtures' ;
4
+ import { shouldSkipMetricsTest } from '../../../utils/helpers' ;
5
+
6
+ sentryTest ( 'exports shim metrics integration for non-tracing bundles' , async ( { getLocalTestPath, page } ) => {
7
+ // Skip in tracing tests
8
+ if ( ! shouldSkipMetricsTest ( ) ) {
9
+ sentryTest . skip ( ) ;
10
+ }
11
+
12
+ const consoleMessages : string [ ] = [ ] ;
13
+ page . on ( 'console' , msg => consoleMessages . push ( msg . text ( ) ) ) ;
14
+
15
+ let requestCount = 0 ;
16
+ await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
17
+ requestCount ++ ;
18
+ return route . fulfill ( {
19
+ status : 200 ,
20
+ contentType : 'application/json' ,
21
+ body : JSON . stringify ( { id : 'test-id' } ) ,
22
+ } ) ;
23
+ } ) ;
24
+
25
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
26
+
27
+ await page . goto ( url ) ;
28
+
29
+ expect ( requestCount ) . toBe ( 0 ) ;
30
+ expect ( consoleMessages ) . toEqual ( [
31
+ 'You are using metrics even though this bundle does not include tracing.' ,
32
+ 'You are using metrics even though this bundle does not include tracing.' ,
33
+ 'You are using metrics even though this bundle does not include tracing.' ,
34
+ 'You are using metrics even though this bundle does not include tracing.' ,
35
+ ] ) ;
36
+ } ) ;
Original file line number Diff line number Diff line change @@ -241,7 +241,7 @@ export function shouldSkipTracingTest(): boolean {
241
241
}
242
242
243
243
/**
244
- * We can only test replay tests in certain bundles/packages:
244
+ * We can only test feedback tests in certain bundles/packages:
245
245
* - NPM (ESM, CJS)
246
246
* - CDN bundles that contain the Replay integration
247
247
*
@@ -252,6 +252,18 @@ export function shouldSkipFeedbackTest(): boolean {
252
252
return bundle != null && ! bundle . includes ( 'feedback' ) && ! bundle . includes ( 'esm' ) && ! bundle . includes ( 'cjs' ) ;
253
253
}
254
254
255
+ /**
256
+ * We can only test metrics tests in certain bundles/packages:
257
+ * - NPM (ESM, CJS)
258
+ * - CDN bundles that include tracing
259
+ *
260
+ * @returns `true` if we should skip the metrics test
261
+ */
262
+ export function shouldSkipMetricsTest ( ) : boolean {
263
+ const bundle = process . env . PW_BUNDLE as string | undefined ;
264
+ return bundle != null && ! bundle . includes ( 'tracing' ) && ! bundle . includes ( 'esm' ) && ! bundle . includes ( 'cjs' ) ;
265
+ }
266
+
255
267
/**
256
268
* Waits until a number of requests matching urlRgx at the given URL arrive.
257
269
* If the timout option is configured, this function will abort waiting, even if it hasn't reveived the configured
Original file line number Diff line number Diff line change 1
1
import type { Metrics } from '@sentry/types' ;
2
+ import { consoleSandbox } from '@sentry/utils' ;
3
+
4
+ function warn ( ) : void {
5
+ consoleSandbox ( ( ) => {
6
+ // eslint-disable-next-line no-console
7
+ console . warn ( 'You are using metrics even though this bundle does not include tracing.' ) ;
8
+ } ) ;
9
+ }
2
10
3
11
export const metricsShim : Metrics = {
4
- /* eslint-disable @typescript-eslint/no-empty-function */
5
- increment : ( ) => { } ,
6
- distribution : ( ) => { } ,
7
- set : ( ) => { } ,
8
- gauge : ( ) => { } ,
9
- /* eslint-enable @typescript-eslint/no-empty-function */
12
+ increment : warn ,
13
+ distribution : warn ,
14
+ set : warn ,
15
+ gauge : warn ,
10
16
} ;
You can’t perform that action at this time.
0 commit comments