From d5c0c2273f82e8ad2915dcb4334afc14902be062 Mon Sep 17 00:00:00 2001 From: Valeriy Date: Thu, 1 Nov 2018 18:56:15 +0300 Subject: [PATCH] test(curriculum): suppress redundant errors (#33327) - [x] I have read [freeCodeCamp's contribution guidelines](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/CONTRIBUTING.md). - [x] My pull request has a descriptive title (not a vague title like `Update index.md`) - [x] My pull request targets the `master` branch of freeCodeCamp. - [x] None of my changes are plagiarized from another source without proper attribution. - [x] My article does not contain shortened URLs or affiliate links. If your pull request closes a GitHub issue, replace the XXXXX below with the issue number. Closes #33195 --- curriculum/test/test-challenges.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/curriculum/test/test-challenges.js b/curriculum/test/test-challenges.js index 271d1709c6..3ce0f08218 100644 --- a/curriculum/test/test-challenges.js +++ b/curriculum/test/test-challenges.js @@ -1,4 +1,5 @@ -const assert = require('chai').assert; +const { assert, AssertionError } = require('chai'); +const Mocha = require('mocha'); const { flatten } = require('lodash'); const path = require('path'); @@ -26,6 +27,15 @@ const { challengeTypes } = require('../../client/utils/challengeTypes'); const { LOCALE: lang = 'english' } = process.env; +const oldRunnerFail = Mocha.Runner.prototype.fail; +Mocha.Runner.prototype.fail = function(test, err) { + // Don't show stacktrace for assertion errors. + if (err.stack && err instanceof AssertionError) { + delete err.stack; + } + return oldRunnerFail.call(this, test, err); +}; + let mongoIds = new MongoIds(); let challengeTitles = new ChallengeTitles(); @@ -127,6 +137,9 @@ const jQueryScript = fs.readFileSync( } it('Test suite must fail on the initial contents', async function() { + // suppress errors in the console. + const oldConsoleError = console.error; + console.error = () => {}; let fails = ( await Promise.all(tests.map(async function(test) { try { @@ -141,6 +154,7 @@ const jQueryScript = fs.readFileSync( return true; } }))).some(v => v); + console.error = oldConsoleError; assert(fails, 'Test suit does not fail on the initial contents'); });