Skip to content

Commit

Permalink
Merge pull request #618 from newfold-labs/enhance/disable-sentry-cypress
Browse files Browse the repository at this point in the history
Disable Sentry During Cypress Tests Run
  • Loading branch information
arunshenoy99 authored Sep 11, 2024
2 parents 2e80ed6 + 041ca89 commit e82f734
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/OnboardingSPA/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ export const convertObjectKeysToSnakeCase = ( object ) => {
result[ snakeCase( key ) ] = value;
} );
};

/**
* Checks if the code is running in a Cypress test environment.
*/
export const isEnvironmentCypress = () => {
return !! window.Cypress;
};
33 changes: 20 additions & 13 deletions src/onboarding.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
import './webpack-public-path';

import { NFD_ONBOARDING_ELEMENT_ID, runtimeDataExists } from './constants';

import * as Sentry from '@sentry/react';
// WordPress
import domReady from '@wordpress/dom-ready';
const version = require( '../package.json' ).version;
import { registerCoreBlocks } from '@wordpress/block-library';

// Classes and functions
import initializeNFDOnboarding from './OnboardingSPA';
import { HiiveAnalytics } from '@newfold-labs/js-utility-ui-analytics';
import { onboardingRestURL } from './OnboardingSPA/utils/api/common';
import { isEnvironmentCypress } from './OnboardingSPA/utils';
import * as Sentry from '@sentry/react';

// Misc
import { NFD_ONBOARDING_ELEMENT_ID, runtimeDataExists } from './constants';
import { CATEGORY } from './OnboardingSPA/utils/analytics/hiive/constants';

const version = require( '../package.json' ).version;
const releaseVersion = `wp-onboarding@${ version }`;

if ( runtimeDataExists ) {
domReady( () => {
// Integrate Sentry to send errors and data for tracking
Sentry.init( {
dsn: window.nfdOnboarding.sentryInitDsnURL,
integrations: [ Sentry.browserTracingIntegration() ],
release: releaseVersion,
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions
} );
// Only initialize Sentry if not running in Cypress
if ( ! isEnvironmentCypress() ) {
// Integrate Sentry to send errors and data for tracking
Sentry.init( {
dsn: window.nfdOnboarding.sentryInitDsnURL,
integrations: [ Sentry.browserTracingIntegration() ],
release: releaseVersion,
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions
} );
}

HiiveAnalytics.initialize( {
namespace: CATEGORY,
Expand Down

0 comments on commit e82f734

Please sign in to comment.