Skip to content

Commit 9654ac5

Browse files
authored
fix(test-timer): test timer doesn't stop right after a test ends (@Leonabcd123) (monkeytypegame#7230)
### Description In the current implementation, the time difference between `now` and when we call `TestTimer.clear()` is high enough, so that if the test duration is really close to a whole number (say `3.96`), then `TestTimer` will continue to run up until the whole number, and will push another wpm entry to `wpmHistory` and another raw entry to `rawHistory`, causing the result chart to be messed up. This implementation clears `TestTimer` right after calculating `now` to hopefully allow for a smaller time difference between `now` and `TestTimer`. Also fixed some typos in comments.
1 parent 7660561 commit 9654ac5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

frontend/src/ts/controllers/chart-controller.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,24 @@ class ChartWithUpdateColors<
8585
}
8686

8787
async updateColors(): Promise<void> {
88-
//@ts-expect-error its too difficult to figure out these types, but this works
88+
//@ts-expect-error it's too difficult to figure out these types, but this works
8989
await updateColors(this);
9090
}
9191

9292
getDataset(id: DatasetIds): ChartDataset<TType, TData> {
93-
//@ts-expect-error its too difficult to figure out these types, but this works
93+
//@ts-expect-error it's too difficult to figure out these types, but this works
9494
return this.data.datasets?.find((x) => x.yAxisID === id);
9595
}
9696

9797
getScaleIds(): DatasetIds[] {
98-
//@ts-expect-error its too difficult to figure out these types, but this works
98+
//@ts-expect-error it's too difficult to figure out these types, but this works
9999
return typedKeys(this.options?.scales ?? {}) as DatasetIds[];
100100
}
101101

102102
getScale(
103103
id: DatasetIds extends never ? never : "x" | DatasetIds,
104104
): DatasetIds extends never ? never : CartesianScaleOptions {
105-
//@ts-expect-error its too difficult to figure out these types, but this works
105+
//@ts-expect-error it's too difficult to figure out these types, but this works
106106
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access
107107
return this.options.scales[id];
108108
}
@@ -120,7 +120,7 @@ export const result = new ChartWithUpdateColors<
120120
labels: [],
121121
datasets: [
122122
{
123-
//@ts-expect-error the type is defined incorrectly, have to ingore the error
123+
//@ts-expect-error the type is defined incorrectly, have to ignore the error
124124
clip: false,
125125
label: "wpm",
126126
data: [],
@@ -131,7 +131,7 @@ export const result = new ChartWithUpdateColors<
131131
pointRadius: 1,
132132
},
133133
{
134-
//@ts-expect-error the type is defined incorrectly, have to ingore the error
134+
//@ts-expect-error the type is defined incorrectly, have to ignore the error
135135
clip: false,
136136
label: "raw",
137137
data: [],
@@ -143,7 +143,7 @@ export const result = new ChartWithUpdateColors<
143143
pointRadius: 0,
144144
},
145145
{
146-
//@ts-expect-error the type is defined incorrectly, have to ingore the error
146+
//@ts-expect-error the type is defined incorrectly, have to ignore the error
147147
clip: false,
148148
label: "errors",
149149
data: [],
@@ -166,7 +166,7 @@ export const result = new ChartWithUpdateColors<
166166
},
167167
},
168168
{
169-
//@ts-expect-error the type is defined incorrectly, have to ingore the error
169+
//@ts-expect-error the type is defined incorrectly, have to ignore the error
170170
clip: false,
171171
label: "burst",
172172
data: [],
@@ -1268,7 +1268,7 @@ async function updateColors<
12681268
return;
12691269
}
12701270

1271-
//@ts-expect-error its too difficult to figure out these types, but this works
1271+
//@ts-expect-error it's too difficult to figure out these types, but this works
12721272
chart.data.datasets[0].borderColor = (ctx): string => {
12731273
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
12741274
const isPb = ctx.raw?.isPb as boolean;

frontend/src/ts/test/test-logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
930930
if (!TestState.isActive) return;
931931
TestUI.setResultCalculating(true);
932932
const now = performance.now();
933+
TestTimer.clear();
933934
TestStats.setEnd(now);
934935

935936
// fade out the test and show loading
@@ -977,7 +978,6 @@ export async function finish(difficultyFailed = false): Promise<void> {
977978
LiveBurst.hide();
978979
TimerProgress.hide();
979980
OutOfFocus.hide();
980-
TestTimer.clear();
981981
Monkey.hide();
982982
void ModesNotice.update();
983983

0 commit comments

Comments
 (0)