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: support function as config for title,classname and suitename #55

Merged
merged 1 commit into from
Jun 18, 2018

Conversation

sarod
Copy link
Contributor

@sarod sarod commented Jun 18, 2018

Fixes #54

@palmerj3
Copy link
Collaborator

@sarod excellent work! Thanks so much for taking the time to submit an issue and a PR!

My one and only concern with this is that this would be the first deviation in configurability - it's a feature currently only usable if you use the reporter config. I'm actually ok with that if you can foresee that others would have vastly different needs for specifying class name.

The alternative would be to add an additional configuration option that would hardcode this behavior. For instance, having a configuration option called javaJunitClassname: true and it would do as you describe in the issue.

What do you think? I'm fine merging this if you can think of more use-cases that require a function.

Thanks!

@sarod
Copy link
Contributor Author

sarod commented Jun 18, 2018

Hi @palmerj3,

I understand you concern.

In my case what I actually do with the function is:

  • remove a common (src/) prefix from the filepath
  • remove the ".test.ts" extension from the file name.
  • convert potential other . in the filename to _

Here is the function I'm actually using to compute classname:

classNameTemplate: ({filepath, filename, classname}) => {
   let folder = filepath.substring(0, filepath.length - filename.length);
   if (folder.startsWith('/src')) {
      folder = folder.substring('/src'.length);
   }
   const folderWithDots = folder.replace(/\//g, '.');
   const fileWithoutExtensionOrDots = filename
      .replace(/(\.(spec|test))?\.ts(x)?/, '')
      .replace(/\./g, '_');
   return folderWithDots + fileWithoutExtensionOrDots;
}

We could probably add string and flags properties to support this case but I feel like at some point it would be more cumbersome to try to find the right combination of flags rather than writing a function with a few lines of codes.

So I think supporting functions allows for much more flexibility while keeping the number of configuration options in the project reasonable.

@palmerj3
Copy link
Collaborator

Ok makes sense

@palmerj3 palmerj3 merged commit ba3f13f into jest-community:master Jun 18, 2018
@palmerj3
Copy link
Collaborator

I'll publish a release later today

@sarod
Copy link
Contributor Author

sarod commented Jun 18, 2018

Excellent. Thanks!

@palmerj3
Copy link
Collaborator

@sarod 5.1.0 was just published containing this feature.

Thanks again! Excellent work.

@palmerj3
Copy link
Collaborator

https://github.com/jest-community/jest-junit/releases/tag/v5.1.0

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 this pull request may close these issues.

2 participants