Skip to content

Commit

Permalink
Add node:test runner and unit tests for API exports
Browse files Browse the repository at this point in the history
  • Loading branch information
robatron committed Feb 27, 2023
1 parent c0169d8 commit 71ab89d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"test": "npm-run-all build -p -r test:*",
"test:e2e": "wdio wdio.conf.cjs",
"test:server": "node test/server.js",
"test:unit": "node --test test/unit/",
"start": "run-s build:ts test:server watch",
"watch": "run-p watch:*",
"watch:ts": "tsc -b -w",
Expand Down
33 changes: 33 additions & 0 deletions test/unit/index-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';

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 71ab89d

Please sign in to comment.