Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ exports.runMocha = (mocha, options) => {
const {
watch = false,
extension = [],
grep = '',
ui = 'bdd',
exit = false,
ignore = [],
Expand All @@ -138,7 +137,7 @@ exports.runMocha = (mocha, options) => {
};

if (watch) {
watchRun(mocha, {ui, grep}, fileCollectParams);
watchRun(mocha, {ui}, fileCollectParams);
} else {
exports.singleRun(mocha, {exit}, fileCollectParams);
}
Expand Down
6 changes: 1 addition & 5 deletions lib/cli/watch-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ const collectFiles = require('./collect-files');
* Run Mocha in "watch" mode
* @param {Mocha} mocha - Mocha instance
* @param {Object} opts - Options
* @param {string|RegExp} opts.grep - Grep for test titles
* @param {string} opts.ui - User interface
* @param {Object} fileCollectParams - Parameters that control test
* file collection. See `lib/cli/collect-files.js`.
* @param {string[]} fileCollectParams.extension - List of extensions to watch
* @private
*/
module.exports = (mocha, {grep, ui}, fileCollectParams) => {
module.exports = (mocha, {ui}, fileCollectParams) => {
let runner;
const files = collectFiles(fileCollectParams);

Expand Down Expand Up @@ -64,9 +63,6 @@ module.exports = (mocha, {grep, ui}, fileCollectParams) => {
const rerun = () => {
purge();
eraseLine();
if (!grep) {
mocha.grep(null);
}
mocha.suite = mocha.suite.clone();
mocha.suite.ctx = new Context();
mocha.ui(ui);
Expand Down
20 changes: 17 additions & 3 deletions test/integration/options/watch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ describe('--watch', function() {
expect(results[1].failures, 'to have length', 1);
});
});

// Regression test for https://github.com/mochajs/mocha/issues/2027
it('respects --fgrep on re-runs', function() {
const testFile = path.join(this.tempDir, 'test.js');
copyFixture('options/grep', testFile);

return runMochaWatch([testFile, '--fgrep', 'match'], this.tempDir, () => {
touchFile(testFile);
}).then(results => {
expect(results, 'to have length', 2);
expect(results[0].tests, 'to have length', 2);
expect(results[1].tests, 'to have length', 2);
});
});
});
});

Expand Down Expand Up @@ -160,7 +174,7 @@ function touchFile(file) {
}

/**
* Synchronously eplace all substrings matched by `pattern` with
* Synchronously replace all substrings matched by `pattern` with
* `replacement` in the file’s content.
*/
function replaceFileContents(file, pattern, replacement) {
Expand All @@ -170,8 +184,8 @@ function replaceFileContents(file, pattern, replacement) {
}

/**
* Synchronously copy a fixture to the given destion file path. Creates
* parent directories of the destination path if necessary.
* Synchronously copy a fixture to the given destination file path.
* Creates parent directories of the destination path if necessary.
*/
function copyFixture(fixtureName, dest) {
const fixtureSource = helpers.resolveFixturePath(fixtureName);
Expand Down