Skip to content

Commit b9cb0ba

Browse files
[test optimization] Update automatic log submission tests to include playwright (#5783)
1 parent 108a847 commit b9cb0ba

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

integration-tests/automatic-log-submission.spec.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { exec } = require('child_process')
3+
const { exec, execSync } = require('child_process')
44

55
const { assert } = require('chai')
66
const getPort = require('get-port')
@@ -23,9 +23,14 @@ describe('test visibility automatic log submission', () => {
2323
'@cucumber/cucumber',
2424
'jest',
2525
'winston',
26-
'chai@4'
26+
'chai@4',
27+
'@playwright/test'
2728
], true)
2829
cwd = sandbox.folder
30+
const { NODE_OPTIONS, ...restOfEnv } = process.env
31+
// Install chromium (configured in integration-tests/playwright.config.js)
32+
// *Be advised*: this means that we'll only be using chromium for this test suite
33+
execSync('npx playwright install chromium', { cwd, env: restOfEnv, stdio: 'inherit' })
2934
webAppPort = await getPort()
3035
webAppServer.listen(webAppPort)
3136
})
@@ -58,10 +63,18 @@ describe('test visibility automatic log submission', () => {
5863
{
5964
name: 'cucumber',
6065
command: './node_modules/.bin/cucumber-js ci-visibility/automatic-log-submission-cucumber/*.feature'
66+
},
67+
{
68+
name: 'playwright',
69+
command: './node_modules/.bin/playwright test -c playwright.config.js',
70+
getExtraEnvVars: () => ({
71+
PW_BASE_URL: `http://localhost:${webAppPort}`,
72+
TEST_DIR: 'ci-visibility/automatic-log-submission-playwright'
73+
})
6174
}
6275
]
6376

64-
testFrameworks.forEach(({ name, command }) => {
77+
testFrameworks.forEach(({ name, command, getExtraEnvVars = () => ({}) }) => {
6578
context(`with ${name}`, () => {
6679
it('can automatically submit logs', (done) => {
6780
let logIds, testIds
@@ -113,11 +126,13 @@ describe('test visibility automatic log submission', () => {
113126
DD_AGENTLESS_LOG_SUBMISSION_ENABLED: '1',
114127
DD_AGENTLESS_LOG_SUBMISSION_URL: `http://localhost:${receiver.port}`,
115128
DD_API_KEY: '1',
116-
DD_SERVICE: 'my-service'
129+
DD_SERVICE: 'my-service',
130+
...getExtraEnvVars()
117131
},
118132
stdio: 'pipe'
119133
}
120134
)
135+
121136
childProcess.on('exit', () => {
122137
Promise.all([logsPromise, eventsPromise]).then(() => {
123138
const { logSpanId, logTraceId } = logIds
@@ -151,7 +166,8 @@ describe('test visibility automatic log submission', () => {
151166
env: {
152167
...getCiVisAgentlessConfig(receiver.port),
153168
DD_AGENTLESS_LOG_SUBMISSION_URL: `http://localhost:${receiver.port}`,
154-
DD_SERVICE: 'my-service'
169+
DD_SERVICE: 'my-service',
170+
...getExtraEnvVars()
155171
},
156172
stdio: 'pipe'
157173
}
@@ -181,7 +197,8 @@ describe('test visibility automatic log submission', () => {
181197
DD_SERVICE: 'my-service',
182198
DD_TRACE_DEBUG: '1',
183199
DD_TRACE_LOG_LEVEL: 'warn',
184-
DD_API_KEY: ''
200+
DD_API_KEY: '',
201+
...getExtraEnvVars()
185202
},
186203
stdio: 'pipe'
187204
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { test, expect } = require('@playwright/test')
2+
const logger = require('./logger')
3+
const sum = require('./sum')
4+
5+
test.beforeEach(async ({ page }) => {
6+
await page.goto(process.env.PW_BASE_URL)
7+
})
8+
9+
test.describe('playwright', () => {
10+
test('should be able to log to the console', async ({ page }) => {
11+
test.step('log to the console', async () => {
12+
logger.log('info', 'Hello simple log!')
13+
})
14+
15+
expect(sum(1, 2)).toEqual(3)
16+
17+
await expect(page.locator('.hello-world')).toHaveText([
18+
'Hello World'
19+
])
20+
})
21+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { createLogger, format, transports } = require('winston')
2+
3+
module.exports = createLogger({
4+
level: 'info',
5+
exitOnError: false,
6+
format: format.json(),
7+
transports: [
8+
new transports.Console()
9+
]
10+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const logger = require('./logger')
2+
3+
module.exports = function (a, b) {
4+
logger.log('info', 'sum function being called')
5+
return a + b
6+
}

0 commit comments

Comments
 (0)