mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
20 lines
412 B
JavaScript
20 lines
412 B
JavaScript
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}`,
|
|
};
|
|
},
|
|
});
|