Navigation Menu

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

Type "rs\n" to restart tests, fixes #871 #3979

Merged
merged 8 commits into from Dec 13, 2019
Merged

Type "rs\n" to restart tests, fixes #871 #3979

merged 8 commits into from Dec 13, 2019

Conversation

broofa
Copy link
Contributor

@broofa broofa commented Aug 3, 2019

Description of the Change

Add a keyboard shortcut (rs\n) for manually restarting tests when running the CLI in watch (--watch) mode.Although the --watch feature is somewhat controversial (see #1780), hopefully it's okay to make minor improvements while that debate is being hashed out?

To test this feature:

  1. mocha -w to run CLI in watch mode
  2. Type [r] [s] [Enter]
  3. Notice that tests restart

Alternate Designs

This feature mimics the behavior of the popular nodemon module, so should be familiar to many developers. (And, in fact, the code is cribbed pretty much straight from nodemon)

Why should this be in core?

This is a minor tweak to behavior already in core (--watch). Although the watch feature is somewhat controversial (see #1780), hopefully there's no reason not to make minor improvements as long as it's supported.

Benefits

Provides behavior that many developers are familiar with in similar tool(s) - specifically nodemon.

Possible Drawbacks

This may make using stdin in the CLI (watch mode) problematic in the future, however that seems like a pretty abstract concern, and mocha does not appear to do anything with stdin at this time

Applicable issues

None that I'm aware of.

This is an enhancement (semver "minor" release)

Although the `--watch` feature is somewhat controversial (see #1780), is there any reason not to make it a little easier to use in the meantime?   This adds nodemon's shortcut (`rs\n`) for manually restarting.
@jsf-clabot
Copy link

jsf-clabot commented Aug 3, 2019

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link

coveralls commented Aug 3, 2019

Coverage Status

Coverage increased (+0.08%) to 92.804% when pulling 3ee6c78 on broofa:patch-1 into 2e9c28a on mochajs:master.

@createthis
Copy link

@broofa I am searching for ways to improve my heavily disk-laden test executions due to multiple import/require statements, so I thought I would give your branch a test run.

This code does not appear to work for me. In a multi-file system where my test requires another file, if I modify the required file and type "rs\n" I see the files re-run, but the required file does not appear to have been reloaded from disk.

@broofa
Copy link
Contributor Author

broofa commented Sep 3, 2019

@createthis Can you put up an SSCCE? I tried to repro your issue with the following (very simple) test, but wasn't able to. Modifying b.js (the required file) causes mocha to reload+rerun, without even having to hit "rs\n". "rs\n" reruns, of course, but since the files we're already reloaded by mocha, it behaves as-expected:

====
a.js:

let {hi, bye} = require('./b');

describe('HI', hi);
describe('BYE', bye);

b.js:

exports.hi = () => it('Hello', () => true);
exports.bye = () => it('Good Bye', () => true);

Command line:

$ mocha --watch a.js

Looking at the source code, I think this PR is doing the right thing - it calls rerun(), which calls the purge() function to have Mocha unload the files in question.

@createthis
Copy link

@broofa You right. This was user error. I was editing a jsx file without --extension js,jsx. I expected rs\n to reload everything but apparently it only reloads what it's watching.

@broofa
Copy link
Contributor Author

broofa commented Oct 23, 2019

@boneskull @craigtaub Any comment on the likelihood of this PR being accepted? 'Just wondering if I should bother figuring out how to resolve the conflicts (not quite as trivial a task as I thought initially.)

@craigtaub
Copy link
Contributor

craigtaub commented Nov 7, 2019

Sorry took a while to response. Nice change @broofa .

So relatively recently we actually swapped to using chokidar for handling watching (see #3980). If you could find a tidy way to do it with that it would be ideal.

@boneskull
Copy link
Member

thanks!! yes, this would be a good add if you want to work on it. otherwise, maybe someone will pick up where you left off.

@broofa
Copy link
Contributor Author

broofa commented Nov 8, 2019

Cool. I'm busy with work for the next month or so, but I'll try to find some time to patch this up. If someone wants to help out with it that'd be cool, too.

@broofa
Copy link
Contributor Author

broofa commented Nov 23, 2019

@boneskull Can you take another look at this? I've resolved conflicts and added a short description in "index.md". (Can't seem to build the site, though because node-gyp isn't installing properly for me at the moment. Also, I'm not sure why README.md is showing as changed - that seems to be an artifact of merging master. :-/)

docs/index.md Outdated Show resolved Hide resolved
@craigtaub
Copy link
Contributor

Small comment, but really it LGTM

@broofa
Copy link
Contributor Author

broofa commented Nov 24, 2019

@boneskull @craigtaub I think this ready to go. I'll be out of the country for the next couple of weeks. It'd be nice to see this merged before more conflicts develop. Thanks!

@broofa
Copy link
Contributor Author

broofa commented Dec 10, 2019

Ping: "It'd be nice to see this merged before more conflicts develop. Thanks!"

@craigtaub craigtaub added type: feature enhancement proposal semver-minor implementation requires increase of "minor" version number; "features" area: usability concerning user experience or interface labels Dec 13, 2019
@craigtaub
Copy link
Contributor

Tested locally. Seems good.

@craigtaub craigtaub merged commit aab8555 into mochajs:master Dec 13, 2019
@craigtaub craigtaub added this to the v7.0.0 milestone Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: usability concerning user experience or interface semver-minor implementation requires increase of "minor" version number; "features" type: feature enhancement proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants