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

CLI: Add file watching option #1123

Merged
merged 2 commits into from
Mar 28, 2017
Merged

Conversation

trentmwillis
Copy link
Member

@trentmwillis trentmwillis commented Mar 24, 2017

This PR introduces a --watch option to the CLI so that tests will re-run when a file is added, changed, or removed from the working directory. It also ensures that if one of the above occurs while tests are executing, then the current test finishes and does any cleanup (via after/afterEach hooks) before restarting.

This depends on #1121 and #1124. I recommend not reviewing until both of those PRs are merged, because this PR will be much simpler afterward.

Todo:

  • Figure out why tests are hanging in Travis

@trentmwillis trentmwillis force-pushed the cli-watch branch 17 times, most recently from 735bbae to 89f151f Compare March 24, 2017 19:23
@trentmwillis trentmwillis changed the title [WIP] CLI: Add file watching option CLI: Add file watching option Mar 25, 2017
@trentmwillis trentmwillis mentioned this pull request Mar 25, 2017

run.watch = function watch() {
const chokidar = require( "chokidar" );
const args = Array.prototype.slice.call( arguments );
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use a rest parameter instead of slicing the arguments object here.

console.log( "Restarting..." );
}

run.abort( () => run.apply( null, args ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use the spread operator here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Spread/rest are not supported in Node 4 unfortunately 😞 https://kangax.github.io/compat-table/es6/#test-rest_parameters

bin/run.js Outdated
}
} );
} else {
delete global.QUnit;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any point in extracting this logic to a closure, so that this code isn't duplicated with the above case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion, I meant to do that but forgot.

const sig = signal || "SIGINT";

// Linux increments the pid by 1 due to creating a new shell instance
if ( process.platform === "linux" ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about OSX or MacOS? Can this be detected any better? Can we do a kill-with-children sort of thing on the process so we don't even need to worry about whether a grandchild process was even spawned?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could add more logic and special case per-platform, but I'd rather keep this simple to start and evolve it as needed over time.

The kill-with-child thing isn't really applicable, because we don't want to kill the parent process (which is the test suite running).

@platinumazure
Copy link
Contributor

LGTM, but left some nitpicks just in case you want to address them.

@trentmwillis
Copy link
Member Author

Thanks for the review!

@trentmwillis trentmwillis deleted the cli-watch branch March 28, 2017 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants