@zendesk/react-measure-timing-hooks
Version:
react hooks for measuring time to interactive and time to render of components
49 lines • 2.83 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const getDynamicQuietWindowDuration_1 = require("./getDynamicQuietWindowDuration");
// Constants for testing
const FMP = 0; // Simulate FMP at time 0
const EPSILON = 0.001; // Allowable error for floating-point calculations
(0, vitest_1.describe)('createQuietWindowDurationCalculator', () => {
const calculateQuietWindowDuration = (0, getDynamicQuietWindowDuration_1.createQuietWindowDurationCalculator)({
D0: 5_000,
Dx: 3_000,
x: 15,
DInfinity: 1_000,
});
(0, vitest_1.it)('should return 5 seconds (5000 ms) at FMP', () => {
const duration = calculateQuietWindowDuration(FMP, FMP);
(0, vitest_1.expect)(duration).toBeCloseTo(5_000, EPSILON);
});
(0, vitest_1.it)('should return approximately 3 seconds (3000 ms) at 15 seconds after FMP', () => {
const duration = calculateQuietWindowDuration(FMP + 15_000, FMP);
(0, vitest_1.expect)(duration).toBeCloseTo(3_000, EPSILON);
});
(0, vitest_1.it)('should approach 1 second (1000 ms) as time progresses far beyond FMP', () => {
const duration = calculateQuietWindowDuration(FMP + 60_000, FMP); // 60 seconds after FMP
(0, vitest_1.expect)(duration).toBeCloseTo(1_250, EPSILON);
});
(0, vitest_1.it)('should never return a value lower than 1 second (1000 ms)', () => {
const duration = calculateQuietWindowDuration(FMP + 1_000_000, FMP); // Far future time
(0, vitest_1.expect)(duration).toBeGreaterThanOrEqual(1_000);
(0, vitest_1.expect)(duration).toBeCloseTo(1_000);
});
(0, vitest_1.it)('should decrease over time from FMP', () => {
const durationAtFMP = calculateQuietWindowDuration(FMP, FMP);
const durationAt5Sec = calculateQuietWindowDuration(FMP + 5_000, FMP);
const durationAt10Sec = calculateQuietWindowDuration(FMP + 10_000, FMP);
const durationAt15Sec = calculateQuietWindowDuration(FMP + 15_000, FMP);
(0, vitest_1.expect)(durationAtFMP).toBeGreaterThan(durationAt5Sec);
(0, vitest_1.expect)(durationAt5Sec).toBeGreaterThan(durationAt10Sec);
(0, vitest_1.expect)(durationAt10Sec).toBeGreaterThan(durationAt15Sec);
});
(0, vitest_1.it)('should work correctly with non-zero FMP values', () => {
const customFMP = 2_000; // FMP at 2 seconds
const durationAtFMP = calculateQuietWindowDuration(customFMP, customFMP);
const durationAt5Sec = calculateQuietWindowDuration(customFMP + 5_000, customFMP);
(0, vitest_1.expect)(durationAtFMP).toBeCloseTo(5_000, EPSILON);
(0, vitest_1.expect)(durationAtFMP).toBeGreaterThan(durationAt5Sec);
});
});
//# sourceMappingURL=getDynamicQuietWindowDuration.test.js.map
;