MCPcopy
hub / github.com/monkeytypegame/monkeytype / logTestEvent

Function logTestEvent

frontend/src/ts/test/events/data.ts:78–198  ·  view source on GitHub ↗
(
  type: TestEventType,
  now: number,
  eventData: TestEventData,
)

Source from the content-addressed store, hash-verified

76> = new Map();
77
78export function logTestEvent(
79 type: TestEventType,
80 now: number,
81 eventData: TestEventData,
82): void {
83 invalidateCache();
84
85 now = roundTo2(now);
86
87 if (!isSafeNumber(now)) {
88 throw new Error(`Invalid timestamp: ${now}`);
89 }
90
91 //strip undefined values from eventData
92 eventData = Object.fromEntries(
93 Object.entries(eventData).filter(([_, v]) => v !== undefined),
94 ) as TestEventData;
95
96 if (type === "keydown") {
97 const data = eventData as KeydownEventData;
98 const code = data.code as Keycode | "NoCode";
99
100 if (!keysToTrack.has(code)) {
101 return;
102 }
103
104 if (pressedKeys.has(code)) {
105 pressedKeys.delete(code);
106 keyupEvents.push({
107 type: "keyup",
108 ms: now,
109 testMs: 0,
110 data: { ...data, code },
111 });
112 }
113
114 if (resultCalculating) {
115 return;
116 }
117
118 let key: Keycode | "NoCode" | `NoCode${number}` = code;
119 if (key === "NoCode") {
120 key = `NoCode${noCodeIndex}`;
121 noCodeIndex++;
122 }
123
124 pressedKeys.set(key, {
125 timestamp: now,
126 });
127
128 keydownEvents.push({
129 type,
130 ms: now,
131 testMs: 0,
132 data: { ...data, code: key },
133 });
134 } else if (type === "keyup") {
135 const data = eventData as KeyupEventData;

Callers 13

test-timer.tsFile · 0.90
clearFunction · 0.90
_startNewFunction · 0.90
_startOldFunction · 0.90
onInsertTextFunction · 0.90
onDeleteFunction · 0.90
onKeyupFunction · 0.90
onKeydownFunction · 0.90
composition.tsFile · 0.90
data.spec.tsFile · 0.90
setupBasicTestFunction · 0.90
stats.spec.tsFile · 0.90

Calls 6

roundTo2Function · 0.90
isSafeNumberFunction · 0.90
recordEventForCacheFunction · 0.90
invalidateCacheFunction · 0.85
pushMethod · 0.80
setMethod · 0.80

Tested by 1

setupBasicTestFunction · 0.72