Skip to content

Commit d7e18bf

Browse files
committed
🐛 pr-feedback: renamed workerImplementation
1 parent 5883aae commit d7e18bf

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

test/e2e/lib/framework/createTest.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ interface TestContext {
3939
flushEvents: () => Promise<void>
4040
deleteAllCookies: () => Promise<void>
4141
sendXhr: (url: string, headers?: string[][]) => Promise<string>
42-
interactWithWorker: (cb: (worker: ServiceWorker) => void) => Promise<void>
4342
}
4443

4544
type TestRunner = (testContext: TestContext) => Promise<void> | void
@@ -132,9 +131,8 @@ class TestBuilder {
132131
return this
133132
}
134133

135-
withWorker(implementation: WorkerImplementationFactory, options: RegistrationOptions = {}) {
136-
implementation.isModule = options.type === 'module'
137-
this.workerImplementationFactory = implementation
134+
withWorker(implementation: WorkerImplementationFactory['implementation'], options: RegistrationOptions = {}) {
135+
this.workerImplementationFactory = { ...options, implementation }
138136

139137
// Service workers require HTTPS or localhost due to browser security restrictions
140138
this.withHostName('localhost')
@@ -175,7 +173,7 @@ class TestBuilder {
175173
testFixture: this.testFixture,
176174
extension: this.extension,
177175
hostName: this.hostName,
178-
workerImplementation: this.workerImplementationFactory,
176+
workerImplementationFactory: this.workerImplementationFactory,
179177
}
180178

181179
if (this.alsoRunWithRumSlim) {
@@ -255,7 +253,7 @@ function declareTest(title: string, setupOptions: SetupOptions, factory: SetupFa
255253
servers.base.bindServerApp(
256254
createMockServerApp(servers, setup, {
257255
remoteConfiguration: setupOptions.remoteConfiguration,
258-
workerImplementation: setupOptions.workerImplementation && workerSetup(setupOptions, servers),
256+
workerImplementation: setupOptions.workerImplementationFactory && workerSetup(setupOptions, servers),
259257
})
260258
)
261259
servers.crossOrigin.bindServerApp(createMockServerApp(servers, setup))
@@ -299,9 +297,6 @@ function createTestContext(
299297
browserLogsManager.clear()
300298
}
301299
},
302-
interactWithWorker: async (cb: (worker: ServiceWorker) => void) => {
303-
await page.evaluate(`(${cb.toString()})(window.myServiceWorker.active)`)
304-
},
305300
flushBrowserLogs: () => browserLogsManager.clear(),
306301
flushEvents: () => flushEvents(page),
307302
deleteAllCookies: () => deleteAllCookies(browserContext),

test/e2e/lib/framework/pageSetups.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { DEFAULT_LOGS_CONFIGURATION } from '../helpers/configuration'
66
import { isBrowserStack, isContinuousIntegration } from './environment'
77
import type { Servers } from './httpServers'
88

9-
export interface WorkerImplementationFactory {
10-
(self: WorkerGlobalScope & { DD_LOGS?: DatadogLogs }): void
11-
isModule?: boolean
9+
export interface WorkerImplementationFactory extends RegistrationOptions {
10+
implementation: (self: WorkerGlobalScope & { DD_LOGS?: DatadogLogs }) => void
1211
}
1312
export interface SetupOptions {
1413
rum?: RumInitConfiguration
@@ -31,7 +30,7 @@ export interface SetupOptions {
3130
logsConfiguration?: LogsInitConfiguration
3231
}
3332
hostName?: string
34-
workerImplementation?: WorkerImplementationFactory
33+
workerImplementationFactory?: WorkerImplementationFactory
3534
}
3635

3736
export type SetupFactory = (options: SetupOptions, servers: Servers) => string
@@ -212,20 +211,20 @@ export function reactSetup(options: SetupOptions, servers: Servers, appName: str
212211
export function workerSetup(options: SetupOptions, servers: Servers) {
213212
let script = ''
214213

215-
if (!options.workerImplementation) {
214+
if (!options.workerImplementationFactory) {
216215
return script
217216
}
218217

219218
if (options.logs) {
220219
script += js`
221-
${options.workerImplementation.isModule ? js`import '/datadog-logs.js';` : js`importScripts('/datadog-logs.js');`}
220+
${options.workerImplementationFactory.type === 'module' ? js`import '/datadog-logs.js';` : js`importScripts('/datadog-logs.js');`}
222221
223222
// Initialize DD_LOGS in service worker
224223
DD_LOGS.init(${formatConfiguration({ ...DEFAULT_LOGS_CONFIGURATION, ...options.logs }, servers)})
225224
`
226225
}
227226

228-
script += `;(${options.workerImplementation.toString()})(self);`
227+
script += `;(${options.workerImplementationFactory.implementation.toString()})(self);`
229228

230229
return script
231230
}

0 commit comments

Comments
 (0)