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

Bazel + Jest: Dynamic location for jest-junit's xml file #167

Closed
daivinhtran opened this issue May 24, 2021 · 4 comments · Fixed by #168
Closed

Bazel + Jest: Dynamic location for jest-junit's xml file #167

daivinhtran opened this issue May 24, 2021 · 4 comments · Fixed by #168

Comments

@daivinhtran
Copy link
Contributor

As mentioned in #34 (comment), when we run jest with Bazel, the tests are run in a test sandbox and the directory to the sandbox is not deterministic until the execution phase.

When bazel runs jest, bazel writes test.xml differently from jest-junit. test.xml (generated by bazel) is in written in
/private/var/tmp/[computer_name]/[unconsistent_hash]/execroot/[workspace_name]/bazel-out/darwin-fastbuild/testlogs/package_name/jest/test.log while jest-junit writes to a folder defined by the config or JEST_JUNIT_OUTPUT_DIR env var.

The path to the testlogs (e.g. XML_OUTPUT_FILE) isn't defined until jest is executed by bazel. So we don't know the value to pass in JEST_JUNIT_OUTPUT_DIR or the config statically.

It would be great if we can pass in a global variable name for jest-junit to look at runtime. Something like

"jest-junit": {
  "outputName": "env_var:JEST_JUNIT_OUTPUT_DIR"
}

I'm happy to put up a PR for the proposed feature if you think it's a good idea.

@palmerj3
Copy link
Collaborator

Hey! Thanks for raising this issue.

I'd be happy to accept a PR contribution that adds this functionality.

Just curious wouldn't you be able to make use of jest-junit's environment variable to make this work?

JEST_JUNIT_OUTPUT_DIR="$XML_OUTPUT_FILE" jest

@daivinhtran
Copy link
Contributor Author

daivinhtran commented May 25, 2021

Thanks @palmerj3 for the quick response.

I found out bazelbuild's rules_nodejs recently added the env attribute to do what you just described above.
PR: bazelbuild/rules_nodejs#2499
Issue: bazelbuild/rules_nodejs#2497

However, we still need another config like JEST_JUNIT_OUTPUT_FILE instead of JEST_JUNIT_OUTPUT_DIR or JEST_JUNIT_OUTPUT_NAME because XML_OUTPUT_FILE (set by bazel) is the full path to the xml file instead of just the directory.

We need the full path (dir + filename) to be dynamic because bazel has the capability to retry on flaky tests. Each retry produces a different xml filepath and we need to store and process all the xmls (both failed and passed attempts) to get better reporting on flaky tests.

So given that rules_nodejs added the env attribute to let us set environment variable, we don't need to implement what I originally propose. Instead, we will add JEST_JUNIT_OUTPUT_FILE to accept the fullpath to the xml file. When this config is used, JEST_JUNIT_OUTPUT_DIR and JEST_JUNIT_OUTPUT_NAME will be overriden.

JEST_JUNIT_OUTPUT_FILE="$XML_OUTPUT_FILE" jest

Please let me know if anything is not clear.

@daivinhtran
Copy link
Contributor Author

Hi @palmerj3 . Please take a look whenever you have a chance. #168. Thank you.

@palmerj3
Copy link
Collaborator

Thank you!

I just published https://github.com/jest-community/jest-junit/releases/tag/v12.1.0 with your changes included.

This was referenced May 25, 2021
This was referenced Jun 6, 2021
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 a pull request may close this issue.

2 participants