UNPKG

@tapjs/reporter

Version:
17 lines 679 B
import { useLayoutEffect, useState } from 'react'; import { listenCleanup } from '../listen-cleanup.js'; export const useTestTime = (test, interval = 247) => { const [time, updateTime] = useState(test.time); const [start] = useState(Date.now()); useLayoutEffect(() => { const i = test.time ? null : (setInterval(() => updateTime(Date.now() - start), interval)); const maybeCT = () => (i === null ? null : clearTimeout(i)); const cleanup = listenCleanup(test, 'complete', maybeCT); return () => { maybeCT(); cleanup(); }; }, [test.time]); return time; }; //# sourceMappingURL=use-test-time.js.map