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
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -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)
Expand All @@ -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

Expand Down
8 changes: 5 additions & 3 deletions docs/index.md
Expand Up @@ -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_
Expand Down Expand Up @@ -1578,17 +1580,17 @@ mocha.setup({

### Browser-specific Option(s)

Browser Mocha supports many, but not all [cli options](#command-line-usage).
Browser Mocha supports many, but not all [cli options](#command-line-usage).
To use a [cli option](#command-line-usage) that contains a "-", please convert the option to camel-case, (eg. `check-leaks` to `checkLeaks`).

#### Options that differ slightly from [cli options](#command-line-usage):

`reporter` _{string|constructor}_
broofa marked this conversation as resolved.
Show resolved Hide resolved
`reporter` _{string|constructor}_
You can pass a reporter's name or a custom reporter's constructor. You can find **recommended** reporters for the browser [here](#reporting). It is possible to use [built-in reporters](#reporters) as well. Their employment in browsers is neither recommended nor supported, open the console to see the test results.

#### Options that _only_ function in browser context:

`noHighlighting` _{boolean}_
`noHighlighting` _{boolean}_
If set to `true`, do not attempt to use syntax highlighting on output test code.

### Reporting
Expand Down
11 changes: 11 additions & 0 deletions lib/cli/watch-run.js
Expand Up @@ -68,6 +68,17 @@ module.exports = (mocha, {watchFiles, watchIgnore}, fileCollectParams) => {
// killed by SIGINT which has portable number 2.
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();
});
};

/**
Expand Down
15 changes: 13 additions & 2 deletions test/integration/options/watch.spec.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down