@@ -4,8 +4,14 @@ import { PostgrestError } from "@supabase/supabase-js";
44
55const captureExceptionMock = vi . fn ( ) ;
66
7+ // Mock isolation scope for isE2ETestFromScope tests
8+ let mockScopeData : Record < string , unknown > = { } ;
9+
710vi . mock ( "@sentry/nextjs" , ( ) => ( {
811 captureException : ( ...args : unknown [ ] ) => captureExceptionMock ( ...args ) ,
12+ getIsolationScope : ( ) => ( {
13+ getScopeData : ( ) => mockScopeData ,
14+ } ) ,
915} ) ) ;
1016
1117import {
@@ -1030,6 +1036,27 @@ describe("isNextjsInternalNoise", () => {
10301036 const event = makeSentryEvent ( [ { type : "Error" } ] ) ;
10311037 expect ( isNextjsInternalNoise ( event ) ) . toBe ( false ) ;
10321038 } ) ;
1039+
1040+ it ( "detects Node.js TransformStream race condition (MEMO-2G)" , ( ) => {
1041+ const event = makeSentryEvent ( [
1042+ {
1043+ type : "TypeError" ,
1044+ value : "controller[kState].transformAlgorithm is not a function" ,
1045+ } ,
1046+ ] ) ;
1047+ expect ( isNextjsInternalNoise ( event ) ) . toBe ( true ) ;
1048+ } ) ;
1049+
1050+ it ( "detects TransformStream error as substring in chained exceptions" , ( ) => {
1051+ const event = makeSentryEvent ( [
1052+ { type : "Error" , value : "Some wrapper error" } ,
1053+ {
1054+ type : "TypeError" ,
1055+ value : "controller[kState].transformAlgorithm is not a function" ,
1056+ } ,
1057+ ] ) ;
1058+ expect ( isNextjsInternalNoise ( event ) ) . toBe ( true ) ;
1059+ } ) ;
10331060} ) ;
10341061
10351062/**
@@ -1667,6 +1694,65 @@ describe("isE2ETestRequest", () => {
16671694 } as unknown as ErrorEvent ;
16681695 expect ( isE2ETestRequest ( event ) ) . toBe ( false ) ;
16691696 } ) ;
1697+
1698+ it ( "returns true when isolation scope has HeadlessChrome in normalizedRequest headers (MEMO-2G on_request_error)" , ( ) => {
1699+ mockScopeData = {
1700+ sdkProcessingMetadata : {
1701+ normalizedRequest : {
1702+ headers : {
1703+ "user-agent" : "Mozilla/5.0 HeadlessChrome/147.0.0.0 Safari/537.36" ,
1704+ } ,
1705+ } ,
1706+ } ,
1707+ } ;
1708+ const event = { type : undefined } as ErrorEvent ;
1709+ expect ( isE2ETestRequest ( event ) ) . toBe ( true ) ;
1710+ mockScopeData = { } ;
1711+ } ) ;
1712+
1713+ it ( "returns true when isolation scope has HeadlessChrome in User-Agent (capitalized)" , ( ) => {
1714+ mockScopeData = {
1715+ sdkProcessingMetadata : {
1716+ normalizedRequest : {
1717+ headers : {
1718+ "User-Agent" : "Mozilla/5.0 HeadlessChrome/147.0.0.0 Safari/537.36" ,
1719+ } ,
1720+ } ,
1721+ } ,
1722+ } ;
1723+ const event = { type : undefined } as ErrorEvent ;
1724+ expect ( isE2ETestRequest ( event ) ) . toBe ( true ) ;
1725+ mockScopeData = { } ;
1726+ } ) ;
1727+
1728+ it ( "returns false when isolation scope has normal Chrome in normalizedRequest headers" , ( ) => {
1729+ mockScopeData = {
1730+ sdkProcessingMetadata : {
1731+ normalizedRequest : {
1732+ headers : {
1733+ "user-agent" : "Mozilla/5.0 Chrome/147.0.0.0 Safari/537.36" ,
1734+ } ,
1735+ } ,
1736+ } ,
1737+ } ;
1738+ const event = { type : undefined } as ErrorEvent ;
1739+ expect ( isE2ETestRequest ( event ) ) . toBe ( false ) ;
1740+ mockScopeData = { } ;
1741+ } ) ;
1742+
1743+ it ( "returns false when isolation scope has no normalizedRequest" , ( ) => {
1744+ mockScopeData = { sdkProcessingMetadata : { } } ;
1745+ const event = { type : undefined } as ErrorEvent ;
1746+ expect ( isE2ETestRequest ( event ) ) . toBe ( false ) ;
1747+ mockScopeData = { } ;
1748+ } ) ;
1749+
1750+ it ( "returns false when isolation scope has no sdkProcessingMetadata" , ( ) => {
1751+ mockScopeData = { } ;
1752+ const event = { type : undefined } as ErrorEvent ;
1753+ expect ( isE2ETestRequest ( event ) ) . toBe ( false ) ;
1754+ mockScopeData = { } ;
1755+ } ) ;
16701756} ) ;
16711757
16721758describe ( "shouldDropServerEvent" , ( ) => {
@@ -1734,4 +1820,39 @@ describe("shouldDropServerEvent", () => {
17341820 } as unknown as ErrorEvent ;
17351821 expect ( shouldDropServerEvent ( event ) ) . toBe ( false ) ;
17361822 } ) ;
1823+
1824+ it ( "drops Node.js TransformStream race condition errors (MEMO-2G)" , ( ) => {
1825+ const event = {
1826+ type : undefined ,
1827+ exception : {
1828+ values : [
1829+ {
1830+ type : "TypeError" ,
1831+ value : "controller[kState].transformAlgorithm is not a function" ,
1832+ } ,
1833+ ] ,
1834+ } ,
1835+ } as unknown as ErrorEvent ;
1836+ expect ( shouldDropServerEvent ( event ) ) . toBe ( true ) ;
1837+ } ) ;
1838+
1839+ it ( "drops on_request_error events from E2E tests via isolation scope (MEMO-2G)" , ( ) => {
1840+ mockScopeData = {
1841+ sdkProcessingMetadata : {
1842+ normalizedRequest : {
1843+ headers : {
1844+ "user-agent" : "Mozilla/5.0 HeadlessChrome/147.0.0.0 Safari/537.36" ,
1845+ } ,
1846+ } ,
1847+ } ,
1848+ } ;
1849+ const event = {
1850+ type : undefined ,
1851+ exception : {
1852+ values : [ { value : "Some server error" } ] ,
1853+ } ,
1854+ } as unknown as ErrorEvent ;
1855+ expect ( shouldDropServerEvent ( event ) ) . toBe ( true ) ;
1856+ mockScopeData = { } ;
1857+ } ) ;
17371858} ) ;
0 commit comments