From 2225d22a8a9ebcdbcc16efdc9528812c38703fb9 Mon Sep 17 00:00:00 2001 From: Barry Pollard Date: Tue, 4 Apr 2023 12:10:11 +0100 Subject: [PATCH] Add thresholds to attribution build (#340) * Add thresholds to attribution build * Add tests --- src/attribution.ts | 7 +++++++ test/unit/attribution-test.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/unit/attribution-test.js diff --git a/src/attribution.ts b/src/attribution.ts index ce911d3d..89fe99a0 100644 --- a/src/attribution.ts +++ b/src/attribution.ts @@ -21,4 +21,11 @@ export {onINP} from './attribution/onINP.js'; export {onLCP} from './attribution/onLCP.js'; export {onTTFB} from './attribution/onTTFB.js'; +export {CLSThresholds} from './onCLS.js'; +export {FCPThresholds} from './onFCP.js'; +export {FIDThresholds} from './onFID.js'; +export {INPThresholds} from './onINP.js'; +export {LCPThresholds} from './onLCP.js'; +export {TTFBThresholds} from './onTTFB.js'; + export * from './types.js'; diff --git a/test/unit/attribution-test.js b/test/unit/attribution-test.js new file mode 100644 index 00000000..be6f2be0 --- /dev/null +++ b/test/unit/attribution-test.js @@ -0,0 +1,33 @@ +import {describe, it} from 'node:test'; +import assert from 'assert'; +import { + onCLS, + onFCP, + onFID, + onINP, + onLCP, + onTTFB, + CLSThresholds, + FCPThresholds, + FIDThresholds, + INPThresholds, + LCPThresholds, + TTFBThresholds, +} from 'web-vitals/attribution'; + +describe('index', () => { + it('exports Web Vitals metrics functions', () => { + [onCLS, onFCP, onFID, onINP, onLCP, onTTFB].forEach((onFn) => + assert(typeof onFn === 'function') + ); + }); + + it('exports Web Vitals metric thresholds', () => { + assert.deepEqual(CLSThresholds, [0.1, 0.25]); + assert.deepEqual(FCPThresholds, [1800, 3000]); + assert.deepEqual(FIDThresholds, [100, 300]); + assert.deepEqual(INPThresholds, [200, 500]); + assert.deepEqual(LCPThresholds, [2500, 4000]); + assert.deepEqual(TTFBThresholds, [800, 1800]); + }); +});