Skip to content

Commit 1ea0c00

Browse files
bcaudanmormubis
authored andcommitted
💬 renaming suggestion
1 parent 90f6d7c commit 1ea0c00

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

‎test/e2e/lib/framework/createTest.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { IntakeRegistry } from './intakeRegistry'
1313
import { flushEvents } from './flushEvents'
1414
import type { Servers } from './httpServers'
1515
import { getTestServers, waitForServersIdle } from './httpServers'
16-
import type { SetupFactory, SetupOptions, WorkerImplementationFactory } from './pageSetups'
17-
import { workerSetup, html, DEFAULT_SETUPS, npmSetup, reactSetup } from './pageSetups'
16+
import type { SetupFactory, SetupOptions, WorkerOptions } from './pageSetups'
17+
import { buildWorkerScript, html, DEFAULT_SETUPS, npmSetup, reactSetup } from './pageSetups'
1818
import { createIntakeServerApp } from './serverApps/intake'
1919
import { createMockServerApp } from './serverApps/mock'
2020
import type { Extension } from './createExtension'
@@ -59,7 +59,7 @@ class TestBuilder {
5959
logsConfiguration?: LogsInitConfiguration
6060
} = {}
6161
private hostName?: string
62-
private workerImplementationFactory?: WorkerImplementationFactory
62+
private workerOptions?: WorkerOptions
6363

6464
constructor(private title: string) {}
6565

@@ -131,15 +131,15 @@ class TestBuilder {
131131
return this
132132
}
133133

134-
withWorker(implementation: WorkerImplementationFactory['implementation'], options: RegistrationOptions = {}) {
135-
this.workerImplementationFactory = { ...options, implementation }
134+
withWorker(testCase: WorkerOptions['testCase'], registrationOptions: RegistrationOptions = {}) {
135+
this.workerOptions = { ...registrationOptions, testCase }
136136

137137
// Service workers require HTTPS or localhost due to browser security restrictions
138138
this.withHostName('localhost')
139139
this.withBody(html`
140140
<script>
141141
if (!window.myServiceWorker && 'serviceWorker' in navigator) {
142-
navigator.serviceWorker.register('/sw.js', ${JSON.stringify(options)}).then((registration) => {
142+
navigator.serviceWorker.register('/sw.js', ${JSON.stringify(registrationOptions)}).then((registration) => {
143143
window.myServiceWorker = registration
144144
})
145145
}
@@ -173,7 +173,7 @@ class TestBuilder {
173173
testFixture: this.testFixture,
174174
extension: this.extension,
175175
hostName: this.hostName,
176-
workerImplementationFactory: this.workerImplementationFactory,
176+
workerOptions: this.workerOptions,
177177
}
178178

179179
if (this.alsoRunWithRumSlim) {
@@ -253,7 +253,7 @@ function declareTest(title: string, setupOptions: SetupOptions, factory: SetupFa
253253
servers.base.bindServerApp(
254254
createMockServerApp(servers, setup, {
255255
remoteConfiguration: setupOptions.remoteConfiguration,
256-
workerImplementation: setupOptions.workerImplementationFactory && workerSetup(setupOptions, servers),
256+
workerScript: buildWorkerScript(setupOptions, servers),
257257
})
258258
)
259259
servers.crossOrigin.bindServerApp(createMockServerApp(servers, setup))

‎test/e2e/lib/framework/pageSetups.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +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 extends RegistrationOptions {
10-
implementation: (self: WorkerGlobalScope & { DD_LOGS?: DatadogLogs }) => void
9+
export interface WorkerOptions extends RegistrationOptions {
10+
testCase: (self: WorkerGlobalScope & { DD_LOGS?: DatadogLogs }) => void
1111
}
1212
export interface SetupOptions {
1313
rum?: RumInitConfiguration
@@ -30,7 +30,7 @@ export interface SetupOptions {
3030
logsConfiguration?: LogsInitConfiguration
3131
}
3232
hostName?: string
33-
workerImplementationFactory?: WorkerImplementationFactory
33+
workerOptions?: WorkerOptions
3434
}
3535

3636
export type SetupFactory = (options: SetupOptions, servers: Servers) => string
@@ -208,23 +208,23 @@ export function reactSetup(options: SetupOptions, servers: Servers, appName: str
208208
})
209209
}
210210

211-
export function workerSetup(options: SetupOptions, servers: Servers) {
211+
export function buildWorkerScript(options: SetupOptions, servers: Servers) {
212212
let script = ''
213213

214-
if (!options.workerImplementationFactory) {
214+
if (!options.workerOptions) {
215215
return script
216216
}
217217

218218
if (options.logs) {
219219
script += js`
220-
${options.workerImplementationFactory.type === 'module' ? js`import '/datadog-logs.js';` : js`importScripts('/datadog-logs.js');`}
220+
${options.workerOptions.type === 'module' ? js`import '/datadog-logs.js';` : js`importScripts('/datadog-logs.js');`}
221221
222222
// Initialize DD_LOGS in service worker
223223
DD_LOGS.init(${formatConfiguration({ ...DEFAULT_LOGS_CONFIGURATION, ...options.logs }, servers)})
224224
`
225225
}
226226

227-
script += `;(${options.workerImplementationFactory.implementation.toString()})(self);`
227+
script += `;(${options.workerOptions.testCase.toString()})(self);`
228228

229229
return script
230230
}

‎test/e2e/lib/framework/serverApps/mock.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export const LARGE_RESPONSE_MIN_BYTE_SIZE = 100_000
1111

1212
interface MockServerOptions {
1313
remoteConfiguration?: RemoteConfiguration
14-
workerImplementation?: string
14+
workerScript?: string
1515
}
1616
export function createMockServerApp(
1717
servers: Servers,
1818
setup: string,
19-
{ remoteConfiguration, workerImplementation }: MockServerOptions = {}
19+
{ remoteConfiguration, workerScript }: MockServerOptions = {}
2020
): MockServerApp {
2121
const app = express()
2222
let largeResponseBytesWritten = 0
@@ -49,7 +49,7 @@ export function createMockServerApp(
4949
})
5050

5151
app.get('/sw.js', (_req, res) => {
52-
res.contentType('application/javascript').send(workerImplementation)
52+
res.contentType('application/javascript').send(workerScript)
5353
})
5454

5555
function generateLargeResponse(res: ServerResponse, chunkText: string) {

0 commit comments

Comments
 (0)