Skip to content

Commit 311fe41

Browse files
add integration tests
1 parent e8f199b commit 311fe41

File tree

5 files changed

+95
-16
lines changed

5 files changed

+95
-16
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
const { test, expect } = require('@playwright/test')
4+
5+
test.describe('did not run', () => {
6+
test('because of early bail', async () => {
7+
expect(true).toBe(false)
8+
})
9+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
const { test, expect } = require('@playwright/test')
4+
5+
test.describe('failing test', () => {
6+
test('fails and causes early bail', async () => {
7+
expect(true).toBe(false)
8+
})
9+
})

integration-tests/playwright.config.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
// Playwright config file for integration tests
44
const { devices } = require('@playwright/test')
55

6+
const projects = [
7+
{
8+
name: 'chromium',
9+
use: {
10+
...devices['Desktop Chrome']
11+
}
12+
}
13+
]
14+
15+
if (process.env.ADD_EXTRA_PLAYWRIGHT_PROJECT) {
16+
projects.push({
17+
name: 'extra-project',
18+
use: {
19+
...devices['Desktop Chrome'],
20+
},
21+
dependencies: ['chromium'],
22+
testMatch: 'did-not-run.js'
23+
})
24+
}
25+
626
const config = {
727
baseURL: process.env.PW_BASE_URL,
828
testDir: process.env.TEST_DIR || './ci-visibility/playwright-tests',
@@ -11,14 +31,7 @@ const config = {
1131
workers: process.env.PLAYWRIGHT_WORKERS ? Number(process.env.PLAYWRIGHT_WORKERS) : undefined,
1232
reporter: 'line',
1333
/* Configure projects for major browsers */
14-
projects: [
15-
{
16-
name: 'chromium',
17-
use: {
18-
...devices['Desktop Chrome']
19-
}
20-
}
21-
],
34+
projects,
2235
testMatch: '**/*-test.js'
2336
}
2437

integration-tests/playwright/playwright.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,5 +2070,39 @@ versions.forEach((version) => {
20702070
})
20712071
})
20722072
})
2073+
2074+
contextNewVersions('playwright early bail', () => {
2075+
it('reports tests that did not run', async () => {
2076+
const receiverPromise = receiver
2077+
.gatherPayloadsMaxTimeout(({ url }) => url === '/api/v2/citestcycle', (payloads) => {
2078+
const events = payloads.flatMap(({ payload }) => payload.events)
2079+
const tests = events.filter(event => event.type === 'test').map(event => event.content)
2080+
assert.equal(tests.length, 2)
2081+
const failedTest = tests.find(test => test.meta[TEST_STATUS] === 'fail')
2082+
assert.propertyVal(failedTest.meta, TEST_NAME, 'failing test fails and causes early bail')
2083+
const didNotRunTest = tests.find(test => test.meta[TEST_STATUS] === 'skip')
2084+
assert.propertyVal(didNotRunTest.meta, TEST_NAME, 'did not run because of early bail')
2085+
})
2086+
2087+
childProcess = exec(
2088+
'./node_modules/.bin/playwright test -c playwright.config.js',
2089+
{
2090+
cwd,
2091+
env: {
2092+
...getCiVisAgentlessConfig(receiver.port),
2093+
PW_BASE_URL: `http://localhost:${webAppPort}`,
2094+
TEST_DIR: './ci-visibility/playwright-did-not-run',
2095+
ADD_EXTRA_PLAYWRIGHT_PROJECT: 'true'
2096+
},
2097+
stdio: 'pipe'
2098+
}
2099+
)
2100+
2101+
await Promise.all([
2102+
once(childProcess, 'exit'),
2103+
receiverPromise
2104+
])
2105+
})
2106+
})
20732107
})
20742108
})

packages/datadog-instrumentations/src/playwright.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,13 +1260,9 @@ addHook({
12601260
return workerPackage
12611261
})
12621262

1263-
addHook({
1264-
name: 'playwright',
1265-
file: 'lib/reporters/base.js',
1266-
versions: ['>=1.38.0']
1267-
}, (reportersPackage) => {
1268-
// from https://github.com/microsoft/playwright/blob/bf92ffecff6f30a292b53430dbaee0207e0c61ad/packages/playwright/src/reporters/base.ts#L279
1269-
shimmer.wrap(reportersPackage.TerminalReporter.prototype, 'generateSummary', generateSummary => function () {
1263+
function generateSummaryWrapper (generateSummary) {
1264+
return function () {
1265+
// https://github.com/microsoft/playwright/blob/bf92ffecff6f30a292b53430dbaee0207e0c61ad/packages/playwright/src/reporters/base.ts#L279
12701266
const didNotRunTests = this.suite.allTests().filter(test =>
12711267
test.outcome() === 'skipped' && (!test.results.length || test.expectedStatus !== 'skipped')
12721268
)
@@ -1285,6 +1281,24 @@ addHook({
12851281
})
12861282
}
12871283
return generateSummary.apply(this, arguments)
1288-
})
1284+
}
1285+
}
1286+
1287+
// If a playwright project B has a dependency on project A,
1288+
// and project A fails, the tests in project B will not run.
1289+
// This hook is used to report tests that did not run as skipped.
1290+
// Note: this is different from tests skipped via test.skip() or test.fixme()
1291+
addHook({
1292+
name: 'playwright',
1293+
file: 'lib/reporters/base.js',
1294+
versions: ['>=1.38.0']
1295+
}, (reportersPackage) => {
1296+
// v1.50.0 changed the name of the base reporter from BaseReporter to TerminalReporter
1297+
if (reportersPackage.TerminalReporter) {
1298+
shimmer.wrap(reportersPackage.TerminalReporter.prototype, 'generateSummary', generateSummaryWrapper)
1299+
}
1300+
if (reportersPackage.BaseReporter) {
1301+
shimmer.wrap(reportersPackage.BaseReporter.prototype, 'generateSummary', generateSummaryWrapper)
1302+
}
12891303
return reportersPackage
12901304
})

0 commit comments

Comments
 (0)