Skip to content
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

Add internal testing tools package #587

Merged
merged 13 commits into from
Jan 26, 2024

Conversation

louiszawadzki
Copy link
Contributor

@louiszawadzki louiszawadzki commented Jan 16, 2024

What does this PR do?

This adds a new package for internal UI-level testing.
The package has 3 methods:

  • enable (to be called before initializing the SDK): registers hooks to capture events
  • getAllEvents: returns all captured events for a given feature
  • clearData: removes all captured events

Motivation

Enable UI-level testing for the SDK.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@louiszawadzki louiszawadzki force-pushed the louiszawadzki/rum-2343/create-testing-package branch from 175600d to 28ef98c Compare January 16, 2024 12:51
@louiszawadzki louiszawadzki force-pushed the louiszawadzki/rum-2343/create-testing-package branch 6 times, most recently from 969d9bb to b6ce681 Compare January 22, 2024 13:54
@louiszawadzki louiszawadzki marked this pull request as ready for review January 22, 2024 14:30
@louiszawadzki louiszawadzki requested review from a team as code owners January 22, 2024 14:30
jhgilbert
jhgilbert previously approved these changes Jan 22, 2024
@louiszawadzki louiszawadzki force-pushed the louiszawadzki/rum-2343/create-testing-package branch 4 times, most recently from 3f2857e to de6a7d5 Compare January 23, 2024 13:58
maxep
maxep previously approved these changes Jan 24, 2024
Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

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

It looks great on the iOS side, well done!
I have left a coupe of suggestions.

Copy link
Member

@0xnm 0xnm left a comment

Choose a reason for hiding this comment

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

nice work! I added few comments/thoughts.

/**
* Internal object used to add internal testing.
*/
object DatadogSDKWrapperStorage {
Copy link
Member

Choose a reason for hiding this comment

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

If we don't want to make it available to the customers, we need to make this class internal.

Suggested change
object DatadogSDKWrapperStorage {
internal object DatadogSDKWrapperStorage {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I make it internal, I cannot import it in the internal testing module.
Is it possible to still import it?

And I think it can be ok to leave it available to customers. Most of them won't do anything, and maybe that can make things a little easier for some customers with hybrid applications.

Copy link
Member

Choose a reason for hiding this comment

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

Let's keep it public then, but if it used only for the tests, nothing in the name reflects that the intended usage is for the tests only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will also be used in Session Replay to make sure we use the same core for all features - it's one of the next tasks on the topic.
When we'll split the RN SDK in core/RUM/Logs/Trace this will also be used to get the core in the feature packages.

Let me know if you think we should still change the name to something more explicit here.

mockContext
)
DatadogSDKWrapperStorage.setSdkCore(mockCore)
DatadogSDKWrapperStorage.notifyOnInitializedListeners()
Copy link
Member

Choose a reason for hiding this comment

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

So this call will do another setSdkCore call, but with StubSDKCore this time? It is a bit non-intuitive by looking on the class name. Maybe we need some method there which has something related to the stubbing directly in the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not do another setSdkCore call directly, but we notify all listeners, and one of them happens to be setting the SdkCore.
I don't think this is a good idea to reflect in the name of notifyOnInitializedListeners that it's currently only being used for internal testing since it is in the main SDK package and we might as well add other callbacks in the future.

I can add a comment in the test and above the function to make it clearer, would that work for you?

@louiszawadzki louiszawadzki force-pushed the louiszawadzki/rum-2343/create-testing-package branch from de6a7d5 to 9288937 Compare January 25, 2024 13:49
@louiszawadzki louiszawadzki force-pushed the louiszawadzki/rum-2343/create-testing-package branch from 9a317d9 to 14f3325 Compare January 25, 2024 16:43
@louiszawadzki louiszawadzki force-pushed the louiszawadzki/rum-2343/create-testing-package branch from 14f3325 to 66855bb Compare January 26, 2024 09:50
@louiszawadzki louiszawadzki merged commit 40d8e7a into develop Jan 26, 2024
4 checks passed
@louiszawadzki louiszawadzki deleted the louiszawadzki/rum-2343/create-testing-package branch January 26, 2024 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants