jest-community / jest-junit

A Jest reporter that creates compatible junit xml files
Apache License 2.0
483 stars 109 forks source link

Reports aren't output when `--runInBand` or `--maxWorkers=1` option is included along with `JEST_JUNIT_OUTPUT_DIR` env variable #219

Closed chiubaka closed 2 years ago

chiubaka commented 2 years ago

Thanks for your work on this project!

I stumbled upon this while trying to get testing reports configured properly with CircleCI. Specifically, they pointed me to this example.

I'm finding that when I run the full command JEST_JUNIT_OUTPUT_DIR="./reports/junit/" jest --ci --runInBand --reports=default --reports=jest-junit, my reports just don't appear. I get no output from jest-junit, and the reports directory isn't created.

The same seems true for JEST_JUNIT_OUTPUT_DIR="./reports/junit/" jest --ci --maxWorkers=1 --reports=default --reports=jest-junit, which likely does the same thing as --runInBand under the hood.

If I remove the environment variable, I get junit.xml output to the current directory.

If I instead remove --runInBand (while keeping the env variable), I get output to reports/junit/ as expected.

If I change --runInBand to --maxConcurrency=1 the reports are output normally in the reports/junit/ directory as expected.

chiubaka commented 2 years ago

Unfortunately, though, --maxConcurrency=1 doesn't seem to work with CircleCI--jest seems to stall due to a known issue.

palmerj3 commented 2 years ago

If I change your first command from:

JEST_JUNIT_OUTPUT_DIR="./reports/junit/" jest --ci --runInBand --reports=default --reports=jest-junit

To

JEST_JUNIT_OUTPUT_DIR="./reports/junit/" jest --ci --runInBand --reporters=default --reporters=jest-junit

It appears to work fine. Can you give that a try and report back?

chiubaka commented 2 years ago

Apologies, the reports vs reporters here must have been a typo in the issue. Fairly certain the command you suggested is what I've been running.

I just tried that again, and still got no output. In case it's relevant, this is the exact command I ran: JEST_JUNIT_OUTPUT_DIR="./reports/junit/" yarn jest --ci --runInBand --reporters=default --reporters=jest-junit

No reports dir is created.

JEST_JUNIT_OUTPUT_DIR="./reports/junit/" yarn jest --ci --reporters=default --reporters=jest-junit (without --runInBand) works as expected.

I've got jest-junit v14.0.0, jest v28.1.2 running with yarn v3.2.1 with plug and play.

palmerj3 commented 2 years ago

Ok. Locally, the first command copied & pasted works perfectly for me.

Could you create a repository that reproduces this issue?

It could also be that you may need quotes around "default" and "jest-junit"

chiubaka commented 2 years ago

Thanks for the fast response!

The repo with the problem is currently open source.

I know that's a pain, though. Fortunately, this project is a generator to scaffold simple repositories with a set up I like. So far the generated repository (which I'm versioning along with the generator) is actually running the command in question just fine, which is interesting...

Will keep an eye out for when / if the generated repo breaks. I've just written myself an integration test in the parent generator project to check if my CI testing command outputs the junit.xml file to the right place.

palmerj3 commented 2 years ago

Ok I'll close this but reopen if you can reproduce this again.

Some closing thoughts I'll leave you with. Might be easier on you to include a jest configuration file. Then you don't have to mix environment variables and cli inputs. You can do it all via a reporter config.

Should still work as you have it but simpler config should help with narrowing this down.