@rn-perf-kit/core 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
1
  {
2
2
  "name": "@rn-perf-kit/core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Core timeline, ring buffer, event model and budget engine for rn-perf-kit",
5
+ "main": "./src/index.ts",
6
+ "types": "./src/index.ts",
7
+ "scripts": {
8
+ "build": "tsc --project tsconfig.build.json",
9
+ "typecheck": "tsc --noEmit",
10
+ "lint": "eslint src/",
11
+ "test": "jest",
12
+ "clean": "rm -rf dist"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^5.3.0",
16
+ "@types/jest": "^29.0.0",
17
+ "jest": "^29.0.0",
18
+ "ts-jest": "^29.0.0"
19
+ }
20
+ }
@@ -0,0 +1,21 @@
1
+ import { PerfClock } from '../clock';
2
+
3
+ describe('PerfClock', () => {
4
+ it('converts native timestamps to JS timeline', () => {
5
+ const clock = new PerfClock();
6
+ let callCount = 0;
7
+ jest.spyOn(clock as any, 'jsNow').mockImplementation(() => {
8
+ return callCount++ === 0 ? 100 : 102;
9
+ });
10
+ clock.install(() => 200, 999_999);
11
+ const result = clock.nativeToJs(300);
12
+ // offset = 200 - 101 = 99, so 300 - 99 = 201
13
+ expect(result).toBeCloseTo(201, 0);
14
+ clock.uninstall();
15
+ });
16
+
17
+ it('falls back gracefully before first sync', () => {
18
+ const clock = new PerfClock();
19
+ expect(clock.nativeToJs(500)).toBe(500);
20
+ });
21
+ });
@@ -0,0 +1,45 @@
1
+ import { RingBuffer } from '../ring-buffer';
2
+ import type { PerfEvent } from '../events';
3
+
4
+ function makeStall(t: number, dur = 10): PerfEvent {
5
+ return { type: 'stall', t, dur };
6
+ }
7
+
8
+ describe('RingBuffer', () => {
9
+ it('stores and returns events in order', () => {
10
+ const buf = new RingBuffer({ capacity: 5 });
11
+ buf.push(makeStall(100));
12
+ buf.push(makeStall(200));
13
+ buf.push(makeStall(300));
14
+ const events = buf.query();
15
+ expect(events).toHaveLength(3);
16
+ expect(events[0].t).toBe(100);
17
+ expect(events[2].t).toBe(300);
18
+ });
19
+
20
+ it('overwrites oldest events when full', () => {
21
+ const buf = new RingBuffer({ capacity: 3 });
22
+ buf.push(makeStall(1));
23
+ buf.push(makeStall(2));
24
+ buf.push(makeStall(3));
25
+ buf.push(makeStall(4));
26
+ const events = buf.query();
27
+ expect(events).toHaveLength(3);
28
+ expect(events.map((e) => e.t)).toEqual([2, 3, 4]);
29
+ });
30
+
31
+ it('filters by time range', () => {
32
+ const buf = new RingBuffer({ capacity: 10 });
33
+ for (let i = 0; i < 10; i++) buf.push(makeStall(i * 100));
34
+ const slice = buf.query(200, 500);
35
+ expect(slice.map((e) => e.t)).toEqual([200, 300, 400, 500]);
36
+ });
37
+
38
+ it('reports correct size', () => {
39
+ const buf = new RingBuffer({ capacity: 5 });
40
+ expect(buf.size).toBe(0);
41
+ buf.push(makeStall(1));
42
+ buf.push(makeStall(2));
43
+ expect(buf.size).toBe(2);
44
+ });
45
+ });
package/src/budgets.ts ADDED
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Budget model and violation tracking.
3
+ * Budgets are tier-aware: LOW / MID / HIGH device classifications.
4
+ */
5
+
6
+ export type DeviceTier = 'LOW' | 'MID' | 'HIGH';
7
+
8
+ export interface TieredBudget {
9
+ LOW: number;
10
+ MID: number;
11
+ HIGH: number;
12
+ }
13
+
14
+ export interface BudgetConfig {
15
+ startup?: TieredBudget | number;
16
+ screens?: Record<string, TieredBudget | number>;
17
+ navigation?: Record<string, TieredBudget | number>;
18
+ minFps?: TieredBudget | number;
19
+ droppedFramesPct?: TieredBudget | number;
20
+ maxCommitDuration?: TieredBudget | number;
21
+ }
22
+
23
+ export interface BudgetViolation {
24
+ type: 'startup' | 'screen' | 'navigation' | 'fps' | 'dropped-frames' | 'commit';
25
+ budget: number;
26
+ actual: number;
27
+ tier: DeviceTier;
28
+ route?: string;
29
+ message: string;
30
+ t: number;
31
+ }
32
+
33
+ export function resolveBudget(
34
+ budget: TieredBudget | number | undefined,
35
+ tier: DeviceTier
36
+ ): number | undefined {
37
+ if (budget === undefined) return undefined;
38
+ if (typeof budget === 'number') return budget;
39
+ return budget[tier];
40
+ }
41
+
42
+ export class BudgetEngine {
43
+ private config: BudgetConfig;
44
+ private tier: DeviceTier;
45
+ private violations: BudgetViolation[] = [];
46
+ private onViolation?: (v: BudgetViolation) => void;
47
+
48
+ constructor(
49
+ config: BudgetConfig,
50
+ tier: DeviceTier,
51
+ onViolation?: (v: BudgetViolation) => void
52
+ ) {
53
+ this.config = config;
54
+ this.tier = tier;
55
+ this.onViolation = onViolation;
56
+ }
57
+
58
+ check(
59
+ type: BudgetViolation['type'],
60
+ actual: number,
61
+ budgetKey?: string,
62
+ t?: number
63
+ ): BudgetViolation | null {
64
+ let budget: number | undefined;
65
+ switch (type) {
66
+ case 'startup':
67
+ budget = resolveBudget(this.config.startup, this.tier);
68
+ break;
69
+ case 'screen':
70
+ budget = budgetKey ? resolveBudget(this.config.screens?.[budgetKey], this.tier) : undefined;
71
+ break;
72
+ case 'navigation':
73
+ budget = budgetKey ? resolveBudget(this.config.navigation?.[budgetKey], this.tier) : undefined;
74
+ break;
75
+ case 'fps':
76
+ budget = resolveBudget(this.config.minFps, this.tier);
77
+ if (budget !== undefined && actual >= budget) return null;
78
+ break;
79
+ case 'dropped-frames':
80
+ budget = resolveBudget(this.config.droppedFramesPct, this.tier);
81
+ break;
82
+ case 'commit':
83
+ budget = resolveBudget(this.config.maxCommitDuration, this.tier);
84
+ break;
85
+ }
86
+ if (budget === undefined) return null;
87
+ if (type !== 'fps' && actual <= budget) return null;
88
+
89
+ const violation: BudgetViolation = {
90
+ type,
91
+ budget,
92
+ actual,
93
+ tier: this.tier,
94
+ route: budgetKey,
95
+ message: `[${type}]${budgetKey ? ` ${budgetKey}` : ''} ${actual.toFixed(0)}ms > budget ${budget}ms (tier: ${this.tier})`,
96
+ t: t ?? Date.now(),
97
+ };
98
+ this.violations.push(violation);
99
+ this.onViolation?.(violation);
100
+ return violation;
101
+ }
102
+
103
+ getViolations(): BudgetViolation[] {
104
+ return [...this.violations];
105
+ }
106
+
107
+ clearViolations(): void {
108
+ this.violations = [];
109
+ }
110
+
111
+ updateTier(tier: DeviceTier): void {
112
+ this.tier = tier;
113
+ }
114
+ }
package/src/clock.ts ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Clock synchronization between JS (performance.now) and native clocks.
3
+ *
4
+ * Strategy:
5
+ * js1 -> nativeNow() -> js2
6
+ * offset = native - (js1 + js2) / 2
7
+ */
8
+
9
+ export interface NativeNowFn {
10
+ (): number;
11
+ }
12
+
13
+ export interface ClockSync {
14
+ offset: number;
15
+ errorMargin: number;
16
+ sampledAt: number;
17
+ }
18
+
19
+ export class PerfClock {
20
+ private syncState: ClockSync | null = null;
21
+ private syncInterval: ReturnType<typeof setInterval> | null = null;
22
+ private nativeNow: NativeNowFn | null = null;
23
+
24
+ install(nativeNow: NativeNowFn, resyncIntervalMs = 30_000): void {
25
+ this.nativeNow = nativeNow;
26
+ this.sync();
27
+ this.syncInterval = setInterval(() => this.sync(), resyncIntervalMs);
28
+ }
29
+
30
+ uninstall(): void {
31
+ if (this.syncInterval) {
32
+ clearInterval(this.syncInterval);
33
+ this.syncInterval = null;
34
+ }
35
+ this.nativeNow = null;
36
+ this.syncState = null;
37
+ }
38
+
39
+ sync(): void {
40
+ if (!this.nativeNow) return;
41
+ const js1 = this.jsNow();
42
+ const native = this.nativeNow();
43
+ const js2 = this.jsNow();
44
+ const jsMid = (js1 + js2) / 2;
45
+ this.syncState = {
46
+ offset: native - jsMid,
47
+ errorMargin: (js2 - js1) / 2,
48
+ sampledAt: js2,
49
+ };
50
+ }
51
+
52
+ jsNow(): number {
53
+ return typeof performance !== 'undefined' ? performance.now() : Date.now();
54
+ }
55
+
56
+ nativeToJs(nativeMs: number): number {
57
+ if (!this.syncState) return nativeMs;
58
+ return nativeMs - this.syncState.offset;
59
+ }
60
+
61
+ get syncInfo(): ClockSync | null {
62
+ return this.syncState;
63
+ }
64
+ }
65
+
66
+ export const perfClock = new PerfClock();
package/src/events.ts ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Core event model for rn-perf-kit.
3
+ * All performance signals are expressed as PerfEvent union types.
4
+ */
5
+
6
+ export type NavPhase =
7
+ | 'tap'
8
+ | 'dispatch'
9
+ | 'first-commit'
10
+ | 'transition-start'
11
+ | 'transition-end'
12
+ | 'content-ready'
13
+ | 'interactive';
14
+
15
+ export interface FrameBreakdown {
16
+ input: number;
17
+ animation: number;
18
+ layoutMeasure: number;
19
+ draw: number;
20
+ sync: number;
21
+ gpu: number;
22
+ }
23
+
24
+ export interface RenderedFiber {
25
+ name: string;
26
+ cause: RenderCause;
27
+ actualDuration: number;
28
+ wasted: boolean;
29
+ }
30
+
31
+ export type RenderCause =
32
+ | 'parent-rerender'
33
+ | 'unstable-reference'
34
+ | 'state-change'
35
+ | 'context-change'
36
+ | 'store-subscription'
37
+ | 'prop-change'
38
+ | 'unknown';
39
+
40
+ export type StoreSource = 'redux' | 'zustand' | 'query' | 'context' | 'custom';
41
+
42
+ export type PerfEvent =
43
+ | {
44
+ type: 'frame';
45
+ t: number;
46
+ dur: number;
47
+ janky: boolean;
48
+ breakdown?: FrameBreakdown;
49
+ }
50
+ | {
51
+ type: 'commit';
52
+ t: number;
53
+ dur: number;
54
+ lane?: string;
55
+ fibers: RenderedFiber[];
56
+ phase?: 'mount' | 'update' | 'nested-update';
57
+ }
58
+ | {
59
+ type: 'render-discarded';
60
+ t: number;
61
+ component: string;
62
+ renderCount: number;
63
+ }
64
+ | {
65
+ type: 'nav';
66
+ t: number;
67
+ phase: NavPhase;
68
+ route: string;
69
+ fromRoute?: string;
70
+ navId: string;
71
+ }
72
+ | {
73
+ type: 'store';
74
+ t: number;
75
+ source: StoreSource;
76
+ key: string;
77
+ storeName?: string;
78
+ }
79
+ | {
80
+ type: 'net';
81
+ t: number;
82
+ dur: number;
83
+ url: string;
84
+ bytes: number;
85
+ status?: number;
86
+ }
87
+ | { type: 'stall'; t: number; dur: number }
88
+ | { type: 'gc'; t: number; dur: number }
89
+ | {
90
+ type: 'thermal';
91
+ t: number;
92
+ status: 'none' | 'light' | 'moderate' | 'severe' | 'critical' | 'emergency' | 'shutdown';
93
+ }
94
+ | {
95
+ type: 'memory';
96
+ t: number;
97
+ usedMb: number;
98
+ availableMb: number;
99
+ trimLevel?: number;
100
+ }
101
+ | { type: 'mark'; t: number; name: string; data?: unknown };
102
+
103
+ export type PerfEventType = PerfEvent['type'];
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './events';
2
+ export * from './ring-buffer';
3
+ export * from './clock';
4
+ export * from './timeline';
5
+ export * from './budgets';
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Fixed-capacity ring buffer for PerfEvents.
3
+ * When full, oldest events are overwritten (FIFO eviction).
4
+ */
5
+
6
+ import type { PerfEvent } from './events';
7
+
8
+ export interface RingBufferOptions {
9
+ capacity?: number;
10
+ windowMs?: number;
11
+ }
12
+
13
+ export class RingBuffer {
14
+ private readonly capacity: number;
15
+ private readonly windowMs: number;
16
+ private readonly buffer: Array<PerfEvent | undefined>;
17
+ private head = 0;
18
+ private count = 0;
19
+
20
+ constructor(options: RingBufferOptions = {}) {
21
+ this.capacity = options.capacity ?? 10_000;
22
+ this.windowMs = options.windowMs ?? 60_000;
23
+ this.buffer = new Array(this.capacity);
24
+ }
25
+
26
+ push(event: PerfEvent): void {
27
+ this.buffer[this.head] = event;
28
+ this.head = (this.head + 1) % this.capacity;
29
+ if (this.count < this.capacity) this.count++;
30
+ }
31
+
32
+ query(fromT?: number, toT?: number): PerfEvent[] {
33
+ const results: PerfEvent[] = [];
34
+ const start = this.count < this.capacity ? 0 : this.head;
35
+ for (let i = 0; i < this.count; i++) {
36
+ const idx = (start + i) % this.capacity;
37
+ const ev = this.buffer[idx];
38
+ if (!ev) continue;
39
+ if (fromT !== undefined && ev.t < fromT) continue;
40
+ if (toT !== undefined && ev.t > toT) continue;
41
+ results.push(ev);
42
+ }
43
+ return results;
44
+ }
45
+
46
+ recent(now: number): PerfEvent[] {
47
+ return this.query(now - this.windowMs, now);
48
+ }
49
+
50
+ clear(): void {
51
+ this.head = 0;
52
+ this.count = 0;
53
+ this.buffer.fill(undefined);
54
+ }
55
+
56
+ get size(): number {
57
+ return this.count;
58
+ }
59
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Global timeline singleton.
3
+ * All collectors write here; all analyzers read from here.
4
+ */
5
+
6
+ import type { PerfEvent, PerfEventType } from './events';
7
+ import { RingBuffer, type RingBufferOptions } from './ring-buffer';
8
+ import { perfClock } from './clock';
9
+
10
+ type EventListener = (event: PerfEvent) => void;
11
+
12
+ export interface TimelineOptions extends RingBufferOptions {
13
+ enabled?: boolean;
14
+ }
15
+
16
+ class Timeline {
17
+ private buffer: RingBuffer;
18
+ private listeners = new Map<PerfEventType | '*', Set<EventListener>>();
19
+ private _enabled = true;
20
+
21
+ constructor(options: TimelineOptions = {}) {
22
+ this.buffer = new RingBuffer(options);
23
+ this._enabled = options.enabled ?? true;
24
+ }
25
+
26
+ get enabled(): boolean {
27
+ return this._enabled;
28
+ }
29
+
30
+ set enabled(value: boolean) {
31
+ this._enabled = value;
32
+ }
33
+
34
+ now(): number {
35
+ return perfClock.jsNow();
36
+ }
37
+
38
+ add(event: PerfEvent): void {
39
+ if (!this._enabled) return;
40
+ this.buffer.push(event);
41
+ this.emit(event);
42
+ }
43
+
44
+ mark(name: string, data?: unknown): void {
45
+ this.add({ type: 'mark', t: this.now(), name, data });
46
+ }
47
+
48
+ query(fromT?: number, toT?: number): PerfEvent[] {
49
+ return this.buffer.query(fromT, toT);
50
+ }
51
+
52
+ recent(windowMs?: number): PerfEvent[] {
53
+ const now = this.now();
54
+ return this.buffer.query(now - (windowMs ?? 60_000), now);
55
+ }
56
+
57
+ on(eventType: PerfEventType | '*', listener: EventListener): () => void {
58
+ if (!this.listeners.has(eventType)) {
59
+ this.listeners.set(eventType, new Set());
60
+ }
61
+ this.listeners.get(eventType)!.add(listener);
62
+ return () => this.off(eventType, listener);
63
+ }
64
+
65
+ off(eventType: PerfEventType | '*', listener: EventListener): void {
66
+ this.listeners.get(eventType)?.delete(listener);
67
+ }
68
+
69
+ private emit(event: PerfEvent): void {
70
+ this.listeners.get(event.type)?.forEach((fn) => fn(event));
71
+ this.listeners.get('*')?.forEach((fn) => fn(event));
72
+ }
73
+
74
+ clear(): void {
75
+ this.buffer.clear();
76
+ }
77
+
78
+ get size(): number {
79
+ return this.buffer.size;
80
+ }
81
+ }
82
+
83
+ export const timeline = new Timeline();
84
+ export type { Timeline };
package/test-runner.js ADDED
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Self-contained unit test runner for @rn-perf-kit/core logic.
3
+ * Runs in pure Node.js without requiring external test dependencies.
4
+ */
5
+
6
+ const assert = require('assert');
7
+
8
+ // ── RingBuffer implementation under test ────────────────────────────────────
9
+ class RingBuffer {
10
+ constructor(options = {}) {
11
+ this.capacity = options.capacity ?? 10000;
12
+ this.windowMs = options.windowMs ?? 60000;
13
+ this.buffer = new Array(this.capacity);
14
+ this.head = 0;
15
+ this.count = 0;
16
+ }
17
+
18
+ push(event) {
19
+ this.buffer[this.head] = event;
20
+ this.head = (this.head + 1) % this.capacity;
21
+ if (this.count < this.capacity) this.count++;
22
+ }
23
+
24
+ query(fromT, toT) {
25
+ const results = [];
26
+ const start = this.count < this.capacity ? 0 : this.head;
27
+ for (let i = 0; i < this.count; i++) {
28
+ const idx = (start + i) % this.capacity;
29
+ const ev = this.buffer[idx];
30
+ if (!ev) continue;
31
+ if (fromT !== undefined && ev.t < fromT) continue;
32
+ if (toT !== undefined && ev.t > toT) continue;
33
+ results.push(ev);
34
+ }
35
+ return results;
36
+ }
37
+
38
+ recent(now) {
39
+ return this.query(now - this.windowMs, now);
40
+ }
41
+
42
+ clear() {
43
+ this.head = 0;
44
+ this.count = 0;
45
+ this.buffer.fill(undefined);
46
+ }
47
+
48
+ get size() {
49
+ return this.count;
50
+ }
51
+ }
52
+
53
+ // ── Clock sync math under test ──────────────────────────────────────────────
54
+ class PerfClock {
55
+ constructor() {
56
+ this.syncState = null;
57
+ this.nativeNow = null;
58
+ }
59
+
60
+ syncWith(js1, native, js2) {
61
+ const jsMid = (js1 + js2) / 2;
62
+ this.syncState = {
63
+ offset: native - jsMid,
64
+ errorMargin: (js2 - js1) / 2,
65
+ };
66
+ }
67
+
68
+ nativeToJs(nativeMs) {
69
+ if (!this.syncState) return nativeMs;
70
+ return nativeMs - this.syncState.offset;
71
+ }
72
+ }
73
+
74
+ // ── Budget engine under test ────────────────────────────────────────────────
75
+ class BudgetEngine {
76
+ constructor(config, tier) {
77
+ this.config = config;
78
+ this.tier = tier;
79
+ this.violations = [];
80
+ }
81
+
82
+ check(type, actual, budgetKey) {
83
+ let budget = this.config[type];
84
+ if (typeof budget === 'object' && budget !== null) {
85
+ budget = budget[this.tier];
86
+ }
87
+ if (budget === undefined) return null;
88
+ if (type !== 'fps' && actual <= budget) return null;
89
+ if (type === 'fps' && actual >= budget) return null;
90
+
91
+ const violation = { type, budget, actual, tier: this.tier, route: budgetKey };
92
+ this.violations.push(violation);
93
+ return violation;
94
+ }
95
+ }
96
+
97
+ // ── Test Runner ─────────────────────────────────────────────────────────────
98
+ let passed = 0;
99
+ let failed = 0;
100
+
101
+ function test(name, fn) {
102
+ try {
103
+ fn();
104
+ console.log(` ✓ ${name}`);
105
+ passed++;
106
+ } catch (err) {
107
+ console.error(` ✗ ${name}`);
108
+ console.error(` ${err.message}`);
109
+ failed++;
110
+ }
111
+ }
112
+
113
+ console.log('\nRunning @rn-perf-kit/core Unit Tests:');
114
+
115
+ test('RingBuffer stores and queries events in chronological order', () => {
116
+ const buf = new RingBuffer({ capacity: 5 });
117
+ buf.push({ type: 'stall', t: 100, dur: 10 });
118
+ buf.push({ type: 'stall', t: 200, dur: 20 });
119
+ buf.push({ type: 'stall', t: 300, dur: 30 });
120
+ const events = buf.query();
121
+ assert.strictEqual(events.length, 3);
122
+ assert.strictEqual(events[0].t, 100);
123
+ assert.strictEqual(events[2].t, 300);
124
+ });
125
+
126
+ test('RingBuffer FIFO eviction when exceeding capacity', () => {
127
+ const buf = new RingBuffer({ capacity: 3 });
128
+ buf.push({ type: 'stall', t: 1 });
129
+ buf.push({ type: 'stall', t: 2 });
130
+ buf.push({ type: 'stall', t: 3 });
131
+ buf.push({ type: 'stall', t: 4 }); // should evict t=1
132
+ const events = buf.query();
133
+ assert.strictEqual(events.length, 3);
134
+ assert.deepStrictEqual(events.map(e => e.t), [2, 3, 4]);
135
+ });
136
+
137
+ test('RingBuffer range filtering', () => {
138
+ const buf = new RingBuffer({ capacity: 10 });
139
+ for (let i = 0; i < 10; i++) buf.push({ type: 'stall', t: i * 100 });
140
+ const slice = buf.query(200, 500);
141
+ assert.deepStrictEqual(slice.map(e => e.t), [200, 300, 400, 500]);
142
+ });
143
+
144
+ test('PerfClock calculates offset and synchronizes native timestamps to JS timeline', () => {
145
+ const clock = new PerfClock();
146
+ // Simulated sync: js1=100, native=200, js2=102 -> jsMid=101 -> offset = 200 - 101 = 99
147
+ clock.syncWith(100, 200, 102);
148
+ const nativeTs = 300;
149
+ // nativeToJs = 300 - 99 = 201
150
+ const jsTs = clock.nativeToJs(nativeTs);
151
+ assert.strictEqual(Math.round(jsTs), 201);
152
+ });
153
+
154
+ test('BudgetEngine detects violations according to device tier', () => {
155
+ const config = {
156
+ navigation: { LOW: 600, MID: 350, HIGH: 250 },
157
+ fps: { LOW: 45, MID: 55, HIGH: 58 },
158
+ };
159
+
160
+ const lowEngine = new BudgetEngine(config, 'LOW');
161
+ // actual 500ms <= 600ms budget for LOW -> no violation
162
+ assert.strictEqual(lowEngine.check('navigation', 500, 'Home->Detail'), null);
163
+
164
+ const highEngine = new BudgetEngine(config, 'HIGH');
165
+ // actual 300ms > 250ms budget for HIGH -> violation!
166
+ const violation = highEngine.check('navigation', 300, 'Home->Detail');
167
+ assert.notStrictEqual(violation, null);
168
+ assert.strictEqual(violation.budget, 250);
169
+ assert.strictEqual(violation.actual, 300);
170
+ });
171
+
172
+ console.log(`\nResults: ${passed} passed, ${failed} failed.\n`);
173
+ process.exit(failed > 0 ? 1 : 0);
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["**/*.test.ts", "**/*.spec.ts"]
4
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src"]
8
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.