Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

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

Robert Kiefferaab855538fe2
diff --git a/README.md b/README.md
index 6e083963..3dc8ac25 100644
--- a/README.md
+++ b/README.md
@@ -56,7 +56,7 @@
## Sponsors
-Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor).
+Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor).
[![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/0/avatar)](https://opencollective.com/mochajs/sponsor/0/website)
[![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/1/avatar)](https://opencollective.com/mochajs/sponsor/1/website)
@@ -83,12 +83,12 @@ Does your company use Mocha? Ask your manager or marketing team if your company
You might want to know that:
-- Mocha is the *most-depended-upon* module on npm (source: [libraries.io](https://libraries.io/search?order=desc&platforms=NPM&sort=dependents_count)), and
-- Mocha is an *independent* open-source project, maintained exclusively by volunteers.
+- Mocha is the _most-depended-upon_ module on npm (source: [libraries.io](https://libraries.io/search?order=desc&platforms=NPM&sort=dependents_count)), and
+- Mocha is an _independent_ open-source project, maintained exclusively by volunteers.
You might want to help:
-- New to contributing to Mocha? Check out this list of [good first issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3Agood-first-issue)
+- New to contributing to Mocha? Check out this list of [good first issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3Agood-first-issue)
- Mocha could use a hand with [these issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)
- The [maintainer's handbook](https://github.com/mochajs/mocha/blob/master/MAINTAINERS.md) explains how things get done
diff --git a/docs/index.md b/docs/index.md
index d3d53a0e..788dbf1e 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -1137,6 +1137,8 @@ Rerun tests on file changes.
The `--watch-files` and `--watch-ignore` options can be used to control which files are watched for changes.
+Tests may be rerun manually by typing ⓡ ⓢ ⏎ (same shortcut as `nodemon`).
+
### `--watch-files <file|directory|glob>`
> _New in v7.0.0_
diff --git a/lib/cli/watch-run.js b/lib/cli/watch-run.js
index dbb66ca4..b35a9069 100644
--- a/lib/cli/watch-run.js
+++ b/lib/cli/watch-run.js
@@ -63,6 +63,17 @@ module.exports = (mocha, {watchFiles, watchIgnore}, fileCollectParams) => {
console.log('\n');
process.exit(128 + 2);
});
+
+ // Keyboard shortcut for restarting when "rs\n" is typed (ala Nodemon)
+ process.stdin.resume();
+ process.stdin.setEncoding('utf8');
+ process.stdin.on('data', data => {
+ const str = data
+ .toString()
+ .trim()
+ .toLowerCase();
+ if (str === 'rs') rerunner.scheduleRun();
+ });
};
/**
diff --git a/test/integration/options/watch.spec.js b/test/integration/options/watch.spec.js
index 08433809..f5cd382d 100644
--- a/test/integration/options/watch.spec.js
+++ b/test/integration/options/watch.spec.js
@@ -137,6 +137,17 @@ describe('--watch', function() {
});
});
+ it('reruns when "rs\\n" typed', function() {
+ const testFile = path.join(this.tempDir, 'test.js');
+ copyFixture('__default__', testFile);
+
+ return runMochaWatch([testFile], this.tempDir, mochaProcess => {
+ mochaProcess.stdin.write('rs\n');
+ }).then(results => {
+ expect(results, 'to have length', 2);
+ });
+ });
+
it('reruns test when file starting with . and matching --extension is changed', function() {
const testFile = path.join(this.tempDir, 'test.js');
copyFixture('__default__', testFile);
@@ -282,11 +293,11 @@ describe('--watch', function() {
function runMochaWatch(args, cwd, change) {
const [mochaProcess, resultPromise] = helpers.invokeMochaAsync(
[...args, '--watch', '--reporter', 'json'],
- {cwd}
+ {cwd, stdio: 'pipe'}
);
return sleep(1000)
- .then(() => change())
+ .then(() => change(mochaProcess))
.then(() => sleep(1000))
.then(() => {
mochaProcess.kill('SIGINT');