mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
improve E2E tests assertion output
This commit is contained in:
parent
6b275171b1
commit
3109a92b19
2 changed files with 15 additions and 10 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue