Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lcam-1282-test-metadata-uuid-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wdio/browserstack-service": patch
---

- Fixed custom test metadata set via `BrowserStackSDK.setTestMetadata()` being dropped when the metadata is set before the test-run UUID is assigned. A per-UUID lookup now falls back to the current-run metadata again, restoring the behaviour that shipped before 8.51.0.
5 changes: 5 additions & 0 deletions .changeset/pr-243.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wdio/browserstack-service": patch
---

- Fixed custom test metadata set via `BrowserStackSDK.setTestMetadata()` before the test-run UUID is assigned being dropped for App Low-Code runs.
6 changes: 5 additions & 1 deletion packages/browserstack-service/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TestMetadata {

static set(metadata: Metadata = {}) {
if (!getCentralUser().app_lcnc) {
BStackLogger.warn(`setTestMetadata: ignored, BROWSERSTACK_CENTRAL_USER=${process.env.BROWSERSTACK_CENTRAL_USER}`)
return
}

Expand All @@ -31,6 +32,7 @@ class TestMetadata {
if (TestMetadata.currentTestRunUuid) {
TestMetadata.metadataByTestRunUuid[TestMetadata.currentTestRunUuid] = metadata
}
BStackLogger.debug(`setTestMetadata: identifier=${testRunIdentifier} storedUnderUuid=${TestMetadata.currentTestRunUuid} store=[${Object.keys(TestMetadata.metadataByTestRunUuid)}]`)
}

static get(testRunUuid?: string): Metadata {
Expand All @@ -39,7 +41,9 @@ class TestMetadata {
}

if (testRunUuid) {
return TestMetadata.metadataByTestRunUuid[testRunUuid] || {}
const metadata = TestMetadata.metadataByTestRunUuid[testRunUuid] || TestMetadata.fallbackMetadata || {}
BStackLogger.debug(`TestMetadata.get: uuid=${testRunUuid} identifier=${metadata.identifier} store=[${Object.keys(TestMetadata.metadataByTestRunUuid)}]`)
return metadata
}

return TestMetadata.fallbackMetadata || {}
Expand Down
19 changes: 15 additions & 4 deletions packages/browserstack-service/tests/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ describe('TestMetadata', () => {
})

describe('fallback vs per-uuid storage', () => {
it('stores as fallback for the no-uuid (current-run) lookup, but not for unknown uuids', () => {
it('stores as fallback for the no-uuid (current-run) lookup', () => {
TestMetadata.set({ identifier: 'run-1' })
expect(TestMetadata.get()).toEqual({ identifier: 'run-1' })
// A per-uuid lookup must not leak the current-run fallback.
expect(TestMetadata.get('unknown-uuid')).toEqual({})
})

it('serves the fallback to a uuid lookup when the uuid was learned after set()', () => {
TestMetadata.set({ identifier: 'run-1' })
expect(TestMetadata.get('uuid-assigned-later')).toEqual({ identifier: 'run-1' })
})

it('stores per-uuid when a current test-run uuid is set', () => {
Expand All @@ -81,9 +84,17 @@ describe('TestMetadata', () => {
expect(TestMetadata.get('uuid-1')).toEqual({ identifier: 'run-1' })
})

it('returns {} for an unknown uuid instead of leaking another run\'s metadata', () => {
it('falls back to the current-run metadata for an unrecognised uuid', () => {
TestMetadata.setCurrentTestRunUuid('uuid-1')
TestMetadata.set({ identifier: 'run-1' })
expect(TestMetadata.get('uuid-2')).toEqual({ identifier: 'run-1' })
})

it('does not carry a previous run\'s metadata once reset() has run between tests', () => {
TestMetadata.setCurrentTestRunUuid('uuid-1')
TestMetadata.set({ identifier: 'run-1' })
TestMetadata.reset()
TestMetadata.setCurrentTestRunUuid('uuid-2')
expect(TestMetadata.get('uuid-2')).toEqual({})
})

Expand Down
Loading