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

Implement watching #96

Closed
wants to merge 1 commit into from
Closed

Implement watching #96

wants to merge 1 commit into from

Conversation

amasad
Copy link
Contributor

@amasad amasad commented Jul 21, 2014

  • Implemented watching option in the TestRunner class.
  • Added watching option to the bin.

The way this feature works is that it runs all tests on the first run when --watch is passed and then idles while watching the testPathDirs and when something has changed, deleted, or added, tests will be run that relates to the changed file (or dir).

I implemented this in TestRunner to be able to reuse it internally. And by doing so I had to move a lot of the file pattern matching logic into the class. But I think it's seems like it belonged there anyways.

closes #38 #7

cc @benjamn @jeffmo @tomocchino

var watcher = sane(dir);
watcher.on('add', handler);
watcher.on('delete', handler);
watcher.on('change', handler);
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'll probably implement all event and update this amasad/sane#21

Add watching option to the binary.

The way this feature works is that it runs all tests on the first run when --watch is passed and then idles while watching the testPathDirs and when something is changed, deleted, or added, tests will be run that relates to the changed file (or dir).

I implemented this in TestRunner to be able to reuse it internally. And by doing so I had to move a lot of the file pattern matching logic into the class. But I think it's seems like it belonged there anyways.
@amasad
Copy link
Contributor Author

amasad commented Aug 19, 2014

Ping!

@jeffmo
Copy link
Contributor

jeffmo commented Aug 20, 2014

Whoa I hadn't even seen this -- I will take a look when I get back in on Thurs

* @return {Promise<Object>} Fulfilled with aggregate pass/fail information
* about the last run of tests.
*/
TestRunner.prototype.start = function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, right now TestRunner is structured as a library utility for various methods one might need to implement a CLI.
This is intentionally kept separate from the cli JS to support the ability to build custom CLI scripts as needed (for example, we use a custom CLI at Facebook -- but all of the common operations like finding files given a pattern, running tests in parallel/in-band, etc are just methods on the TestRunner object). The only reason TestRunner isn't just a bag of utility functions (i.e. the reason it's a class) is because all of the util functions depend on stuff from the config object. I'd like to keep this pattern because it will make it easier to write custom uses of the Jest libs -- vs pushing higher level CLI decisions down into the library.

That said, I think it makes a lot of sense for those helpers and methods to return a stream object rather than a Promise. I had started to refactor TestRunner to do this before, but didn't quite finish. It turns out we can squeeze other bits of perf out of doing this as well (but that's kind of a separate topic).

So rather than pushing interface-level decisions like "should I watch? or should I run on changed paths? (etc)" into TestRunner, it would be nice if we could just add another method to TestRunner that streams changed files back out to the CLI. That way CLIs can decide how they want to handle those events (maybe some CLIs may want to do some pre- or post-processing before running a test? Or report back to a logger? etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, right now TestRunner is structured as a library utility for various methods one might need to implement a CLI.

I got the impression that it's stateful class that's responsible for running the test suite. But now you mention this, things make more sense.

This is intentionally kept separate from the cli JS to support the ability to build custom CLI scripts as needed (for example, we use a custom CLI at Facebook -- but all of the common operations like finding files given a pattern, running tests in parallel/in-band, etc are just methods on the TestRunner object). The only reason TestRunner isn't just a bag of utility functions (i.e. the reason it's a class) is because all of the util functions depend on stuff from the config object. I'd like to keep this pattern because it will make it easier to write custom uses of the Jest libs -- vs pushing higher level CLI decisions down into the library.

Understandable. But in reality before I wrote this diff I had only glanced over the Facebook CLI code and just wrote this to work with the package's CLI. And then when it came time to integrate it in FB it was rather easy (after understanding the CLI code). Just moving of things from if statements and method calls to the options. That's what I thought it boiled down to, leaving a lot of the decisions duplicated in CLIs or push them down to the TestRunner. I guess my object-oriented habits wanted to centralize those decisions and push them down into the class. Not going to lie, for me it makes it easier to reason about the code.

That said, I think it makes a lot of sense for those helpers and methods to return a stream object rather than a Promise. I had started to refactor TestRunner to do this before, but didn't quite finish. It turns out we can squeeze other bits of perf out of doing this as well (but that's kind of a separate topic).

Yeah that sounds like a better design decision.

So rather than pushing interface-level decisions like "should I watch? or should I run on changed paths? (etc)" into TestRunner, it would be nice if we could just add another method to TestRunner that streams changed files back out to the CLI. That way CLIs can decide how they want to handle those events (maybe some CLIs may want to do some pre- or post-processing before running a test? Or report back to a logger? etc)

Cool, that sounds good as well.

@kentcdodds
Copy link
Contributor

ping

@mindreframer
Copy link

Ping, could this feature get a bit more love, please? It's so great to have instant feedback on saving, without leaving the editor....

@AGresvig
Copy link

AGresvig commented Nov 6, 2014

Ping!

1 similar comment
@tomchentw
Copy link

Ping!

@tombray
Copy link

tombray commented Dec 19, 2014

ping

@schickling
Copy link

+1

@jeffmo
Copy link
Contributor

jeffmo commented Jan 23, 2015

It looks like we left this in a place where some of the code needed to be moved around. I know @leebyron did a pretty big refactoring of the CLI code a month or so ago... @amasad: Think we could rebase this and get it in with the updated CLI?

Seems like lots of people are really interested in this

@fourcube
Copy link

+1

@amasad
Copy link
Contributor Author

amasad commented Jan 26, 2015

Cool, I think I'll send a new PR shortly

@eriklharper
Copy link

+1

2 similar comments
@steida
Copy link

steida commented Mar 15, 2015

+1

@ptmt
Copy link

ptmt commented Mar 20, 2015

👍

@hyzhak
Copy link

hyzhak commented Jul 9, 2015

👍

@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@cpojer
Copy link
Member

cpojer commented Aug 10, 2015

@amasad are you still working on this?

@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 14, 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.