Skip to content

Comments

✅ improve unit test setup#4149

Merged
BenoitZugmeyer merged 3 commits intomainfrom
benoit/improve-unit-test-bundling
Feb 11, 2026
Merged

✅ improve unit test setup#4149
BenoitZugmeyer merged 3 commits intomainfrom
benoit/improve-unit-test-bundling

Conversation

@BenoitZugmeyer
Copy link
Member

Motivation

For a long time, our unit test suite did not support to be built as a single bundle -- each .spec.ts files produced a separate bundle with their dependencies, so module-level variables were not shared between spec files.

This constraint caused maintenance issues in the past (see). It also prevents us from running global cleanups in the "forEach.spec.ts" file.

Changes

  • Make sure all tests are properly cleaned-up on exit
  • Remove the runtimeChunck: false option so karma-webpack is building mutualizing common dependencies between spec files
  • Also, introduce a --seed argument so we can run the spec files for a given seed without modifying the config file (useful for letting agents investigating test failures)

Test instructions

If CI is green, it should be good

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Feb 6, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 8ec528c | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/improve-unit-test-bundling branch from 59a5a75 to 9694209 Compare February 6, 2026 16:50
@cit-pr-commenter-54b7da
Copy link

cit-pr-commenter-54b7da bot commented Feb 6, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 168.98 KiB 168.97 KiB -3 B -0.00%
Rum Profiler 4.31 KiB 4.31 KiB 0 B 0.00%
Rum Recorder 24.54 KiB 24.54 KiB 0 B 0.00%
Logs 56.27 KiB 56.27 KiB -3 B -0.01%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 125.82 KiB 125.82 KiB -3 B -0.00%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance

Pending...

🧠 Memory Performance

Pending...

🔗 RealWorld

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/improve-unit-test-bundling branch from 9694209 to 4ddaa91 Compare February 6, 2026 17:12
yarn test:unit --spec packages/core/src/path/to/feature.spec.ts

# Run tests on a specific seed
yarn test:unit --seed 123
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 praise: ‏Nice!

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/improve-unit-test-bundling branch from 02c399c to d5103b6 Compare February 10, 2026 15:23
@BenoitZugmeyer BenoitZugmeyer marked this pull request as ready for review February 10, 2026 15:24
@BenoitZugmeyer BenoitZugmeyer requested review from a team as code owners February 10, 2026 15:24
Comment on lines 96 to 120
cookieString: /^dd_[\w_-]+=[^;]*;expires=[^;]+;path=\/;samesite=strict$/,
description: 'should set samesite to strict by default',
},
{
initConfiguration: { clientToken: 'abc', useSecureSessionCookie: true },
cookieOptions: { secure: true },
cookieString: /^dd_cookie_test_[\w-]+=[^;]*;expires=[^;]+;path=\/;samesite=strict;secure$/,
cookieString: /^dd_[\w_-]+=[^;]*;expires=[^;]+;path=\/;samesite=strict;secure$/,
description: 'should add secure attribute when defined',
},
{
initConfiguration: { clientToken: 'abc', trackSessionAcrossSubdomains: true },
cookieOptions: { domain: 'foo.bar' },
cookieString: new RegExp(
`^dd_cookie_test_[\\w-]+=[^;]*;expires=[^;]+;path=\\/;samesite=strict;domain=${getCurrentSite()}$`
`^dd_[\\w_-]+=[^;]*;expires=[^;]+;path=\\/;samesite=strict;domain=${getCurrentSite()}$`
),
description: 'should set cookie domain when tracking accross subdomains',
},
].forEach(({ description, initConfiguration, cookieString }) => {
it(description, () => {
const cookieSetSpy = spyOnProperty(document, 'cookie', 'set')
selectCookieStrategy(initConfiguration)
expect(cookieSetSpy.calls.argsFor(0)[0]).toMatch(cookieString)
expect(cookieSetSpy).toHaveBeenCalled()
for (const call of cookieSetSpy.calls.all()) {
expect(call.args[0]).toMatch(cookieString)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this change was needed because before that PR, the getCurrentSite cache had a high chance of being defined when those tests were executed, so cookie accesses to get the current site were not taken into account. Now that the current site cache is properly reset between tests, this test was failing consistently.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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: d5103b670a

ℹ️ 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".

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/improve-unit-test-bundling branch from d5103b6 to 226bfcf Compare February 10, 2026 15:58
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/improve-unit-test-bundling branch from 226bfcf to 8ec528c Compare February 10, 2026 16:19
Copy link
Collaborator

@bcaudan bcaudan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BenoitZugmeyer BenoitZugmeyer merged commit 3fa9bcb into main Feb 11, 2026
21 checks passed
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/improve-unit-test-bundling branch February 11, 2026 08:54
@github-actions github-actions bot locked and limited conversation to collaborators Feb 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants