Skip to content

Commit 88f45d5

Browse files
Thomas Scholtesjuergba
authored andcommitted
Don't re-initialize grep option on watch re-run (#3960)
We remove code that called `mocha.grep(null)` on watch re-runs if the `--grep` option was not supplied. The code seems to serve no purpose and is the cause of #2027.
1 parent 5d4dd98 commit 88f45d5

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

lib/cli/run-helpers.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ exports.runMocha = (mocha, options) => {
118118
const {
119119
watch = false,
120120
extension = [],
121-
grep = '',
122121
ui = 'bdd',
123122
exit = false,
124123
ignore = [],
@@ -138,7 +137,7 @@ exports.runMocha = (mocha, options) => {
138137
};
139138

140139
if (watch) {
141-
watchRun(mocha, {ui, grep}, fileCollectParams);
140+
watchRun(mocha, {ui}, fileCollectParams);
142141
} else {
143142
exports.singleRun(mocha, {exit}, fileCollectParams);
144143
}

lib/cli/watch-run.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ const collectFiles = require('./collect-files');
1616
* Run Mocha in "watch" mode
1717
* @param {Mocha} mocha - Mocha instance
1818
* @param {Object} opts - Options
19-
* @param {string|RegExp} opts.grep - Grep for test titles
2019
* @param {string} opts.ui - User interface
2120
* @param {Object} fileCollectParams - Parameters that control test
2221
* file collection. See `lib/cli/collect-files.js`.
2322
* @param {string[]} fileCollectParams.extension - List of extensions to watch
2423
* @private
2524
*/
26-
module.exports = (mocha, {grep, ui}, fileCollectParams) => {
25+
module.exports = (mocha, {ui}, fileCollectParams) => {
2726
let runner;
2827
const files = collectFiles(fileCollectParams);
2928

@@ -64,9 +63,6 @@ module.exports = (mocha, {grep, ui}, fileCollectParams) => {
6463
const rerun = () => {
6564
purge();
6665
eraseLine();
67-
if (!grep) {
68-
mocha.grep(null);
69-
}
7066
mocha.suite = mocha.suite.clone();
7167
mocha.suite.ctx = new Context();
7268
mocha.ui(ui);

test/integration/options/watch.spec.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ describe('--watch', function() {
115115
expect(results[1].failures, 'to have length', 1);
116116
});
117117
});
118+
119+
// Regression test for https://github.com/mochajs/mocha/issues/2027
120+
it('respects --fgrep on re-runs', function() {
121+
const testFile = path.join(this.tempDir, 'test.js');
122+
copyFixture('options/grep', testFile);
123+
124+
return runMochaWatch([testFile, '--fgrep', 'match'], this.tempDir, () => {
125+
touchFile(testFile);
126+
}).then(results => {
127+
expect(results, 'to have length', 2);
128+
expect(results[0].tests, 'to have length', 2);
129+
expect(results[1].tests, 'to have length', 2);
130+
});
131+
});
118132
});
119133
});
120134

@@ -160,7 +174,7 @@ function touchFile(file) {
160174
}
161175

162176
/**
163-
* Synchronously eplace all substrings matched by `pattern` with
177+
* Synchronously replace all substrings matched by `pattern` with
164178
* `replacement` in the file’s content.
165179
*/
166180
function replaceFileContents(file, pattern, replacement) {
@@ -170,8 +184,8 @@ function replaceFileContents(file, pattern, replacement) {
170184
}
171185

172186
/**
173-
* Synchronously copy a fixture to the given destion file path. Creates
174-
* parent directories of the destination path if necessary.
187+
* Synchronously copy a fixture to the given destination file path.
188+
* Creates parent directories of the destination path if necessary.
175189
*/
176190
function copyFixture(fixtureName, dest) {
177191
const fixtureSource = helpers.resolveFixturePath(fixtureName);

0 commit comments

Comments
 (0)