rules_webtesting
rules_webtesting copied to clipboard
Support Bazel IntelliJ Plugin
I noticed that rules_webtesting has some strange behavior when combined with https://github.com/bazelbuild/intellij
I created an simple example project, which imports to IntelliJ to make things easy to reproduce: https://github.com/lucidsoftware/rules_webtesting_intellij_example
Normally with IntelliJ + Bazel, when you create a java_test there are icons in the gutter of your test file, that enable you to run the test:

When you create a java_web_test_suite, these same icons show up, but they don't do anyything:

After some digging I found that it is because of the manual tag set by default in constants.bzl
https://github.com/bazelbuild/rules_webtesting/blob/master/web/internal/constants.bzl#L16
If you set some tags on your java_web_test_suite. For example, java_test_tags = ["foo"] here https://github.com/lucidsoftware/rules_webtesting_intellij_example/blob/master/com/google/testing/web/BUILD.bazel#L26
Then the test fails with a MalformedURLException:
java.net.MalformedURLException
java.lang.RuntimeException: java.net.MalformedURLException
at com.google.testing.web.WebTest.<init>(WebTest.java:60)
Thrown here: https://github.com/bazelbuild/rules_webtesting/blob/master/java/com/google/testing/web/WebTest.java#L60
After some more digging, I found that this is essentially what rules_webtesting is doing when you call java_web_test_suite:

The reason the test fails with a MalformedURLException is because the WEB_TEST_WEBDRIVER_SERVER is never set because instead of the java_test being run by the web_test, it is running independently. Accordingly, the Selenium server never starts, that environment variable is never set, and things fail.
I've been poking at the IntelliJ plugin and rules_webtesting without much progress. I tried to change rules_webtesting to do something like this, but I don't believe this is possible with Bazel: 
I'm not familiar enough with the IntelliJ plugin to know if it is feasible to tell java_tests from java_web_test_suites to execute the web_test instead of the java_test.
I would love to get people's thoughts on whether this is possible, and if it is, then a potential path forward.
I have never used the bazel IntelliJ plugin, but can start looking into this. I think it should be possible to make it smart about web_test.
That would be awesome! I'm happy to help.