Files
3ff11f4029 refactor(web): consolidate Datadog logs into RUM (#7414)
* refactor(web): consolidate Datadog logs into RUM

Remove @datadog/browser-logs dependency and route all logging through
@datadog/browser-rum. Info/warn/debug logs use datadogRum.addAction()
with a level field, error logs use datadogRum.addError(). This
eliminates a separate SDK initialization and simplifies the Datadog
integration to a single entry point.

* tests(web): add integration tests for Datadog RUM logger methods

Verify addAction is called with correct level context for info/warn/debug
and addError is called for error logging and captureException.

---------

Co-authored-by: Hanzo Dev <[email protected]>
2026-03-13 14:53:26 +01:00

74 lines
1.8 KiB
JavaScript

// Used for __tests__/testing-library.js
// Learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom'
import { server } from '@/tests/server'
import { faker } from '@faker-js/faker'
// Seed faker for deterministic test data
faker.seed(123)
// Set timezone to UTC for consistent date formatting across environments
process.env.TZ = 'UTC'
jest.mock('@web3-onboard/coinbase', () => jest.fn())
jest.mock('@web3-onboard/injected-wallets', () => ({ ProviderLabel: { MetaMask: 'MetaMask' } }))
jest.mock('@web3-onboard/walletconnect', () => jest.fn())
// Mock Datadog RUM SDK to prevent it from loading during tests
jest.mock(
'@datadog/browser-rum',
() => ({
datadogRum: {
init: jest.fn(),
addAction: jest.fn(),
addError: jest.fn(),
setGlobalContextProperty: jest.fn(),
getInitConfiguration: jest.fn(),
},
}),
{ virtual: true },
)
const mockOnboardState = {
chains: [],
walletModules: [],
wallets: [],
accountCenter: {},
}
jest.mock('@web3-onboard/core', () => () => ({
connectWallet: jest.fn(),
disconnectWallet: jest.fn(),
setChain: jest.fn(),
state: {
select: (key) => ({
subscribe: (next) => {
next(mockOnboardState[key])
return {
unsubscribe: jest.fn(),
}
},
}),
get: () => mockOnboardState,
},
}))
// This is required for jest.spyOn to work with imported modules.
// After Next 13, imported modules have `configurable: false` for named exports,
// which means that `jest.spyOn` cannot modify the exported function.
const defineProperty = Object.defineProperty
Object.defineProperty = (obj, prop, desc) => {
if (prop !== 'prototype') {
desc.configurable = true
}
return defineProperty(obj, prop, desc)
}
beforeAll(() => {
server.listen()
})
afterEach(() => server.resetHandlers())
afterAll(() => server.close())