pact-foundation / jest-pact

A Pact adaptor for to allow you to easily run tests with Jest
https://pact.io
MIT License
80 stars 12 forks source link

Log file does not contain data for all tests #193

Closed alastairs closed 4 years ago

alastairs commented 4 years ago

In evaluating Jest-Pact last week I discovered that, with multiple Pact tests executing with --runInBand, the log file is overwritten for each test in the run. This means that it does not contain log data for the earlier tests in the run, which makes debugging those tests a bit trickier.

Workaround: run the tests one at a time.

TimothyJones commented 4 years ago

I remember now - this is a bit annoying to fix nicely. I've just released v0.6.0, which includes any explicit port numbers in the log filename. Read on for some discussion and a workaround:

Ideally, each test file would have its own log file, making it easy to debug. Here are some candidates for naming them automatically, in order of preference:

Alternatively, you can work around this by specifying log: "pact/logs/whatever.log" in your pactWith options.

We can make that workaround less clunky, by allowing separate logDir and logFileName options for pactWith.

What do you think?

alastairs commented 4 years ago

@TimothyJones sorry for the delay responding, I moved onto a different team and so have put down my jest-pact work for a while. Thank you for the mitigation nonetheless. The file/test name would be ideal, of course, but my own research came to the same conclusion. Might there be a route to achieving this with, e.g., Object.prototype.constructor?

Anyway, if you're open to changing the API in the way you describe, I'd suggest a logDir option defaulting "pact/logs" and logFileName defaulting to the current generated filename if that's possible. It feels like this may be a relatively niche use case.

YOU54F commented 4 years ago

In evaluating Jest-Pact last week I discovered that, with multiple Pact tests executing with --runInBand, the log file is overwritten for each test in the run.

--runInBand is for running in serial not parallel. I have several provider-consumer tests split into seperate pact tests in a single code base and each one generates its own log file. We use random ports on each instantiation and I run them in parallel for speed.

My config is below for a single test file, each file is for either a different consumer or provider

jestpact.pactWith(
  {
    consumer: "consumer-service",
    provider: "provider-service",
    dir: "src/pact/pacts",
  },

And I get a separate log file for each pair in pact/logs

TimothyJones commented 4 years ago

@YOU54F - you do get a separate log file for each pair of consumer / providers, yes.

However, if you have multiple spec files for the same consumer / provider pairs, then the logs get overwritten because the file name is generated from the consumer/provider names.

TimothyJones commented 4 years ago

@alastairs : I've added logDir and logFileName in v0.8.0, which I'm releasing today. This should make life easier for this use case.

In lieu of the ability to do nicer things like tell what the filename is, I'll close this out for now. Feel free to reopen if you have further issues.