Skip to content

Commit 9f78ec5

Browse files
committed
Move puppeteer inject helper out of createTest
1 parent 42a0085 commit 9f78ec5

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function createScrollValuesObservable(
102102

103103
const observerTarget = document.scrollingElement || document.documentElement
104104
const resizeObserver = new ResizeObserver(monitor(throttledNotify.throttled))
105-
if (observerTarget instanceof Element) {
105+
if (observerTarget) {
106106
resizeObserver.observe(observerTarget)
107107
}
108108
const eventListener = addEventListener(configuration, window, DOM_EVENT.SCROLL, throttledNotify.throttled, {

test/e2e/lib/framework/createTest.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as fs from 'fs'
21
import type { LogsInitConfiguration } from '@datadog/browser-logs'
32
import type { RumInitConfiguration } from '@datadog/browser-rum-core'
43
import { DefaultPrivacyLevel } from '@datadog/browser-rum'
@@ -15,7 +14,6 @@ import type { SetupFactory, SetupOptions } from './pageSetups'
1514
import { DEFAULT_SETUPS, npmSetup } from './pageSetups'
1615
import { createIntakeServerApp } from './serverApps/intake'
1716
import { createMockServerApp } from './serverApps/mock'
18-
import { RUM_BUNDLE } from './sdkBuilds'
1917

2018
const DEFAULT_RUM_CONFIGURATION = {
2119
applicationId: APPLICATION_ID,
@@ -230,33 +228,3 @@ async function tearDownTest({ intakeRegistry }: TestContext) {
230228
})
231229
await deleteAllCookies()
232230
}
233-
234-
export async function injectRumWithPuppeteer() {
235-
const ddRUM = fs.readFileSync(RUM_BUNDLE, 'utf8')
236-
const puppeteerBrowser = await browser.getPuppeteer()
237-
let injected = true
238-
239-
await browser.call(async () => {
240-
const page = await puppeteerBrowser.newPage()
241-
await page.evaluateOnNewDocument(
242-
`
243-
if (location.href !== 'about:blank') {
244-
${ddRUM}
245-
window.DD_RUM._setDebug(true)
246-
window.DD_RUM.init({
247-
applicationId: ${APPLICATION_ID},
248-
clientToken: ${CLIENT_TOKEN},
249-
})
250-
window.DD_RUM.startView()
251-
}
252-
`
253-
)
254-
page.on('console', (msg) => {
255-
if (msg.type() === 'error') {
256-
injected = false
257-
}
258-
})
259-
await page.goto('https://webdriver.io')
260-
})
261-
return injected
262-
}

test/e2e/lib/framework/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
export { createTest, injectRumWithPuppeteer } from './createTest'
1+
export { createTest } from './createTest'
22
export { bundleSetup, html } from './pageSetups'
33
export { IntakeRegistry } from './intakeRegistry'
44
export { getTestServers, waitForServersIdle } from './httpServers'
55
export { flushEvents } from './flushEvents'
66
export { waitForRequests } from './waitForRequests'
77
export { LARGE_RESPONSE_MIN_BYTE_SIZE } from './serverApps/mock'
8+
export { RUM_BUNDLE } from './sdkBuilds'
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
1-
import { injectRumWithPuppeteer } from '../../lib/framework'
1+
import * as fs from 'fs'
2+
import { RUM_BUNDLE } from '../../lib/framework'
3+
import { APPLICATION_ID, CLIENT_TOKEN } from '../../lib/helpers/configuration'
4+
25
describe('Inject RUM with Puppeteer', () => {
36
// S8s tests inject RUM with puppeteer evaluateOnNewDocument
47
it('should not throw error in chrome', async () => {
58
const isInjected = await injectRumWithPuppeteer()
69
expect(isInjected).toBe(true)
710
})
811
})
12+
13+
async function injectRumWithPuppeteer() {
14+
const ddRUM = fs.readFileSync(RUM_BUNDLE, 'utf8')
15+
const puppeteerBrowser = await browser.getPuppeteer()
16+
let injected = true
17+
18+
await browser.call(async () => {
19+
const page = await puppeteerBrowser.newPage()
20+
await page.evaluateOnNewDocument(
21+
`
22+
if (location.href !== 'about:blank') {
23+
${ddRUM}
24+
window.DD_RUM._setDebug(true)
25+
window.DD_RUM.init({
26+
applicationId: ${APPLICATION_ID},
27+
clientToken: ${CLIENT_TOKEN},
28+
})
29+
window.DD_RUM.startView()
30+
}
31+
`
32+
)
33+
page.on('console', (msg) => {
34+
if (msg.type() === 'error') {
35+
injected = false
36+
}
37+
})
38+
await page.goto('https://webdriver.io')
39+
})
40+
return injected
41+
}

0 commit comments

Comments
 (0)