Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow collecting coverage from test files #5067

Closed
efegurkan opened this issue Dec 12, 2017 · 2 comments
Closed

Allow collecting coverage from test files #5067

efegurkan opened this issue Dec 12, 2017 · 2 comments

Comments

@efegurkan
Copy link
Contributor

Do you want to request a feature or report a bug?
feature
What is the current behavior?

It is not possible to collect coverage if tests are in the same file with the source. Since should_instrument.js checks if file name matches testRegex or testMatches currently it is not possible to collect coverage from these files.

We have several tests similar to this example.

// sum.test.js

export function sum(a,b) {
  return a + b;
}

if (process.env.NODE_ENV === 'test') {
  test('sum', () => {
    expect(sum(1, 2)).toBe(3);
  });
}

What is the expected behavior?

It would be nice to have an option to check for coverage even if the file is a test file. Normally you wouldn't want to collect coverage from all of your test files.
Having and option like enforceCoverageRegex : ".*\\.test\\.js$" would allow you to collecting coverage from the files that are named in a certain way.

I am currently experimenting with the idea and i would like to come with a PR as well.

@efegurkan
Copy link
Contributor Author

This has been merged with #5081.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant