Giter VIP home page Giter VIP logo

Comments (5)

TimothyJones avatar TimothyJones commented on August 29, 2024 1

@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.

from jest-pact.

TimothyJones avatar TimothyJones commented on August 29, 2024

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:

  • File names / test names: As far as I am aware, there isn't a nice way to determine the test file (or test name) from Jest.
  • Port number of the mock server: Since the mock server writes the log file, and is told what the log file should be named at startup, we can only do this when we are specifying the port manually (I have just added a commit that does this)
  • Add a sequential string: Jest runs each test file in a separate environment, so we can't do this without adding extra setup steps
  • Add a random string: This would work, but I'm reluctant to do this before we automatically clear out the log directory on startup (which in itself is a bit annoying - to do this, I think we're going to have to require that users modify their jest config, which I was hoping to avoid/minimise)

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?

from jest-pact.

alastairs avatar alastairs commented on August 29, 2024

@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.

from jest-pact.

YOU54F avatar YOU54F commented on August 29, 2024

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

from jest-pact.

TimothyJones avatar TimothyJones commented on August 29, 2024

@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.

from jest-pact.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.