@@ -92,6 +92,69 @@ describe('micro-agent', () => {
9292 }
9393 } )
9494
95+ // https://new-relic.atlassian.net/browse/NR-453240 <-- issue with rollup seen here around dynamic imports
96+ it ( 'Smoke Test - Can send distinct payloads of all relevant data types to 2 distinct app IDs - ROLL UP BUNDLE' , async ( ) => {
97+ const [ rumCapture , errorsCapture , insightsCapture , logsCapture ] = await browser . testHandle . createNetworkCaptures ( 'bamServer' , [
98+ { test : testRumRequest } ,
99+ { test : testErrorsRequest } ,
100+ { test : testInsRequest } ,
101+ { test : testLogsRequest }
102+ ] )
103+ await browser . url ( await browser . testHandle . assetURL ( 'test-builds/rollup-micro-agent/index.html' ) )
104+
105+ const [ rumHarvests , errorsHarvests , insightsHarvests , logsHarvest ] = await Promise . all ( [
106+ rumCapture . waitForResult ( { totalCount : 2 } ) ,
107+ errorsCapture . waitForResult ( { totalCount : 2 } ) ,
108+ insightsCapture . waitForResult ( { totalCount : 2 } ) ,
109+ logsCapture . waitForResult ( { totalCount : 2 , timeout : 15000 } )
110+ ] )
111+
112+ // these props will get set to true once a test has matched it
113+ // if it gets tried again, the test will fail, since these should all
114+ // only have one distinct matching payload
115+ const tests = {
116+ 1 : { rum : false , err : false , pa : false , log : false } ,
117+ 2 : { rum : false , err : false , pa : false , log : false }
118+ }
119+
120+ // each type of test should check that:
121+ // each payload exists once per appId
122+ // each payload should have internal attributes matching it to the right appId
123+ rumHarvests . forEach ( ( { request : { query, body } } ) => {
124+ expect ( ranOnce ( query . a , 'rum' ) ) . toEqual ( true )
125+ expect ( payloadMatchesAppId ( query . a , body . ja . customAttr ) ) . toEqual ( true )
126+ } )
127+
128+ errorsHarvests . forEach ( ( { request : { query, body } } ) => {
129+ expect ( ranOnce ( query . a , 'err' ) ) . toEqual ( true )
130+ expect ( payloadMatchesAppId ( query . a , body . err [ 0 ] . params . message ) ) . toEqual ( true )
131+ } )
132+
133+ insightsHarvests . forEach ( ( { request : { query, body } } ) => {
134+ expect ( ranOnce ( query . a , 'pa' ) ) . toEqual ( true )
135+ const data = body . ins [ 0 ]
136+ expect ( payloadMatchesAppId ( query . a , data . val , data . actionName , data . customAttr ) ) . toEqual ( true )
137+ } )
138+
139+ logsHarvest . forEach ( ( { request : { query, body } } ) => {
140+ const data = JSON . parse ( body ) [ 0 ]
141+ expect ( ranOnce ( data . common . attributes . appId , 'log' ) ) . toEqual ( true )
142+ expect ( payloadMatchesAppId ( data . common . attributes . appId , data . logs [ 0 ] . message ) ) . toEqual ( true )
143+ } )
144+
145+ function payloadMatchesAppId ( appId , ...props ) {
146+ // each payload in this test is decorated with data that matches its appId for ease of testing
147+ return props . every ( p => Number ( appId ) === Number ( p ) )
148+ }
149+
150+ // eslint-disable-next-line
151+ function ranOnce ( appId , type ) {
152+ if ( tests [ appId ] [ type ] ) return false
153+ tests [ appId ] [ type ] = true
154+ return true
155+ }
156+ } )
157+
95158 it ( 'returns null on top-level spa api interaction call' , async ( ) => {
96159 await browser . url ( await browser . testHandle . assetURL ( 'test-builds/browser-agent-wrapper/micro-agent.html' ) )
97160
0 commit comments