From 76fa998f9fc55197f48c9592b0cc329ec1bf8f28 Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Wed, 20 Feb 2019 19:14:58 -0600 Subject: [PATCH] fix(cli): Add new cmdline option to denote implicit returns CoffeeScript has implicit returns. The change made to deprecate suites returning a value causes a warning for _every_ `describe`. This adds a cmdline option to disable the deprecation warning. Fixes #3744 --- lib/cli/run-option-metadata.js | 1 + lib/cli/run.js | 4 ++++ lib/interfaces/common.js | 15 +++++++++------ lib/mocha.js | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/cli/run-option-metadata.js b/lib/cli/run-option-metadata.js index 0838e6050c..223c3a1861 100644 --- a/lib/cli/run-option-metadata.js +++ b/lib/cli/run-option-metadata.js @@ -35,6 +35,7 @@ exports.types = { 'forbid-pending', 'full-trace', 'growl', + 'implicit-returns', 'inline-diffs', 'interfaces', 'invert', diff --git a/lib/cli/run.js b/lib/cli/run.js index d10b89f637..8a8a8a7ae1 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -143,6 +143,10 @@ exports.builder = yargs => description: 'Enable Growl notifications', group: GROUPS.OUTPUT }, + 'implicit-returns': { + description: 'Denote source language uses implicit returns', + group: GROUPS.RULES + }, 'inline-diffs': { description: 'Display actual/expected differences inline within each string', diff --git a/lib/interfaces/common.js b/lib/interfaces/common.js index 976b4d7a65..cdefd68db2 100644 --- a/lib/interfaces/common.js +++ b/lib/interfaces/common.js @@ -1,9 +1,11 @@ 'use strict'; +var util = require('util'); var Suite = require('../suite'); var utils = require('../utils'); var errors = require('../errors'); var createMissingArgumentError = errors.createMissingArgumentError; +var dQuote = utils.dQuote; /** * Functions common to more than one interface. @@ -139,13 +141,14 @@ module.exports = function(suites, context, mocha) { } if (typeof opts.fn === 'function') { var result = opts.fn.call(suite); - if (typeof result !== 'undefined') { + if (typeof result !== 'undefined' && !mocha.options.implicitReturns) { utils.deprecate( - 'Suites ignore return values. Suite "' + - suite.fullTitle() + - '" in ' + - suite.file + - ' returned a value; this may be a bug in your test code' + util.format( + 'Suites ignore return values. Suite %s in %s returned a value; ' + + 'this may be a bug in your test code', + dQuote(suite.fullTitle()), + dQuote(suite.file) + ) ); } suites.shift(); diff --git a/lib/mocha.js b/lib/mocha.js index 2b2dc13341..d597234495 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -81,6 +81,7 @@ exports.Test = require('./test'); * @param {boolean} [options.growl] - Enable desktop notifications? * @param {boolean} [options.hideDiff] - Suppress diffs from failures? * @param {boolean} [options.ignoreLeaks] - Ignore global leaks? + * @param {boolean} [options.implicitReturns] - Language uses implicit returns? * @param {boolean} [options.invert] - Invert test filter matches? * @param {boolean} [options.noHighlighting] - Disable syntax highlighting? * @param {string} [options.reporter] - Reporter name.