-
Notifications
You must be signed in to change notification settings - Fork 168
♻️ Refactor e2e service worker setup into a composable builder pattern #4162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Introduce `createWorker()` builder with `.withRum()` and `.withLogs()` methods, replacing inline worker configuration in `createTest`. This makes worker setup composable and enables testing RUM and Logs independently in service workers.
…xecution in service workers Add a generic evaluate message handler in the worker that executes arbitrary code sent from tests, enabling direct SDK API calls (DD_LOGS, DD_RUM) inside the worker. Remove the nativeLog option in favor of explicit console.log calls.
Bundles Sizes Evolution
🚀 CPU PerformancePending... 🧠 Memory PerformancePending... |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2faf21dc6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await page.evaluate(`(${cb.toString()})(window.myServiceWorker.active)`) | ||
| evaluateInWorker: async (fn: () => void) => { | ||
| await page.evaluate((code) => { | ||
| window.myServiceWorker.active?.postMessage({ __type: 'evaluate', code }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fail fast when service worker is not yet active
evaluateInWorker() posts messages through window.myServiceWorker.active?.postMessage, which silently no-ops when registration.active is still null (a common state right after first registration). In that case the helper resolves even though the worker callback never runs, so service-worker tests can become flaky or give misleading results because assertions run without the intended worker-side action.
Useful? React with 👍 / 👎.
Motivation
The e2e service worker test infrastructure was tightly coupled and hard to extend. Adding new SDK configurations (e.g. RUM in a worker) required modifying multiple options flags (
importScript,nativeLog) and threading them through the test framework. TheinteractWithWorkerAPI forced tests to go throughpostMessagewith the active service worker, making test code indirect and harder to read.Changes
createWorker()builder (test/e2e/lib/framework/createWorker.ts): Composable builder pattern that mirrors the existingcreateTest()API. Workers can be configured with.withRum()and.withLogs()independently, replacing the previous boolean flags.interactWithWorkerwithevaluateInWorker: Instead of sending messages to the worker viapostMessage,evaluateInWorkersends code as a string and executes it vianew Function()inside the worker. This allows tests to call SDK APIs (e.g.DD_LOGS.logger.log(...)) directly in the worker scope.workerSetup()inpageSetups.tsnow conditionally includes Logs and/or RUM SDK imports based on the worker configuration, and always registers a message listener for theevaluateprotocol.forwardConsoleLogsare only enabled in the test that actually usesconsole.log, making the intent clearer.test/e2e/scenario/rum/init.scenario.ts): Verifies that initializing RUM inside a service worker gracefully warns about missing session storage instead of crashing.createWorker().withLogs()builder andevaluateInWorkerAPI.Test instructions
yarn test:e2e:init yarn test:e2e -g "service worker"Checklist