@@ -12,6 +12,7 @@ const {
12
12
} = require ( '../helpers' )
13
13
const { FakeCiVisIntake } = require ( '../ci-visibility-intake' )
14
14
const webAppServer = require ( '../ci-visibility/web-app-server' )
15
+ const webAppServerWithRedirect = require ( '../ci-visibility/web-app-server-with-redirect' )
15
16
const {
16
17
TEST_STATUS ,
17
18
TEST_SOURCE_START ,
@@ -54,7 +55,7 @@ const versions = ['1.18.0', 'latest']
54
55
55
56
versions . forEach ( ( version ) => {
56
57
describe ( `playwright@${ version } ` , ( ) => {
57
- let sandbox , cwd , receiver , childProcess , webAppPort
58
+ let sandbox , cwd , receiver , childProcess , webAppPort , webPortWithRedirect
58
59
59
60
before ( async function ( ) {
60
61
// bump from 60 to 90 seconds because playwright is heavy
@@ -67,11 +68,14 @@ versions.forEach((version) => {
67
68
execSync ( 'npx playwright install chromium' , { cwd, env : restOfEnv , stdio : 'inherit' } )
68
69
webAppPort = await getPort ( )
69
70
webAppServer . listen ( webAppPort )
71
+ webPortWithRedirect = await getPort ( )
72
+ webAppServerWithRedirect . listen ( webPortWithRedirect )
70
73
} )
71
74
72
75
after ( async ( ) => {
73
76
await sandbox . remove ( )
74
77
await new Promise ( resolve => webAppServer . close ( resolve ) )
78
+ await new Promise ( resolve => webAppServerWithRedirect . close ( resolve ) )
75
79
} )
76
80
77
81
beforeEach ( async function ( ) {
@@ -1429,35 +1433,52 @@ versions.forEach((version) => {
1429
1433
} )
1430
1434
1431
1435
context ( 'correlation between tests and RUM sessions' , ( ) => {
1432
- it ( 'can correlate tests and RUM sessions' , ( done ) => {
1433
- const receiverPromise = receiver
1436
+ const getTestAssertions = ( { isRedirecting } ) =>
1437
+ receiver
1434
1438
. gatherPayloadsMaxTimeout ( ( { url } ) => url === '/api/v2/citestcycle' , ( payloads ) => {
1435
1439
const events = payloads . flatMap ( ( { payload } ) => payload . events )
1436
1440
const playwrightTest = events . find ( event => event . type === 'test' ) . content
1441
+ if ( isRedirecting ) {
1442
+ assert . notProperty ( playwrightTest . meta , TEST_IS_RUM_ACTIVE )
1443
+ assert . notProperty ( playwrightTest . meta , TEST_BROWSER_VERSION )
1444
+ } else {
1445
+ assert . property ( playwrightTest . meta , TEST_IS_RUM_ACTIVE , 'true' )
1446
+ assert . property ( playwrightTest . meta , TEST_BROWSER_VERSION )
1447
+ }
1437
1448
assert . include ( playwrightTest . meta , {
1438
1449
[ TEST_BROWSER_NAME ] : 'chromium' ,
1439
- [ TEST_TYPE ] : 'browser' ,
1440
- [ TEST_IS_RUM_ACTIVE ] : 'true'
1450
+ [ TEST_TYPE ] : 'browser'
1441
1451
} )
1442
- assert . property ( playwrightTest . meta , TEST_BROWSER_VERSION )
1443
1452
} )
1444
1453
1454
+ const runTest = ( done , { isRedirecting } , extraEnvVars ) => {
1455
+ const testAssertionsPromise = getTestAssertions ( { isRedirecting } )
1456
+
1445
1457
childProcess = exec (
1446
1458
'./node_modules/.bin/playwright test -c playwright.config.js active-test-span-rum-test.js' ,
1447
1459
{
1448
1460
cwd,
1449
1461
env : {
1450
1462
...getCiVisAgentlessConfig ( receiver . port ) ,
1451
- PW_BASE_URL : `http://localhost:${ webAppPort } ` ,
1452
- TEST_DIR : './ci-visibility/playwright-tests-rum'
1463
+ PW_BASE_URL : `http://localhost:${ isRedirecting ? webPortWithRedirect : webAppPort } ` ,
1464
+ TEST_DIR : './ci-visibility/playwright-tests-rum' ,
1465
+ ...extraEnvVars
1453
1466
} ,
1454
1467
stdio : 'pipe'
1455
1468
}
1456
1469
)
1457
1470
1458
1471
childProcess . on ( 'exit' , ( ) => {
1459
- receiverPromise . then ( ( ) => done ( ) ) . catch ( done )
1472
+ testAssertionsPromise . then ( ( ) => done ( ) ) . catch ( done )
1460
1473
} )
1474
+ }
1475
+
1476
+ it ( 'can correlate tests and RUM sessions' , ( done ) => {
1477
+ runTest ( done , { isRedirecting : false } )
1478
+ } )
1479
+
1480
+ it ( 'do not crash when redirecting and RUM sessions are not active' , ( done ) => {
1481
+ runTest ( done , { isRedirecting : true } )
1461
1482
} )
1462
1483
} )
1463
1484
}
0 commit comments