Skip to content

Commit

Permalink
Add thresholds to attribution build (GoogleChrome#340)
Browse files Browse the repository at this point in the history
* Add thresholds to attribution build

* Add tests
  • Loading branch information
tunetheweb authored Apr 4, 2023
1 parent fb01e30 commit 2225d22
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/attribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
33 changes: 33 additions & 0 deletions test/unit/attribution-test.js
Original file line number Diff line number Diff line change
@@ -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]);
});
});

0 comments on commit 2225d22

Please sign in to comment.