Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joozty committed Nov 8, 2024
1 parent 0a34c0c commit 26be13a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 54 deletions.
9 changes: 9 additions & 0 deletions packages/integration-tests/src/pages/record-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export class RecordPage {
private readonly context: BrowserContext,
) {}

changeVisibilityInTab = async (state: 'visible' | 'hidden') => {
await this.page.evaluate((stateInner) => {
Object.defineProperty(document, 'visibilityState', { value: stateInner, writable: true })
Object.defineProperty(document, 'hidden', { value: Boolean(stateInner === 'hidden'), writable: true })

window.dispatchEvent(new Event('visibilitychange'))
}, state)
}

clearReceivedSpans() {
this.receivedSpans = []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
* limitations under the License.
*
*/
import { expect } from '@playwright/test'
import { test } from '../../utils/test'

module.exports = {
'native session id integration': async function (browser) {
const url = browser.globals.getUrl('/native/native.ejs')
await browser.url(url)
test.describe('native', () => {
test('native session id integration', async ({ recordPage }) => {
await recordPage.goTo('/native/native.ejs')

const anySpan = await browser.globals.findSpan((span) => span.tags['splunk.rumSessionId'] !== undefined)
await recordPage.waitForSpans((spans) => spans.some((s) => s.name === 'documentFetch'))
const receivedSpans = recordPage.receivedSpans

await browser.assert.ok(anySpan)

await browser.assert.strictEqual(anySpan.tags['splunk.rumSessionId'], '12341234123412341234123412341234')
await browser.globals.assertNoErrorSpans()
},
}
expect(
receivedSpans.every((span) => span.tags['splunk.rumSessionId'] === '12341234123412341234123412341234'),
).toBe(true)
expect(recordPage.receivedErrorSpans).toHaveLength(0)
})
})
38 changes: 38 additions & 0 deletions packages/integration-tests/src/tests/visibility/visibility.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*
* Copyright 2024 Splunk Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { test } from '../../utils/test'
import { expect } from '@playwright/test'

test.describe('visibility', () => {
test('native session id integration', async ({ recordPage }) => {
await recordPage.goTo('/visibility/visibility.ejs')
await recordPage.waitForTimeout(1000)

await recordPage.changeVisibilityInTab('hidden')
await recordPage.changeVisibilityInTab('visible')

await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'visibility').length >= 2)

const receivedSpans = recordPage.receivedSpans
const visibilitySpans = receivedSpans.filter((span) => span.name === 'visibility')

expect(visibilitySpans).toHaveLength(2)
expect(visibilitySpans[0].tags['hidden']).toBe('true')
expect(visibilitySpans[1].tags['hidden']).toBe('false')
})
})
43 changes: 0 additions & 43 deletions packages/web/integration-tests/tests/visibility/visibility.spec.js

This file was deleted.

0 comments on commit 26be13a

Please sign in to comment.