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

[Feature Request] Bazel Support #63

Open
bohregard opened this issue May 2, 2023 · 7 comments
Open

[Feature Request] Bazel Support #63

bohregard opened this issue May 2, 2023 · 7 comments
Assignees

Comments

@bohregard
Copy link

The company that I work for is using Bazel as the build tool for our application and we are considering using Roborazzi for snapshot testing in the future. We've done some internal testing and it looks like the tool doesn't need the Gradle plugin to successfully run since you can pass in the environment flag. For instance in Gradle we could do:

tasks.withType<Test> {
  doFirst {
    systemProperties["roborazzi.test.record"] = "true"
  }
}

All tests that incorporate Roborazzi will then output the snapshots. (Obviously they will always do that but that's ok for us since that's our desired output).

Ideally we would build a custom rule on android_local_test (something like snapshot_local_test) where we pass in the custom environment variable for Roborazzi.

The challenge is then Bazel outputs everything into a build output directory (https://bazel.build/remote/output-directories). Is it possible to bake support for moving the snapshot tests to the root src directory after a successful rule has executed?

@Bencodes
Copy link

Bencodes commented May 2, 2023

Apart from telling Roborazzi where to write the snapshots to and where to look for the previous ones, this pretty much works out of the box with Bazel:

android_local_test(
    name = "test",
    jvm_flags = [
		# Pass the Roborazzi flags that you need
		"-Droborazzi.test.record=true",
		# Pass in the runfiles path to the baselines
		"-Dsnapshot.baseline='$(rlocationpath baseline.zip)'",
    ],
	data = [
		# Feed the baselines back in
		"baseline.zip",
	],
)
@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
class ExampleSnapshotTest {

    private val workingDirectory = File(System.getenv("TEST_UNDECLARED_OUTPUTS_DIR")!!)

    @get:Rule
    val testRule = createSnapshotTestRule()

    @get:Rule
    val snapshotRule = SnapshotRule(testRule = testRule, outputDirectoryPath = workingDirectory.path)

And you can place the snapshots back by doing:

	// Can be wrapped up into a custom JunitRule
	val runfiles = Runfiles.preload()
	val baselinesZipArchive = File(runfiles.unmapped().rlocation(System.getProperty("snapshot.baseline")!!))
	unzip(baselinesZipArchive, workingDirectory)

@bohregard
Copy link
Author

Excellent. Thanks for the insight @Bencodes . It sounds like there isn't anything more to want then. I'll close this for now and reopen if something comes up.
:)

@Bencodes
Copy link

Bencodes commented May 2, 2023

If there is interest in supporting an open source Bazel specific wrapper around SnapshotRule we could drop it into https://github.com/robolectric/robolectric-bazel so that Bazel users have access to that when setting up Robolectric for Bazel.

@takahirom
Copy link
Owner

takahirom commented May 3, 2023

Thank you @bohregard and @Bencodes for discussing Bazel support for Roborazzi. I appreciate your insights and sample code.

I'm considering creating a roborazzi-bazel module with Bazel-specific rules for easier integration. I'll also look into updating documentation, and providing sample projects showcasing the Bazel integration.

Feel free to reach out with any questions or concerns about Bazel integration. I'll monitor the issue tracker and provide support for any Bazel-related issues.

Thanks for your input, and I look forward to improving Roborazzi for the Bazel community.

@takahirom takahirom reopened this May 3, 2023
@sanchezz93
Copy link

Hey everyone, I've synced with @takahirom and I'll be happy to contribute the roborazzi-bazel module.

@takahirom
Copy link
Owner

@sanchezz93, great to have you on board! Thanks for joining us on the roborazzi-bazel module. Looking forward to it!

@utzcoz
Copy link

utzcoz commented Dec 29, 2023

If there is interest in supporting an open source Bazel specific wrapper around SnapshotRule we could drop it into https://github.com/robolectric/robolectric-bazel so that Bazel users have access to that when setting up Robolectric for Bazel.

@Bencodes is it okay to support Roborazzi in robolectric-bazel? Ideally, Roborazzi might need to create a custom wrapper for itself but depends on robolectric-bazel? Or do you want to support common SnapshotRule in robolectric-bazel?

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

No branches or pull requests

5 participants