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

Fix bug: MPR executes tests multiple times #5335

Merged
merged 2 commits into from
Jan 17, 2018
Merged

Fix bug: MPR executes tests multiple times #5335

merged 2 commits into from
Jan 17, 2018

Conversation

mjesun
Copy link
Contributor

@mjesun mjesun commented Jan 17, 2018

When executing a test by path (not sure why this is a thing?) we were returning true for each call in a project configured. This is because as soon as a test is a file, we returned true, not checking if the file actually belongs to the project being tested.

This has popped up multiple times (e.g. #5332).

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a test, should be straightforward with an integration test.

Also changelog :)

return false;
}

// It exists and it is a file; return true if it's in the project.
return allFiles.includes(path.resolve(name));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjesun have you measured perf impact of this? I suspect allFiles to be quite a big array, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it to a Set so that the search becomes O(1).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, for the typical use-case (jest some-path or jest test1 test2) it should be negligible, but hypothetically it might hit the user harder when they provide a glob with tens of paths.

I'm good with a set.

@mjesun
Copy link
Contributor Author

mjesun commented Jan 17, 2018

  • I've added a test which mimics the observed behavior (tests passed by path get executed N-times, once per config). I've also tested that the test fails on master and passes on the current branch.

  • Added entry to the changelog pointing to this PR.

  • Modified the code for checking if the file belongs to the project, by using a Set instead of the Array given by hasteFS.getAllFiles().

@codecov-io
Copy link

Codecov Report

Merging #5335 into master will decrease coverage by 0.02%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5335      +/-   ##
==========================================
- Coverage   61.21%   61.19%   -0.03%     
==========================================
  Files         205      205              
  Lines        6900     6903       +3     
  Branches        4        4              
==========================================
  Hits         4224     4224              
- Misses       2675     2678       +3     
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-cli/src/search_source.js 39.02% <0%> (-1.49%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb21f0b...bf2eab2. Read the comment docs.

@mjesun mjesun merged commit c8bb0a7 into jestjs:master Jan 17, 2018
const validTestPaths =
paths &&
paths.filter(name => {
try {
return fs.lstatSync(name).isFile();
if (!fs.lstatSync(name).isFile()) {
// It exists, but it is not a file; return false.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove the "return false" here? It's literally the next line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, I didn't spot that :D

@github-actions
Copy link

This pull request 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 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants