From c4426920a113b419c22f27eda347e5a04c108acc Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Thu, 26 Aug 2021 02:07:16 +0200 Subject: :bug: fix unit tests --- util/tests/setupJest.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 util/tests/setupJest.js (limited to 'util/tests/setupJest.js') 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}`, + }; + }, +}); -- cgit 1.5.1