From 3109a92b1988ba2c78467c6322a7c12527940fe4 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 22 May 2020 16:09:25 +0200 Subject: [PATCH] improve E2E tests assertion output --- test/e2e/lib/util.js | 11 ++++++++++- test/e2e/lib/validate-fptf-with.js | 14 +++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/test/e2e/lib/util.js b/test/e2e/lib/util.js index 3050563f..3dd8162d 100644 --- a/test/e2e/lib/util.js +++ b/test/e2e/lib/util.js @@ -1,6 +1,7 @@ 'use strict' const isRoughlyEqual = require('is-roughly-equal') +const {AssertionError} = require('assert') const {DateTime} = require('luxon') const a = require('assert') const {join} = require('path') @@ -27,7 +28,15 @@ const assertValidWhen = (actual, expected, name) => { const ts = +new Date(actual) a.ok(!Number.isNaN(ts), name + ' is not parsable by Date') // the timestamps might be from long-distance trains - a.ok(isRoughlyEqual(day + 6 * hour, +expected, ts), name + ' is out of range') + const delta = day + 6 * hour + if (!isRoughlyEqual(delta, +expected, ts)) { + throw new AssertionError({ + message: name + ' is out of range', + actual: ts, + expected: `${expected - delta} - ${+expected + delta}`, + operator: 'isRoughlyEqual', + }) + } } // HTTP request mocking diff --git a/test/e2e/lib/validate-fptf-with.js b/test/e2e/lib/validate-fptf-with.js index 9db61db5..eb77f417 100644 --- a/test/e2e/lib/validate-fptf-with.js +++ b/test/e2e/lib/validate-fptf-with.js @@ -13,16 +13,12 @@ const create = (cfg, customValidators = {}) => { Object.assign(val, customValidators) const validateFptfWith = (t, item, allowedTypes, name) => { - try { - if ('string' === typeof allowedTypes) { - val[allowedTypes](val, item, name) - } else { - anyOf(allowedTypes, val, item, name) - } - t.pass(name + ' is valid') - } catch (err) { - t.ifError(err) // todo: improve error logging + if ('string' === typeof allowedTypes) { + val[allowedTypes](val, item, name) + } else { + anyOf(allowedTypes, val, item, name) } + t.pass(name + ' is valid') } return validateFptfWith }