summary refs log tree commit diff
path: root/util/tests/setupJest.js
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-26 02:07:16 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-26 02:07:16 +0200
commitc4426920a113b419c22f27eda347e5a04c108acc (patch)
treee475e8af64c3e6c7e6086c1cc09c3a8daa9046a0 /util/tests/setupJest.js
parent:sparkles: unit test (diff)
downloadserver-c4426920a113b419c22f27eda347e5a04c108acc.tar.xz
:bug: fix unit tests
Diffstat (limited to 'util/tests/setupJest.js')
-rw-r--r--util/tests/setupJest.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/util/tests/setupJest.js b/util/tests/setupJest.js
new file mode 100644

index 00000000..551d2be5 --- /dev/null +++ b/util/tests/setupJest.js
@@ -0,0 +1,19 @@ +const { performance } = require("perf_hooks"); + +global.expect.extend({ + toBeFasterThan: async (func, target) => { + const start = performance.now(); + var error; + try { + await func(); + } catch (e) { + error = e.toString(); + } + const time = performance.now() - start; + + return { + pass: time < target && !error, + message: () => error || `${func.name} took ${time}ms of maximum ${target}`, + }; + }, +});