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 a407866 commit bc8701a
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 103 deletions.
9 changes: 8 additions & 1 deletion packages/integration-tests/src/pages/record-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ export class RecordPage {

async flushData() {
await this.page.evaluate(() => {
window.SplunkRum._processor.forceFlush()
if (window.SplunkRum) {
window.SplunkRum._processor.forceFlush()
}
})
}

async getCookie(name: string) {
const cookies = await this.context.cookies()
return cookies.find((cookie) => cookie.name === name)
}

goTo(url: string) {
const absoluteUrl = new URL(url, 'http://localhost:3000').toString()
return this.page.goto(absoluteUrl)
Expand Down
85 changes: 85 additions & 0 deletions packages/integration-tests/src/tests/cookies/cookies.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
*
* 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 { expect } from '@playwright/test'
import { test } from '../../utils/test'

test.describe('cookies', () => {
test('Connectivity events are captured', async ({ recordPage }) => {
await recordPage.goTo('/cookies/cookies.ejs')

// This should create two streams of documentLoad sequences, all with the same sessionId but having
// two scriptInstances (one from parent, one from iframe)
await recordPage.waitForSpans((spans) => spans.filter((s) => s.name === 'documentFetch').length === 2)
const documentFetchSpans = recordPage.receivedSpans.filter((span) => span.name === 'documentFetch')
expect(documentFetchSpans).toHaveLength(2)

expect(documentFetchSpans[0].tags['location.href']).toBe('http://localhost:3000/cookies/iframe.ejs')
expect(documentFetchSpans[1].tags['location.href']).toBe('http://localhost:3000/cookies/cookies.ejs')

// same sessionId& instanceId
expect(documentFetchSpans[0].tags['splunk.rumSessionId']).toBe(
documentFetchSpans[1].tags['splunk.rumSessionId'],
)
expect(documentFetchSpans[0].tags['browser.instance.id']).toBe(
documentFetchSpans[1].tags['browser.instance.id'],
)

// different scriptInstance
expect(documentFetchSpans[0].tags['splunk.scriptInstance']).not.toBe(
documentFetchSpans[1].tags['splunk.scriptInstance'],
)

const cookie = await recordPage.getCookie('_splunk_rum_sid')
expect(cookie).toBeTruthy()

expect(recordPage.receivedErrorSpans).toHaveLength(0)
})

test('setting session cookie in iframe should work', async ({ recordPage }) => {
await recordPage.goTo('/cookies/cookies.iframe.ejs')

await recordPage.waitForSpans((spans) =>
spans.some((s) => s.name === 'documentFetch' && s.tags.app === 'iframe'),
)
const documentFetchSpans = recordPage.receivedSpans.filter((span) => span.name === 'documentFetch')
expect(documentFetchSpans).toHaveLength(1)
expect(documentFetchSpans[0].tags['splunk.rumSessionId']).toBeTruthy()

const cookie = await recordPage.getCookie('_splunk_rum_sid')

expect(cookie).toBeTruthy()
expect(cookie.secure).toBe(true)
expect(cookie.sameSite).toBe('None')
})

test('setting cookieDomain via config sets it on subdomains also', async ({ recordPage }) => {
await recordPage.goTo(`http://127.0.0.1.nip.io:3000/cookies/cookies-domain.ejs`)
const cookie1 = await recordPage.getCookie('_splunk_rum_sid')

expect(cookie1).toBeTruthy()

await recordPage.goTo(`http://test.127.0.0.1.nip.io:3000/cookies/cookies-domain.ejs`)
const cookie2 = await recordPage.getCookie('_splunk_rum_sid')

expect(cookie2).toBeTruthy()
expect(cookie1.value).toBe(cookie2.value)
expect(cookie1.domain).toBe(cookie2.domain)

expect(recordPage.receivedErrorSpans).toHaveLength(0)
})
})
102 changes: 0 additions & 102 deletions packages/web/integration-tests/tests/cookies/cookies.spec.js

This file was deleted.

0 comments on commit bc8701a

Please sign in to comment.