Skip to content

Commit d61748d

Browse files
Mariovidorochdev
authored andcommitted
[test-optimization] [SDTEST-2024] Fix Playwright exit code status when it fails before running the test (#5733)
1 parent c1fe55c commit d61748d

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { test, expect } = require('@playwright/test')
2+
// eslint-disable-next-line no-unused-vars
3+
const dummy = require('dummy') // This should not exist, so should throw an error
4+
5+
test.beforeEach(async ({ page }) => {
6+
await page.goto(process.env.PW_BASE_URL)
7+
})
8+
9+
test.describe('exit code', () => {
10+
test('should exit with code 1', async ({ page }) => {
11+
await expect(page.locator('.hello-world')).toHaveText([
12+
'Hello World'
13+
])
14+
})
15+
})

integration-tests/playwright/playwright.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,37 @@ versions.forEach((version) => {
14881488
runTest(done, { isRedirecting: true })
14891489
})
14901490
})
1491+
1492+
context('run session status', () => {
1493+
it('session status is not changed if it fails before running any test', (done) => {
1494+
const receiverPromise = receiver
1495+
.gatherPayloadsMaxTimeout(({ url }) => url === '/api/v2/citestcycle', (payloads) => {
1496+
const events = payloads.flatMap(({ payload }) => payload.events)
1497+
const testSession = events.find(event => event.type === 'test_session_end').content
1498+
assert.equal(testSession.meta[TEST_STATUS], 'fail')
1499+
})
1500+
1501+
receiver.setSettings({ test_management: { enabled: true } })
1502+
1503+
childProcess = exec(
1504+
'./node_modules/.bin/playwright test -c playwright.config.js exit-code-test.js',
1505+
{
1506+
cwd,
1507+
env: {
1508+
...getCiVisAgentlessConfig(receiver.port),
1509+
PW_BASE_URL: `http://localhost:${webAppPort}`,
1510+
TEST_DIR: './ci-visibility/playwright-tests-exit-code'
1511+
},
1512+
stdio: 'pipe'
1513+
}
1514+
)
1515+
1516+
childProcess.on('exit', (exitCode) => {
1517+
assert.equal(exitCode, 1)
1518+
receiverPromise.then(() => done()).catch(done)
1519+
})
1520+
})
1521+
})
14911522
}
14921523
})
14931524
})

packages/datadog-instrumentations/src/playwright.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,9 @@ function runnerHook (runnerExport, playwrightVersion) {
604604
totalAttemptToFixFailedTestCount += testStatuses.filter(status => status === 'fail').length
605605
}
606606

607-
if (totalFailedTestCount === totalAttemptToFixFailedTestCount) {
607+
if (totalFailedTestCount > 0 &&
608+
totalAttemptToFixFailedTestCount > 0 &&
609+
totalFailedTestCount === totalAttemptToFixFailedTestCount) {
608610
runAllTestsReturn = 'passed'
609611
}
610612
}

0 commit comments

Comments
 (0)