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

Convert BaseJavaModuleTest to Kotlin #37822

Conversation

abdennour-jebbar-nw
Copy link
Contributor

@abdennour-jebbar-nw abdennour-jebbar-nw commented Jun 11, 2023

Summary:

As part of the effort to Kotlin-fy React Native tests, I've converted BaseJavaModuleTest to Kotlin.

Changelog:

[Internal] [Changed] - Convert BaseJavaModuleTest to Kotlin

Test Plan:

Tests pass: ./gradlew :packages:react-native:ReactAndroid:test
Formatted with KtFmt

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 11, 2023
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,744,428 -3,406
android hermes armeabi-v7a 8,056,635 -3,800
android hermes x86 9,235,558 -3,882
android hermes x86_64 9,086,375 -2,863
android jsc arm64-v8a 9,307,265 -3,164
android jsc armeabi-v7a 8,496,811 -3,552
android jsc x86 9,369,285 -3,641
android jsc x86_64 9,624,206 -2,618

Base commit: 03f70bf
Branch: main

@Pranav-yadav Pranav-yadav added the Tests This PR adds or edits a test case. label Jun 12, 2023
@abdennour-jebbar-nw abdennour-jebbar-nw marked this pull request as ready for review June 12, 2023 08:21
@abdennour-jebbar-nw
Copy link
Contributor Author

Hello @cortinico, can you have a look at this PR?

}

@Test(expected = NativeArgumentsParseException::class)
@Throws(Exception::class)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your reviews, I would love to know why this should be removed

Copy link
Contributor

Choose a reason for hiding this comment

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

The @Test(expected = NativeArgumentsParseException::class) bit should be enough to fulfill the purpose of this test, the @Throws(Exception::class) part doesn't add anything there in terms of information, neither it's required for proper compilation.

@rshest
Copy link
Contributor

rshest commented Jun 12, 2023

@abdennour-jebbar-nw

Thank you so much for taking this on!

Looks good overall, aside from a few stylistic suggestions.

Copy link
Contributor

@rshest rshest left a comment

Choose a reason for hiding this comment

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

Could you please address the stylistic suggestions? Thanks!

@facebook-github-bot
Copy link
Contributor

@rshest has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

}

@Test(expected = NativeArgumentsParseException::class)
@Throws(Exception::class)
Copy link
Contributor

Choose a reason for hiding this comment

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

The @Test(expected = NativeArgumentsParseException::class) bit should be enough to fulfill the purpose of this test, the @Throws(Exception::class) part doesn't add anything there in terms of information, neither it's required for proper compilation.

Copy link
Contributor

@rshest rshest left a comment

Choose a reason for hiding this comment

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

@abdennour-jebbar-nw

Sending it back to you, once again (sorry!), since List<JavaModuleWrapper.MethodDescriptor>? breaks the build - should be List<JavaModuleWrapper.MethodDescriptor>.

@facebook-github-bot
Copy link
Contributor

@rshest has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

Hey @abdennour-jebbar-nw it seems like the CI is still red on 2 tests with an NPE. Could you check them out?

@abdennour-jebbar-nw
Copy link
Contributor Author

@cortinico I'm investigating the failing tests

@rshest
Copy link
Contributor

rshest commented Jun 14, 2023

Hey @abdennour-jebbar-nw , what are your plans with the diff?

Will you be able to follow up, or should we maybe close it?

@abdennour-jebbar-nw
Copy link
Contributor Author

@rshest I'm still following up with this PR, I'm trying to figure out why the moduleWrapper remains null

private inner class GeneratedMethodsModule : NativeTestGeneratedModuleSpec() {
override fun getName(): String ="GeneratedMethods"

override fun generatedMethod(a: String, b: Int) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
override fun generatedMethod(a: String, b: Int) {}
override fun generatedMethod(a: String?, b: Int?) {}

}

private abstract inner class NativeTestGeneratedModuleSpec : BaseJavaModule(), TurboModule {
@ReactMethod abstract fun generatedMethod(a: String, b: Int)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@ReactMethod abstract fun generatedMethod(a: String, b: Int)
@ReactMethod abstract fun generatedMethod(a: String?, b: Int?)

private class MethodsModule : BaseJavaModule() {
override fun getName(): String = "Methods"

@ReactMethod fun regularMethod(a: String, b: Int) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@ReactMethod fun regularMethod(a: String, b: Int) {}
@ReactMethod fun regularMethod(a: String?, b: Int?) {}

@rshest
Copy link
Contributor

rshest commented Jun 21, 2023

@rshest I'm still following up with this PR, I'm trying to figure out why the moduleWrapper remains null

@abdennour-jebbar-nw

Hey, I think I know the reason why the remaining two tests were crashing, please see my code suggestions above.

Since the methods in question (and their arguments) were mocked, it's not safe to have them strictly non-nullable. This caused the crash.

@abdennour-jebbar-nw
Copy link
Contributor Author

@rshest Thank you so much for following up with me, I'll try the changes asap, once green I'll update the PR. Your help was so much appreciated 🙌

@github-actions
Copy link

This pull request was successfully merged by @abdennour-jebbar-nw in 8ddb334.

When will my fix make it into a release? | Upcoming Releases

@github-actions github-actions bot added the Merged This PR has been merged. label Jun 22, 2023
@rshest
Copy link
Contributor

rshest commented Jun 22, 2023

@rshest Thank you so much for following up with me, I'll try the changes asap, once green I'll update the PR. Your help was so much appreciated 🙌

@abdennour-jebbar-nw I verified internally that the tests are fixed, so your PR is merged to trunk now. Thank you very much, once again, for working on this! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Tests This PR adds or edits a test case.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants