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

fix(karma): allow custom browsers to specify args (fixes #595) #2132

Merged
merged 1 commit into from
Sep 23, 2020
Merged

fix(karma): allow custom browsers to specify args (fixes #595) #2132

merged 1 commit into from
Sep 23, 2020

Conversation

applmak
Copy link
Contributor

@applmak applmak commented Aug 21, 2020

Today, the args as specified in the various manifests of the rules_webtesting
browsers never make it into the generated karma.conf.js. This results in these
arguments never being used when launching Chrome, preventing customization of
browsers such as window size, enabling remote debugging, or other flag-based
options. This PR fixes this by reading those arguments from the manifest, and
adding them to the browsers list in the generated karma.conf.js.

This PR also includes a small (manual) test that specifies an additional
argument in a custom browser, which then can be seen to be used via:

VERBOSE_LOGS=1 bazel run packages/karma/test/karma:testing_custom_chrome

Note the appearance of the additional flags in the new debug output.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

See description above.

Issue Number: #595

What is the new behavior?

See description above.

Does this PR introduce a breaking change?

Perhaps! This might surprise people. If anyone has been using custom browsers up to now, they will suddenly see new arguments on their command-lines. However, given that the feature didn't really work before, I don't think that this is a big deal.

  • Yes
  • No

Other information

Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

Great! thank you for contributing!

@gregmagolan was the author of this so I'd like his review too

@@ -41,3 +43,9 @@ karma_web_test_suite(
"requirejs-config.js",
],
)

custom_browser(
Copy link
Collaborator

Choose a reason for hiding this comment

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

how is this tested? to put it another way, if I take these changes to packages/karma/test but throw away the change to packages/karma/karma.conf.js will the CI be red?
Feels like maybe we're missing one more target here, like maybe a generated_file_test that asserts on what the generated karma conf will look like for the :testing karma_web_test_suite above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. I was a bit concerned about the churn associated with a golden file test, but if that is the standard, I will create one.

Would you happen to know how to get a label to the generated .conf.js file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

it would be nice to test it in a better way but probably hard to sense whether the browser got a right initial dimensions or something.
I don't know the label offhand, if you use bazel query //the/package:all it will probably show up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to make the generated .conf.js a 'predeclared' output so as to write this test. I hope that's okay.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah that looks fine. Note you could also add the file to an Output Group to give a way to select the dynamic (non-predeclared) output

packages/karma/karma.conf.js Show resolved Hide resolved
@applmak
Copy link
Contributor Author

applmak commented Aug 25, 2020

Ping!

@@ -0,0 +1,454 @@
// Karma configuration
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks brittle that this golden is so long, probably more than we meant to assert on in this case.

I'd like to make a convenience rule for golden_content_test or sth so we can just say "make sure this line (± whitespace) appears in the file"

this is okay for now if the content is stable

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 is stable. Should I file a bug about (perhaps) amending generated_file_test to include substring match capability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added that capability. PTAL.

Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

do you need help to get the tests green?

@applmak
Copy link
Contributor Author

applmak commented Aug 29, 2020

Ah, looks like it's not as stable as I would have wished. I'll make that improvement to generated_file_test first.

@applmak
Copy link
Contributor Author

applmak commented Aug 29, 2020

Yep! It looks like I will need help. I'm not sure of the mechanism that seems to be excluding the :testing_chromium-local from buildkite/rules-nodejs-nodejs, but when it tried to run :testing_custom_chrome, it errors with a missing .so.

@applmak
Copy link
Contributor Author

applmak commented Sep 2, 2020

Ping!

@alexeagle
Copy link
Collaborator

Hmm, I don't have time to dig in right now. The error for anyone following along:

ERROR [launcher]: Cannot start ChromeHeadless
  | /var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/ec321eb2cc2d0f8f91b676b6d4c66c29/sandbox/linux-sandbox/1531/execroot/build_bazel_rules_nodejs/bazel-out/k8-fastbuild/bin/packages/karma/test/karma/testing_custom_chrome.sh.runfiles/io_bazel_rules_webtesting/third_party/chromium/chromium.out/chrome-linux/chrome: error while loading shared libraries: libatk-bridge-2.0.so.0: cannot open shared object file: No such file or directory

Could this be due to the custom_chrome.json enabling some options that cause Chromium to dynamic-link more libraries than before? We only installed a minimal set on our CI workers - ideally you'd find a way to assert that the custom browser args are being honored, but without introducing new dependencies on the underlying machine.

(Also WDYT about the substring mode accepting a string attribute with the content to match, rather than (or in addition to) accepting a golden file input? In a lot of cases you just want the equivalent of assert_contains which would mean a lot of tiny one-line files)

@applmak
Copy link
Contributor Author

applmak commented Sep 7, 2020

So, these tests have never worked on CircleCI. The CircleCL script executes:

bazel test --flaky_test_attempts=3 --build_tests_only --local_test_jobs=12 --show_progress_rate_limit=5 --curses=yes --color=yes --terminal_columns=143 --show_timestamps --verbose_failures --jobs=30 --announce_rc --experimental_repository_cache_hardlinks --disk_cache= --sandbox_tmpfs_path=/tmp --experimental_build_event_json_file_path_conversion=false --build_event_json_file=/tmp/tmperwd7qg1/test_bep.json --test_tag_filters=-e2e,-examples,-manual,-browser:chromium-local,-browser:firefox-local,-cypress --test_env=HOME --test_env=USE_BAZEL_VERSION --sandbox_writable_path=/var/lib/buildkite-agent/.cache/bazelisk -- //... /

which removes tests that are tagged browser:chromium-local.

Running

bazel query --output=build packages/karma/test/karma:all

shows the generated test rule as:

web_test(
  name = "testing_custom_chrome",
  tags = ["browser:custom_chrome", "custom_chrome", "ibazel_notify_changes", "native"],
  generator_name = "testing",
  generator_function = "karma_web_test_suite",
  generator_location = "packages/karma/test/karma/BUILD.bazel:19:1",
  size = "large",
  browser = "//packages/karma/test/karma:custom_chrome",
  config = "@io_bazel_rules_webtesting//web:default_config",
  data = [],
  launcher = "//packages/karma/test/karma:testing_wrapped_test",
  test = "//packages/karma/test/karma:testing_wrapped_test",
)

which means it does not get excluded from the circlecl integration test.

So: either, I can add a misleading tag to the test suite (something like browser:chromium-local), or I can extend the circlecl tag exclusion to include browser:custom_chrome. LMK what you want.

@applmak
Copy link
Contributor Author

applmak commented Sep 7, 2020

I found the configuration at .buildci/presubmit.yml and updated it to include an exclusion for tests with the tag 'browser:custom_chrome'.

PTAL.

@applmak
Copy link
Contributor Author

applmak commented Sep 11, 2020

Ping!

@applmak
Copy link
Contributor Author

applmak commented Sep 15, 2020

Pong!

@applmak
Copy link
Contributor Author

applmak commented Sep 17, 2020

Pingigidipong!

Today, the args as specified in the various manifests of the rules_webtesting
browsers never make it into the generated karma.conf.js. This results in these
arguments never being used when launching Chrome, preventing customization of
browsers such as window size, enabling remote debugging, or other flag-based
options. This PR fixes this by reading those arguments from the manifest, and
adding them to the browsers list in the generated karma.conf.js.

Also, this PR includes a change to generated_file_test to allow a golden file
to represent a substring of the generated output.

Also Also: This PR includes a golden file test that verified that the generated
karma.conf.js does read in the specified value.

Furthermore, the effect of this can be verified manually via:
```
VERBOSE_LOGS=1 bazel run packages/karma/test/karma:testing_custom_chrome
```
Note the appearance of the additional flags in the new debug output.
@alexeagle
Copy link
Collaborator

CI rerun still failed, trying a rebase on stable/HEAD to see if it's green

@alexeagle alexeagle merged commit 5a58030 into bazel-contrib:stable Sep 23, 2020
@alexeagle
Copy link
Collaborator

Thanks for pinging :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants