Skip to content

Commit d4dee15

Browse files
Mariovidowatson
authored andcommitted
[test-optimization] [SDTEST-1871] Add tests for Playwright when redirecting (#5607)
1 parent df23eaf commit d4dee15

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// File to spin an HTTP server that returns an HTML for playwright to visit
2+
const http = require('http')
3+
4+
module.exports = http.createServer((req, res) => {
5+
res.setHeader('Content-Type', 'text/html')
6+
res.writeHead(200)
7+
res.end(`
8+
<!DOCTYPE html>
9+
<meta http-equiv="refresh" content="0; url=https://playwright.dev/" />
10+
`)
11+
})

integration-tests/playwright/playwright.spec.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
} = require('../helpers')
1313
const { FakeCiVisIntake } = require('../ci-visibility-intake')
1414
const webAppServer = require('../ci-visibility/web-app-server')
15+
const webAppServerWithRedirect = require('../ci-visibility/web-app-server-with-redirect')
1516
const {
1617
TEST_STATUS,
1718
TEST_SOURCE_START,
@@ -54,7 +55,7 @@ const versions = ['1.18.0', 'latest']
5455

5556
versions.forEach((version) => {
5657
describe(`playwright@${version}`, () => {
57-
let sandbox, cwd, receiver, childProcess, webAppPort
58+
let sandbox, cwd, receiver, childProcess, webAppPort, webPortWithRedirect
5859

5960
before(async function () {
6061
// bump from 60 to 90 seconds because playwright is heavy
@@ -67,11 +68,14 @@ versions.forEach((version) => {
6768
execSync('npx playwright install chromium', { cwd, env: restOfEnv, stdio: 'inherit' })
6869
webAppPort = await getPort()
6970
webAppServer.listen(webAppPort)
71+
webPortWithRedirect = await getPort()
72+
webAppServerWithRedirect.listen(webPortWithRedirect)
7073
})
7174

7275
after(async () => {
7376
await sandbox.remove()
7477
await new Promise(resolve => webAppServer.close(resolve))
78+
await new Promise(resolve => webAppServerWithRedirect.close(resolve))
7579
})
7680

7781
beforeEach(async function () {
@@ -1429,35 +1433,52 @@ versions.forEach((version) => {
14291433
})
14301434

14311435
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
14341438
.gatherPayloadsMaxTimeout(({ url }) => url === '/api/v2/citestcycle', (payloads) => {
14351439
const events = payloads.flatMap(({ payload }) => payload.events)
14361440
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+
}
14371448
assert.include(playwrightTest.meta, {
14381449
[TEST_BROWSER_NAME]: 'chromium',
1439-
[TEST_TYPE]: 'browser',
1440-
[TEST_IS_RUM_ACTIVE]: 'true'
1450+
[TEST_TYPE]: 'browser'
14411451
})
1442-
assert.property(playwrightTest.meta, TEST_BROWSER_VERSION)
14431452
})
14441453

1454+
const runTest = (done, { isRedirecting }, extraEnvVars) => {
1455+
const testAssertionsPromise = getTestAssertions({ isRedirecting })
1456+
14451457
childProcess = exec(
14461458
'./node_modules/.bin/playwright test -c playwright.config.js active-test-span-rum-test.js',
14471459
{
14481460
cwd,
14491461
env: {
14501462
...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
14531466
},
14541467
stdio: 'pipe'
14551468
}
14561469
)
14571470

14581471
childProcess.on('exit', () => {
1459-
receiverPromise.then(() => done()).catch(done)
1472+
testAssertionsPromise.then(() => done()).catch(done)
14601473
})
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 })
14611482
})
14621483
})
14631484
}

0 commit comments

Comments
 (0)