Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Oct 10, 2024
1 parent c8a8844 commit 71bc301
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class BasePage {
*/
async loadAndWait(...args: Parameters<BasePage['load']>) {
await Promise.all([this.load(...args), this.waitForSettings()])
return this
}

/**
Expand All @@ -48,8 +49,12 @@ export class BasePage {
this.edgeFn = edgeFn
await this.setupMockedRoutes()
const url = options.updateURL ? options.updateURL(this.url) : this.url
await this.page.goto(url)
void this.invokeAnalyticsLoad(signalSettings)
await this.page.goto(url, { waitUntil: 'domcontentloaded' })
void this.invokeAnalyticsLoad({
...signalSettings,
flushInterval: 500,
})
return this
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { test, expect } from '@playwright/test'
import { IndexPage } from './index-page'

const indexPage = new IndexPage()

const basicEdgeFn = `
// this is a process signal function
const processSignal = (signal) => {
Expand All @@ -12,8 +10,10 @@ const basicEdgeFn = `
}
}`

let indexPage: IndexPage

test.beforeEach(async ({ page }) => {
await indexPage.loadAndWait(page, basicEdgeFn)
indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn)
})

test('network signals fetch', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { test, expect } from '@playwright/test'
import { IndexPage } from './index-page'

const indexPage = new IndexPage()

const basicEdgeFn = `const processSignal = (signal) => {}`

let indexPage: IndexPage
test.beforeEach(async ({ page }) => {
await indexPage.loadAndWait(page, basicEdgeFn)
indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn)
})

const data = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { test, expect } from '@playwright/test'
import { waitForCondition } from '../../helpers/playwright-utils'
import { IndexPage } from './index-page'

const indexPage = new IndexPage()

const basicEdgeFn = `const processSignal = (signal) => {}`

test('Collecting signals whenever a user enters text input', async ({
Expand All @@ -12,7 +10,7 @@ test('Collecting signals whenever a user enters text input', async ({
/**
* Input some text into the input field, see if the signal is emitted correctly
*/
await indexPage.loadAndWait(page, basicEdgeFn, {
const indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn, {
disableSignalsRedaction: true,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { test, expect } from '@playwright/test'
import { IndexPage } from './index-page'

const indexPage = new IndexPage()

const basicEdgeFn = `const processSignal = (signal) => {}`

test('network signals allow and disallow list', async ({ page }) => {
await indexPage.loadAndWait(page, basicEdgeFn, {
const indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn, {
networkSignalsAllowList: ['allowed-api.com'],
networkSignalsDisallowList: ['https://disallowed-api.com/api/foo'],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ test.describe('network signals - fetch', () => {
let indexPage: IndexPage

test.beforeEach(async ({ page }) => {
indexPage = new IndexPage()
await indexPage.loadAndWait(page, basicEdgeFn)
indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn)
})

test('should not emit anything if neither request nor response are json', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ test.describe('network signals - XHR', () => {
let indexPage: IndexPage

test.beforeEach(async ({ page }) => {
indexPage = new IndexPage()
await indexPage.loadAndWait(page, basicEdgeFn)
indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn)
})
test('should not emit anything if neither request nor response are json', async () => {
await indexPage.network.mockTestRoute('http://localhost/test', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import { test, expect } from '@playwright/test'
import { waitForCondition } from '../../helpers/playwright-utils'
import { IndexPage } from './index-page'

const indexPage = new IndexPage()

const basicEdgeFn = `const processSignal = (signal) => {}`

test('redaction enabled -> will XXX the value of text input', async ({
page,
}) => {
await indexPage.loadAndWait(page, basicEdgeFn, {
const indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn, {
disableSignalsRedaction: false,
})

Expand Down Expand Up @@ -38,10 +36,9 @@ test('redaction enabled -> will XXX the value of text input', async ({
test('redation disabled -> will not touch the value of text input', async ({
page,
}) => {
await indexPage.loadAndWait(page, basicEdgeFn, {
const indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn, {
disableSignalsRedaction: true,
})

await Promise.all([
indexPage.fillNameInput('John Doe'),
indexPage.waitForSignalsApiFlush(),
Expand Down

0 comments on commit 71bc301

Please sign in to comment.