From e9bd88d2456e076454637745913ac417bac17d01 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Thu, 27 Aug 2020 12:00:25 +0200 Subject: [PATCH] fix: make all unhandled errors fail tests --- curriculum/test/test-challenges.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/curriculum/test/test-challenges.js b/curriculum/test/test-challenges.js index 027e3cf75b..6ee07f5c6e 100644 --- a/curriculum/test/test-challenges.js +++ b/curriculum/test/test-challenges.js @@ -27,9 +27,6 @@ const { flatten } = require('lodash'); const jsdom = require('jsdom'); -const dom = new jsdom.JSDOM(''); -global.document = dom.window.document; - const vm = require('vm'); const puppeteer = require('puppeteer'); @@ -57,6 +54,18 @@ const { createPoly } = require('../../utils/polyvinyl'); const testEvaluator = require('../../client/config/test-evaluator').filename; +// rethrow unhandled rejections to make sure the tests exit with -1 +process.on('unhandledRejection', err => { + cleanup(); + // setting the error code because node does not (yet) exit with a non-zero + // code on unhandled exceptions. + process.exitCode = 1; + throw err; +}); + +const dom = new jsdom.JSDOM(''); +global.document = dom.window.document; + const oldRunnerFail = Mocha.Runner.prototype.fail; Mocha.Runner.prototype.fail = function(test, err) { if (err instanceof AssertionError) { @@ -194,11 +203,6 @@ function cleanup() { } function runTests(challengeData) { - // rethrow unhandled rejections to make sure the tests exit with -1 - process.on('unhandledRejection', err => { - throw err; - }); - describe('Check challenges', function() { after(function() { cleanup();