Skip to content

Commit

Permalink
fix jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez committed Sep 4, 2024
1 parent 7eafa08 commit 0db02e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions integration-tests/cucumber/cucumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ versions.forEach(version => {

const receiverPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), payloads => {
const events = payloads.flatMap(({ payload }) => payload.events)
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)

metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})

const events = payloads.flatMap(({ payload }) => payload.events)

const testSessionEvent = events.find(event => event.type === 'test_session_end')
const testModuleEvent = events.find(event => event.type === 'test_module_end')
const testSuiteEvents = events.filter(event => event.type === 'test_suite_end')
Expand Down
18 changes: 10 additions & 8 deletions integration-tests/jest/jest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const {
TEST_EARLY_FLAKE_ABORT_REASON,
TEST_SOURCE_START,
TEST_CODE_OWNERS,
TEST_SESSION_NAME
TEST_SESSION_NAME,
TEST_LEVEL_EVENT_TYPES
} = require('../../packages/dd-trace/src/plugins/util/test')
const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants')

Expand Down Expand Up @@ -134,6 +135,14 @@ describe('jest CommonJS', () => {
receiver.setInfoResponse({ endpoints: ['/evp_proxy/v4'] })
}
receiver.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('citestcycle'), (payloads) => {
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)

metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})

const events = payloads.flatMap(({ payload }) => payload.events)
const sessionEventContent = events.find(event => event.type === 'test_session_end').content
const moduleEventContent = events.find(event => event.type === 'test_module_end').content
Expand All @@ -150,25 +159,18 @@ describe('jest CommonJS', () => {
)
assert.equal(suites.length, 2)
assert.exists(sessionEventContent)
assert.equal(sessionEventContent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(moduleEventContent)
assert.equal(moduleEventContent.meta[TEST_SESSION_NAME], 'my-test-session')

assert.include(testOutput, expectedStdout)

tests.forEach(testEvent => {
assert.equal(testEvent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.equal(testEvent.meta[TEST_SOURCE_FILE].startsWith('ci-visibility/test/ci-visibility-test'), true)
assert.exists(testEvent.metrics[TEST_SOURCE_START])
// Can read DD_TAGS
assert.propertyVal(testEvent.meta, 'test.customtag', 'customvalue')
assert.propertyVal(testEvent.meta, 'test.customtag2', 'customvalue2')
})

suites.forEach(testSuite => {
assert.equal(testSuite.meta[TEST_SESSION_NAME], 'my-test-session')
})

done()
})

Expand Down

0 comments on commit 0db02e4

Please sign in to comment.