fix: make challenge test errors more informative (#37020)

This commit is contained in:
Oliver Eyton-Williams
2019-10-04 12:16:30 +02:00
committed by mrugesh
parent 7128eb0211
commit 2066ed674b

View File

@ -257,7 +257,7 @@ function populateTestsForLang({ lang, challenges }) {
describe('Check tests against solutions', function() { describe('Check tests against solutions', function() {
solutions.forEach((solution, index) => { solutions.forEach((solution, index) => {
it(`Solution ${index + 1}`, async function() { it(`Solution ${index + 1} must pass the tests`, async function() {
this.timeout(5000 * tests.length + 1000); this.timeout(5000 * tests.length + 1000);
const testRunner = await createTestRunner( const testRunner = await createTestRunner(
{ ...challenge, files }, { ...challenge, files },
@ -311,13 +311,10 @@ async function createTestRunnerForDOMChallenge(
}, testString) }, testString)
]); ]);
if (!pass) { if (!pass) {
throw AssertionError(`${text}\n${err.message}`); throw new AssertionError(err.message);
} }
} catch (err) { } catch (err) {
throw typeof err === 'string' reThrow(err, text);
? `${text}\n${err}`
: (err.message = `${text}
${err.message}`);
} }
}; };
} }
@ -338,13 +335,23 @@ async function createTestRunnerForJSChallenge({ files }, solution) {
5000 5000
).done; ).done;
if (!pass) { if (!pass) {
throw new AssertionError(`${text}\n${err.message}`); throw new AssertionError(err.message);
} }
} catch (err) { } catch (err) {
throw typeof err === 'string' reThrow(err, text);
? `${text}\n${err}`
: (err.message = `${text}
${err.message}`);
} }
}; };
} }
function reThrow(err, text) {
if (typeof err === 'string') {
throw new AssertionError(
`${text}
${err}`
);
} else {
err.message = `${text}
${err.message}`;
throw err;
}
}