Newer
Older
percord / util / tests / setupJest.js
@Flam3rboy Flam3rboy on 29 Aug 2021 530 bytes :sparkles: update util
const { performance } = require("perf_hooks");
const fs = require("fs");
const path = require("path");

// fs.unlinkSync(path.join(__dirname, "..", "database.db"));

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}`,
		};
	},
});