-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Only run tests for changed sources #544
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
Only run tests for changed sources #544
Conversation
|
By analyzing the blame information on this pull request, we identified @jokeyrhyme, @ariporad and @sotojuan to be potential reviewers |
|
@sindresorhus @vdemedes @jamestalmage any feedback? |
|
@novemberborn I'll try to take a look tomorrow. Been busy IRL and James is off traveling :) |
|
I'm a bit busy this weekend, I'll take a look during the start of the week. Thanks! |
|
@sindresorhus @vdemedes ping |
lib/test-worker.js
Outdated
| // slowing down IPC. Consider removing filenames that are excluded from | ||
| // being sources, and not tracking dependencies at all if not in --watch | ||
| // mode. Additionally consider sending these in a single message when the | ||
| // process exits (including in error conditions). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be a better approach to send it all at once, as you've suggested.
|
The approach generally looks good.
By |
|
LGTM from me, will clean up later myself ;) |
Yes. Naming is hard…
Let me take the feedback and improve on this :) |
|
@novemberborn it's no big deal, few things I noticed:
Most of it and others are stylistic changes, so don't worry ;) |
|
Updated! This should be good to go now. New PR description:
@vdemedes
But @sindresorhus wrote |
|
I meant just to change the var name, not the module :) Never mind, it's totally my preferences, not forcing them. |
|
Pushed a commit to fix Windows. Paths are insanely confusing so I've tried to simplify a few assumptions:
This way the actual calls to the various matcher libraries are the same no matter the platform and we don't have to make assumptions on how the library adjusts. Just for example with On Windows 10: 😖 |
Use a class-based approach so state can be kept on the instances, reducing the need to pass it through function calls and closures. Extract debouncer into a separate class (kept within the module). Rather than passing process.stdin the CLI is now responsible for starting observation. When 'rs' is entered directly rerun all tests, without passing through the change detection. Reset the logger before every test run, including the first.
fork.js sends the teardown command when uncaught exceptions occur, if there are no tests, and when results are received. However the results message is sent from the worker when all tests have run. This means teardown can be sent more than once.
Test workers keep track of test dependencies for all registered file extensions. These are sent back to the Api as part of the 'teardown' event, ensuring they're captured irrespective of whether tests passed. The watcher rejects any dependencies that are not source files, matching how Chokidar watches for source file modifications. It maintains a list of source dependencies for each test file. The watcher will find the test files that depend on modified source files and rerun those (along with any other modified test files). If any modified source files cannot be mapped to test files all tests are rerun. This is necessary because only `require()` dependencies are tracked, not file access.
Explicitly normalize test file paths as they're discovered in `api.js`. They end up being normalized implicitly in `fork.js` but it's saner if test file paths always use backslashes on Windows. Assume test file and source patterns use slashes. Ensure such when recursing directories in `api.js` and when matching files in `watcher.js`. Fix watcher tests to emit dependencies and chokidar changes using platform-specific paths.
|
@sindresorhus @vdemedes @jamestalmage rebased on |
|
Cool, interesting idea @novemberborn! I don't think we need to squash commits here, just merge as it is. |
|
In general LGTM. How is thorough is coverage of new code? It just seems like a high ratio of new code to tests (gut feeling after reviewing on mobile - I could be off base). My only concern with the require hook is that it is easily broken by bad actors. Something like |
|
Alright. I've been testing this now in many different projects and seems to be working good. |
Is there anything we could do to prevent this?
I think an actual dependency graph is a lot better than what a static analysis could do. |
Only run tests for changed sources
|
Merging. We can follow-up with any improvements/requests. Really good stuff @novemberborn :) |
Maybe instead of a conventional hook we wrap
I agree. |
Probably looked that way due to the refactor I did. That had little test impact though.
Yea it's icky. If it's any consolation the require hook is added after the custom requires have loaded, so unless hooks are added afterwards we'll be able to capture any dependencies. I'll make sure to explain this in the documentation.
I don't think that would work for native and JSON dependencies?
Thanks @sindresorhus! |
I like this idea. Could even be a separate module we consume. @novemberborn hint hint ;) @novemberborn Also feel free to extract anything else into modules where it makes sense. |
Yup, that's true, since they don't call https://github.com/nodejs/node/blob/0bea78682a0530cc51d3dfeab504352034a9fc02/lib/module.js#L423-L445 |
Oh that sounds good. I considered extracting it initially but then figured it wasn't quite interesting enough. Combining it with |

Fixes #115, building on top of the
--watchimplementation.Test workers keep track of test dependencies for all registered file extensions. These are sent back to the Api as part of the 'teardown' event, ensuring they're captured irrespective of whether tests passed.
The watcher rejects any dependencies that are not source files, matching how Chokidar watches for source file modifications. It maintains a list of source dependencies for each test file.
The watcher will find the test files that depend on modified source files and rerun those (along with any other modified test files). If any modified source files cannot be mapped to test files all tests are rerun. This is necessary because only
require()dependencies are tracked, not file access.Run
DEBUG=ava:watcher $(npm bin)/ava --watchin a project to see the matching in action.This required some extensive refactoring of the watcher code itself. Worth it in the end since the changes drop in quite nicely. This will conflict heavily with #536 so best if that lands first.
Additionally I found that test workers may receive multiple
teardownevents. This made theemits dependencies for test filesApi test flaky since it would occur for uncaught exceptions. That's fixed in a separate commit.