From 964df70c8e02cc358222a8de20f5a5af89bd03b8 Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Mon, 18 Oct 2021 15:34:47 +0300 Subject: [PATCH] Add test on failOnFailingTestSuite --- .../fixtures/require-undefined.fixture.js | 11 ++++++++++ .../options/failOnFailingTestSuite.spec.js | 22 +++++++++++++++++++ test/unit/mocha.spec.js | 22 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 test/integration/fixtures/require-undefined.fixture.js create mode 100644 test/integration/options/failOnFailingTestSuite.spec.js diff --git a/test/integration/fixtures/require-undefined.fixture.js b/test/integration/fixtures/require-undefined.fixture.js new file mode 100644 index 0000000000..3afbeab5ba --- /dev/null +++ b/test/integration/fixtures/require-undefined.fixture.js @@ -0,0 +1,11 @@ +// this generic fixture does nothing special and will be used if no fixture is supplied + +'use strict'; + +var assert = require('assert'); + +describe('a suite', function() { + it('should succeed', function() { + assert(false); + }); +}); diff --git a/test/integration/options/failOnFailingTestSuite.spec.js b/test/integration/options/failOnFailingTestSuite.spec.js new file mode 100644 index 0000000000..7834ef693b --- /dev/null +++ b/test/integration/options/failOnFailingTestSuite.spec.js @@ -0,0 +1,22 @@ +'use strict'; + +var helpers = require('../helpers'); +var runMochaJSON = helpers.runMochaJSON; + +describe('--fail-on-failing-test-suite', function() { + var args = ['--fail-on-failing-test-suite=false']; + + it('should success', function(done) { + var fixture = 'require-undefined.fixture.js'; + runMochaJSON(fixture, args, function(err, res) { + if (err) { + return done(err); + } + + expect(res, 'to have passed test count', 0) + .and('to have test count', 1) + .and('to have exit code', 0); + done(); + }); + }); +}); diff --git a/test/unit/mocha.spec.js b/test/unit/mocha.spec.js index f966e0c3e7..9a768d62d3 100644 --- a/test/unit/mocha.spec.js +++ b/test/unit/mocha.spec.js @@ -376,6 +376,28 @@ describe('Mocha', function () { }); }); + describe('failOnFailingTestSuite()', function() { + it('should set the failOnFailingTestSuite option to true', function() { + mocha.failOnFailingTestSuite(); + expect( + mocha.options, + 'to have property', + 'failOnFailingTestSuite', + true + ); + }); + + it('should set the failOnFailingTestSuite option to false', function() { + mocha.failOnFailingTestSuite(false); + expect( + mocha.options, + 'to have property', + 'failOnFailingTestSuite', + false + ); + }); + }); + describe('failZero()', function () { it('should set the failZero option to true', function () { mocha.failZero();