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 28, 2023
1 parent f55e289 commit 25105d6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@
"release:major": "npm version major -m 'Release v%s' && npm publish",
"release:minor": "npm version minor -m 'Release v%s' && npm publish",
"release:patch": "npm version patch -m 'Release v%s' && npm publish",
"test": "npm-run-all build -p -r test:*",
"test": "npm-run-all build test:unit -p -r test:e2e test:server",
"test:e2e": "wdio wdio.conf.cjs",
"test:server": "node test/server.js",
"test:unit": "node --test test/unit/*test.js",
"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 25105d6

Please sign in to comment.