summary refs log tree commit diff
path: root/util/tests/setupJest.js
blob: 551d2be59d6e8feff405b90fef533cf64716b9cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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}`,
		};
	},
});