Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: ConfigManagerのマイグレーション時にスナップショットテストを追加 #2357

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/backend/common/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ export abstract class BaseConfigManager {
this._save();
}

/** 全ての設定を取得する。テスト用。 */
public getAll(): ConfigType {
if (!this.config) throw new Error("Config is not initialized");
return this.config;
}

private _save() {
void this.lock.acquire(lockKey, async () => {
await this.save({
Expand Down
239 changes: 239 additions & 0 deletions tests/unit/backend/common/__snapshots__/configManager.spec.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion tests/unit/backend/common/configManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pastConfigs from "./pastConfigs";
import configBugDefaultPreset1996 from "./pastConfigs/0.19.1-bug_default_preset.json";
import { BaseConfigManager } from "@/backend/common/ConfigManager";
import { configSchema } from "@/type/preload";
import { configSchema, isMac } from "@/type/preload";

const configBase = {
...configSchema.parse({}),
Expand Down Expand Up @@ -85,6 +85,13 @@ for (const [version, data] of pastConfigs) {
const configManager = new TestConfigManager();
await configManager.initialize();
expect(configManager).toBeTruthy();

// マイグレーション後のデータが正しいことをスナップショットで確認
// NOTE: Macはショートカットキーが異なるためパス
// TODO: ConfigManagerにOSを引数指定できるようにしてテストを分ける
if (!isMac) {
expect(configManager.getAll()).toMatchSnapshot();
}
});
}

Expand Down
Loading