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

Feature Request: outputNameTemplate #236

Open
tobysmith568 opened this issue Dec 12, 2022 · 4 comments
Open

Feature Request: outputNameTemplate #236

tobysmith568 opened this issue Dec 12, 2022 · 4 comments

Comments

@tobysmith568
Copy link

Hey :)

Would you be open to the idea of an outputNameTemplate configuration option?

I'd personally be interested in it at least having the {displayName} as a possibility for interpolation as it would be very helpful in my Nx Monorepo where there's lots of libraries all executing different jest runs at once but with different display names.

I'm open to trying to implement it myself if you greenlight the feature.

Thanks!

@palmerj3
Copy link
Collaborator

Hey!

I like the idea but I'm not sure if it would work in practice.
displayName is used to signify different jest projects, but the jest runner will also run them all by default.

So if multiple jest projects are run then it would get confusing and possibly unpredictable what the filename would be.

@tobysmith568
Copy link
Author

tobysmith568 commented Dec 13, 2022

When working with an Nx monorepo you don't call the Jest CLI yourself. Instead you call the Nx CLI and it starts multiple Jest processes at once, one for each of the packages in your monorepo.

By default all of these Jest processes share a single Jest base config file, and therefore share a single jest-junit configuration too, meaning their file names can't be hard-coded into their config. That's why I'd like the ability to interpolate the Jest display name into the file name.

If you include jest-junit in an Nx monorepo with its default config in the Jest base config then you get N number of Jest processes all start at once with the same jest-junit config, all writing to the same output file. All 15 processes write to the file ./junit.xml and overwrite each other. You're left with a single file that only contains the output from the longest running process.

Right now I have a jest-junit config that looks something like:

reporters: [
  "default",
  [
    "jest-junit",
    {
      suiteName: "<name of my monorepo>",
      suiteNameTemplate: "{filepath}",
      uniqueOutputName: "true",
      outputName: "junit",
      outputDirectory: "reports"
    }
  ]
]

This is pretty good, I end up with N number of files in a reports directory but there's no way to tie them back to the library in the monorepo that they came from - the names are just random.

I think it would be ideal if a monorepo with a structure like

jest.base.ts
libs/
    project-one/
        package.json
        src/
            index.ts
        test/
            index.spec.ts
    project-two/
        package.json
        src/
            index.ts
        test/
            index.spec.ts

was able to produce a reports directory like

reports/
    project-one-junit.xml
    project-two-junit.xml

Which is what interpolating the display name into the file name would give me.

Does that help explain my situation?
Let me know if you have more questions :)

@palmerj3
Copy link
Collaborator

Hey thanks that helps a lot.

My main point in bringing this up is that most of the people who rely on jest-junit don't have that structure. So if you add the feature make sure to make a note in the docs that this is only for situations where jest projects are run independently.

@tobysmith568
Copy link
Author

Great yeah OK, can do :)

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

No branches or pull requests

2 participants