improve E2E tests assertion output

This commit is contained in:
Jannis R 2020-05-22 16:09:25 +02:00 committed by Jannis Redmann
parent 6b275171b1
commit 3109a92b19
2 changed files with 15 additions and 10 deletions

View file

@ -1,6 +1,7 @@
'use strict' 'use strict'
const isRoughlyEqual = require('is-roughly-equal') const isRoughlyEqual = require('is-roughly-equal')
const {AssertionError} = require('assert')
const {DateTime} = require('luxon') const {DateTime} = require('luxon')
const a = require('assert') const a = require('assert')
const {join} = require('path') const {join} = require('path')
@ -27,7 +28,15 @@ const assertValidWhen = (actual, expected, name) => {
const ts = +new Date(actual) const ts = +new Date(actual)
a.ok(!Number.isNaN(ts), name + ' is not parsable by Date') a.ok(!Number.isNaN(ts), name + ' is not parsable by Date')
// the timestamps might be from long-distance trains // 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 // HTTP request mocking

View file

@ -13,16 +13,12 @@ const create = (cfg, customValidators = {}) => {
Object.assign(val, customValidators) Object.assign(val, customValidators)
const validateFptfWith = (t, item, allowedTypes, name) => { const validateFptfWith = (t, item, allowedTypes, name) => {
try {
if ('string' === typeof allowedTypes) { if ('string' === typeof allowedTypes) {
val[allowedTypes](val, item, name) val[allowedTypes](val, item, name)
} else { } else {
anyOf(allowedTypes, val, item, name) anyOf(allowedTypes, val, item, name)
} }
t.pass(name + ' is valid') t.pass(name + ' is valid')
} catch (err) {
t.ifError(err) // todo: improve error logging
}
} }
return validateFptfWith return validateFptfWith
} }