Skip to content

Commit f3f0e9e

Browse files
authored
refactor: config split (@Miodec) (monkeytypegame#7659)
### Description <!-- Please describe the change(s) made in your PR --> ### Checks - [ ] Adding quotes? - [ ] Make sure to include translations for the quotes in the description (or another comment) so we can verify their content. - [ ] Adding a language? - Make sure to follow the [languages documentation](https://github.com/monkeytypegame/monkeytype/blob/master/docs/LANGUAGES.md) - [ ] Add language to `packages/schemas/src/languages.ts` - [ ] Add language to exactly one group in `frontend/src/ts/constants/languages.ts` - [ ] Add language json file to `frontend/static/languages` - [ ] Adding a theme? - Make sure to follow the [themes documentation](https://github.com/monkeytypegame/monkeytype/blob/master/docs/THEMES.md) - [ ] Add theme to `packages/schemas/src/themes.ts` - [ ] Add theme to `frontend/src/ts/constants/themes.ts` - [ ] (optional) Add theme css file to `frontend/static/themes` - [ ] Add some screenshots of the theme, especially with different test settings (colorful, flip colors) to your pull request - [ ] Adding a layout? - [ ] Make sure to follow the [layouts documentation](https://github.com/monkeytypegame/monkeytype/blob/master/docs/LAYOUTS.md) - [ ] Add layout to `packages/schemas/src/layouts.ts` - [ ] Add layout json file to `frontend/static/layouts` - [ ] Adding a font? - Make sure to follow the [fonts documentation](https://github.com/monkeytypegame/monkeytype/blob/master/docs/FONTS.md) - [ ] Add font file to `frontend/static/webfonts` - [ ] Add font to `packages/schemas/src/fonts.ts` - [ ] Add font to `frontend/src/ts/constants/fonts.ts` - [ ] Check if any open issues are related to this PR; if so, be sure to tag them below. - [ ] Make sure the PR title follows the Conventional Commits standard. (https://www.conventionalcommits.org for more info) - [ ] Make sure to include your GitHub username prefixed with @ inside parentheses at the end of the PR title. <!-- label(optional scope): pull request title (@your_github_username) --> <!-- I know I know they seem boring but please do them, they help us and you will find out it also helps you.--> Closes # <!-- the issue(s) your PR resolves if any (delete if that is not the case) --> <!-- please also reference any issues and or PRs related to your pull request --> <!-- Also remove it if you are not following any issues. --> <!-- pro tip: you can mention an issue, PR, or discussion on GitHub by referencing its hash number e.g: [monkeytypegame#1234](monkeytypegame#1234) --> <!-- pro tip: you can press . (dot or period) in the code tab of any GitHub repo to get access to GitHub's VS Code web editor Enjoy! :) -->
1 parent e7a2cd9 commit f3f0e9e

119 files changed

Lines changed: 675 additions & 607 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/__tests__/commandline/util.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
//import type { ConfigMetadata } from "../../src/ts/config-metadata";
1+
//import type { ConfigMetadata } from "../../src/ts/config/metadata";
22

33
import { describe, it, expect, afterAll, vi } from "vitest";
44
import * as Util from "../../src/ts/commandline/util";
55

66
import type { CommandlineConfigMetadata } from "../../src/ts/commandline/commandline-metadata";
77
import type { ConfigKey } from "@monkeytype/schemas/configs";
8-
import type { ConfigMetadata } from "../../src/ts/config-metadata";
8+
import type { ConfigMetadata } from "../../src/ts/config/metadata";
99
import { z, ZodSchema } from "zod";
1010

1111
const buildCommandForConfigKey = Util.__testing._buildCommandForConfigKey;
1212

1313
describe("CommandlineUtils", () => {
14-
vi.mock("../../src/ts/config-metadata", () => ({ configMetadata: [] }));
14+
vi.mock("../../src/ts/config/metadata", () => ({ configMetadata: [] }));
1515
vi.mock("../../src/ts/commandline/commandline-metadata", () => ({
1616
commandlineConfigMetadata: [],
1717
}));

frontend/__tests__/controllers/preset-controller.spec.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { describe, it, expect, beforeEach, vi } from "vitest";
22
import * as PresetController from "../../src/ts/controllers/preset-controller";
33
import { Preset } from "@monkeytype/schemas/presets";
44
import * as DB from "../../src/ts/db";
5-
import * as UpdateConfig from "../../src/ts/config";
5+
import { setConfig } from "../../src/ts/config/setters";
6+
import { Config } from "../../src/ts/config/store";
7+
import * as Lifecycle from "../../src/ts/config/lifecycle";
8+
import * as ConfigUtils from "../../src/ts/config/utils";
9+
import * as Persistence from "../../src/ts/config/persistence";
610
import * as Notifications from "../../src/ts/states/notifications";
711
import * as TestLogic from "../../src/ts/test/test-logic";
812
import * as TagController from "../../src/ts/controllers/tag-controller";
@@ -16,13 +20,13 @@ describe("PresetController", () => {
1620
//
1721
}));
1822
const dbGetSnapshotMock = vi.spyOn(DB, "getSnapshot");
19-
const configApplyMock = vi.spyOn(UpdateConfig, "applyConfig");
23+
const configApplyMock = vi.spyOn(Lifecycle, "applyConfig");
2024
const configSaveFullConfigMock = vi.spyOn(
21-
UpdateConfig,
25+
Persistence,
2226
"saveFullConfigToLocalStorage",
2327
);
2428
const configGetConfigChangesMock = vi.spyOn(
25-
UpdateConfig,
29+
ConfigUtils,
2630
"getConfigChanges",
2731
);
2832
const notificationAddMock = vi.spyOn(
@@ -111,8 +115,8 @@ describe("PresetController", () => {
111115
settingGroups: ["test"],
112116
});
113117

114-
UpdateConfig.setConfig("numbers", true);
115-
const oldConfig = structuredClone(UpdateConfig.default);
118+
setConfig("numbers", true);
119+
const oldConfig = structuredClone(Config);
116120

117121
//WHEN
118122
await PresetController.apply(preset._id);

frontend/__tests__/controllers/url-handler.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect, beforeEach, vi } from "vitest";
22
import { Difficulty, Mode, Mode2 } from "@monkeytype/schemas/shared";
33
import { compressToURI } from "lz-ts";
4-
import * as UpdateConfig from "../../src/ts/config";
4+
import * as UpdateConfig from "../../src/ts/config/setters";
55
import * as Notifications from "../../src/ts/states/notifications";
66
import * as TestLogic from "../../src/ts/test/test-logic";
77
import * as TestState from "../../src/ts/test/test-state";

frontend/__tests__/input/helpers/fail-or-finish.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
checkIfFailedDueToDifficulty,
55
checkIfFinished,
66
} from "../../../src/ts/input/helpers/fail-or-finish";
7-
import { __testing } from "../../../src/ts/config";
7+
import { __testing } from "../../../src/ts/config/testing";
88
import * as Misc from "../../../src/ts/utils/misc";
99
import * as TestLogic from "../../../src/ts/test/test-logic";
1010
import * as Strings from "../../../src/ts/utils/strings";

frontend/__tests__/input/helpers/validation.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
isCharCorrect,
44
shouldInsertSpaceCharacter,
55
} from "../../../src/ts/input/helpers/validation";
6-
import { __testing } from "../../../src/ts/config";
6+
import { __testing } from "../../../src/ts/config/testing";
77
import * as FunboxList from "../../../src/ts/test/funbox/list";
88
import * as Strings from "../../../src/ts/utils/strings";
99

