From 1e1471556fa3c17d12c5f23ad34dbec2c20533cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Cabrera=20Dur=C3=A1n?= <pateketrueke@gmail.com> Date: Thu, 10 Oct 2019 10:09:37 -0500 Subject: [PATCH] Decorate ran tests on failure --- tests/schema/helpers.js | 20 ++++++++++++++------ tests/schema/main.spec.js | 6 ++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/schema/helpers.js b/tests/schema/helpers.js index 9275936b..936008c6 100644 --- a/tests/schema/helpers.js +++ b/tests/schema/helpers.js @@ -59,19 +59,27 @@ export function getTests(srcDir) { return { only, all }; } -export function tryTest(test, refs, schema) { +export function tryTest(nth, max, test, refs, schema) { return _jsf.resolve(schema, refs).then(sample => { if (test.dump) { console.log(JSON.stringify(sample, null, 2)); return; } - if (test.type) { - checkType(sample, test.type); - } + try { + if (test.type) { + checkType(sample, test.type); + } + + if (test.valid) { + checkSchema(sample, schema, refs); + } + } catch (e) { + const _e = new Error(`${e.message.split('\n')[0]} (${nth} of ${max})`); + + _e.stack = e.stack.split('\n').slice(1).join('\n'); - if (test.valid) { - checkSchema(sample, schema, refs); + throw _e; } if (test.length) { diff --git a/tests/schema/main.spec.js b/tests/schema/main.spec.js index f63bfd1c..b8096981 100644 --- a/tests/schema/main.spec.js +++ b/tests/schema/main.spec.js @@ -54,13 +54,15 @@ function seed() { // support for "exhaustive" testing, increase or set in .json spec // for detecting more bugs quickly by executing the same test N-times - let nth = test.repeat || (process.CI ? 100 : 10); + const max = test.repeat || (process.CI ? 100 : 10); + + let nth = max; const tasks = []; while (nth) { if (!test.skip) { - tasks.push(tryTest(test, refs, schema)); + tasks.push(tryTest(nth, max, test, refs, schema)); } nth -= 1; -- GitLab