From 00e6c2db8e948769d8747b7a0e5eab187d67efb8 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Sat, 3 Aug 2019 10:52:59 -0700 Subject: [PATCH 1/7] Type "rs\n" to restart tests, fixes #871 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. --- lib/cli/watch-run.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/cli/watch-run.js b/lib/cli/watch-run.js index e7ef34c632..cf162da684 100644 --- a/lib/cli/watch-run.js +++ b/lib/cli/watch-run.js @@ -77,6 +77,14 @@ module.exports = (mocha, {ui}, fileCollectParams) => { rerun(); } }); + + // 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') rerun(); + }); }; /** From d9f26443c45cd0d7dec692f7fa4158550f4fc2c8 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Sat, 3 Aug 2019 11:24:10 -0700 Subject: [PATCH 2/7] fix lint errors, add unit test --- lib/cli/watch-run.js | 5 ++++- test/integration/options/watch.spec.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/cli/watch-run.js b/lib/cli/watch-run.js index cf162da684..aa79fa8562 100644 --- a/lib/cli/watch-run.js +++ b/lib/cli/watch-run.js @@ -82,7 +82,10 @@ module.exports = (mocha, {ui}, fileCollectParams) => { process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', data => { - const str = data.toString().trim().toLowerCase(); + const str = data + .toString() + .trim() + .toLowerCase(); if (str === 'rs') rerun(); }); }; diff --git a/test/integration/options/watch.spec.js b/test/integration/options/watch.spec.js index 5d9fb2f26a..3690844f58 100644 --- a/test/integration/options/watch.spec.js +++ b/test/integration/options/watch.spec.js @@ -49,6 +49,17 @@ describe('--watch', function() { }); }); + it('reruns test when "rs\\n" typed', function() { + const testFile = path.join(this.tempDir, 'test.js'); + copyFixture('__default__', testFile); + + return runMochaWatch([testFile], this.tempDir, () => { + process.stdin.write('rs\n'); + }).then(results => { + expect(results, 'to have length', 2); + }); + }); + it('ignores files in "node_modules" and ".git" by default', function() { const testFile = path.join(this.tempDir, 'test.js'); copyFixture('__default__', testFile); From 22a559b5814334fe97c771c5b44fea4b11e86706 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Sat, 3 Aug 2019 12:57:44 -0700 Subject: [PATCH 3/7] write to mochaProcess.stdin --- test/integration/options/watch.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/options/watch.spec.js b/test/integration/options/watch.spec.js index 3690844f58..10c7b932ed 100644 --- a/test/integration/options/watch.spec.js +++ b/test/integration/options/watch.spec.js @@ -53,8 +53,8 @@ describe('--watch', function() { const testFile = path.join(this.tempDir, 'test.js'); copyFixture('__default__', testFile); - return runMochaWatch([testFile], this.tempDir, () => { - process.stdin.write('rs\n'); + return runMochaWatch([testFile], this.tempDir, mochaProcess => { + mochaProcess.stdin.write('rs\n'); }).then(results => { expect(results, 'to have length', 2); }); @@ -155,11 +155,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'); From 833e7b0512ee5ba16fc3b2c63b5b88404bf37119 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Sat, 3 Aug 2019 13:10:48 -0700 Subject: [PATCH 4/7] Trigger travis build From 0c5e0fbb1eae699a2631ede92eea5a4f204a2070 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Fri, 22 Nov 2019 17:31:24 -0800 Subject: [PATCH 5/7] add documentation --- docs/index.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/index.md b/docs/index.md index 4aea617d29..906eda2d26 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 ` > _New in v7.0.0_ @@ -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}_ +`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 From 24c48582a638e2e0cc308200659eb529b0acf949 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Sat, 23 Nov 2019 12:05:02 -0800 Subject: [PATCH 6/7] restore trailing whitespace --- docs/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/index.md b/docs/index.md index 906eda2d26..ef56724ee4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1580,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}_ +`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 From 3ee6c78a3cb95cd0ee4c8572d5829a1243235299 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Sun, 24 Nov 2019 07:08:18 -0800 Subject: [PATCH 7/7] empty commit (to rerun tests)