frontend/__tests__/root/config-metadata.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { describe, it, expect, afterAll, vi } from "vitest";
2-
import { configMetadata } from "../../src/ts/config-metadata";
3-
import * as Config from "../../src/ts/config";
2+
import { configMetadata } from "../../src/ts/config/metadata";
3+
import { __testing } from "../../src/ts/config/testing";
4+
import { setConfig } from "../../src/ts/config/setters";
45
import { ConfigKey, Config as ConfigType } from "@monkeytype/schemas/configs";
56

6-
const { replaceConfig, getConfig } = Config.__testing;
7+
const { replaceConfig, getConfig } = __testing;
78

89
type TestsByConfig<T> = Partial<{
910
[K in keyof ConfigType]: (T & { value: ConfigType[K] })[];
@@ -138,7 +139,7 @@ describe("ConfigMeta", () => {
138139
replaceConfig(given ?? {});
139140

140141
//WHEN
141-
Config.setConfig(key, value as any);
142+
setConfig(key, value as any);
142143

143144
//THEN
144145
expect(getConfig()).toMatchObject(expected);
@@ -175,7 +176,7 @@ describe("ConfigMeta", () => {
175176
replaceConfig(given ?? {});
176177

177178
//WHEN
178-
const applied = Config.setConfig(key, value as any);
179+
const applied = setConfig(key, value as any);
179180

180181
//THEN
181182
expect(applied).toEqual(!fail);
@@ -335,7 +336,7 @@ describe("ConfigMeta", () => {
335336
replaceConfig(given);
336337

337338
//WHEN
338-
Config.setConfig(key, value as any);
339+
setConfig(key, value as any);
339340

340341
//THEN
341342
expect(getConfig()).toMatchObject(expected ?? {});

frontend/__tests__/root/config.spec.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { describe, it, expect, beforeEach, afterAll, vi } from "vitest";
2-
import * as Config from "../../src/ts/config";
2+
import * as Config from "../../src/ts/config/setters";
3+
import * as Lifecycle from "../../src/ts/config/lifecycle";
4+
import * as ConfigUtils from "../../src/ts/config/utils";
5+
import { __testing } from "../../src/ts/config/testing";
36
import * as Misc from "../../src/ts/utils/misc";
47
import * as Env from "../../src/ts/utils/env";
58
import {
@@ -8,11 +11,11 @@ import {
811
CaretStyleSchema,
912
} from "@monkeytype/schemas/configs";
1013
import * as FunboxValidation from "../../src/ts/test/funbox/funbox-validation";
11-
import * as ConfigValidation from "../../src/ts/config-validation";
14+
import * as ConfigValidation from "../../src/ts/config/validation";
1215
import * as ConfigEvent from "../../src/ts/observables/config-event";
1316
import * as ApeConfig from "../../src/ts/ape/config";
1417
import * as Notifications from "../../src/ts/states/notifications";
15-
const { replaceConfig, getConfig } = Config.__testing;
18+
const { replaceConfig, getConfig } = __testing;
1619

1720
describe("Config", () => {
1821
const isDevEnvironmentMock = vi.spyOn(Env, "isDevEnvironment");
@@ -281,7 +284,7 @@ describe("Config", () => {
281284
replaceConfig({
282285
mode: "words",
283286
});
284-
await Config.applyConfig({
287+
await Lifecycle.applyConfig({
285288
numbers: true,
286289
punctuation: true,
287290
});
@@ -326,7 +329,7 @@ describe("Config", () => {
326329
];
327330

328331
it.each(testCases)("$display", async ({ value, expected }) => {
329-
await Config.applyConfig(value);
332+
await Lifecycle.applyConfig(value);
330333

331334
const config = getConfig();
332335
const applied = Object.fromEntries(
@@ -363,7 +366,7 @@ describe("Config", () => {
363366
];
364367

365368
it.each(testCases)("$display", async ({ value, expected }) => {
366-
await Config.applyConfig(value);
369+
await Lifecycle.applyConfig(value);
367370
const config = getConfig();
368371
const applied = Object.fromEntries(
369372
Object.entries(config).filter(([key]) =>
@@ -378,8 +381,8 @@ describe("Config", () => {
378381
replaceConfig({
379382
numbers: true,
380383
});
381-
await Config.applyConfig({
382-
...Config.getConfigChanges(),
384+
await Lifecycle.applyConfig({
385+
...ConfigUtils.getConfigChanges(),
383386
punctuation: true,
384387
});
385388
const config = getConfig();
@@ -390,7 +393,7 @@ describe("Config", () => {
390393
replaceConfig({
391394
minWpm: "off",
392395
});
393-
await Config.applyConfig({
396+
await Lifecycle.applyConfig({
394397
minWpmCustomSpeed: 100,
395398
});
396399
const config = getConfig();
@@ -402,7 +405,7 @@ describe("Config", () => {
402405
replaceConfig({
403406
minWpm: "off",
404407
});
405-
await Config.applyConfig({
408+
await Lifecycle.applyConfig({
406409
minWpm: "custom",
407410
minWpmCustomSpeed: 100,
408411
});
@@ -413,7 +416,7 @@ describe("Config", () => {
413416

414417
it("should keep the keymap off when applying keymapLayout", async () => {
415418
replaceConfig({});
416-
await Config.applyConfig({
419+
await Lifecycle.applyConfig({
417420
keymapLayout: "qwerty",
418421
});
419422
const config = getConfig();

frontend/__tests__/test/british-english.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect, beforeEach } from "vitest";
22
import { replace } from "../../src/ts/test/british-english";
3-
import Config from "../../src/ts/config";
3+
import { Config } from "../../src/ts/config/store";
44

55
describe("british-english", () => {
66
describe("replace", () => {

frontend/__tests__/utils/config.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from "vitest";
22
import { getDefaultConfig } from "../../src/ts/constants/default-config";
3-
import { migrateConfig } from "../../src/ts/utils/config";
3+
import { migrateConfig } from "../../src/ts/config/utils";
44
import { PartialConfig } from "@monkeytype/schemas/configs";
55

66
const defaultConfig = getDefaultConfig();

frontend/src/ts/auth.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
import Ape from "./ape";
1212
import { showRegisterCaptchaModal } from "./components/modals/RegisterCaptchaModal";
13-
import { updateFromServer as updateConfigFromServer } from "./config";
13+
import { updateFromServer as updateConfigFromServer } from "./config/remote";
1414
import * as DB from "./db";
1515
import {
1616
isAuthAvailable,

0 commit comments

Comments
 (0)