Skip to content

Commit

Permalink
Add: ConfigManagerのマイグレーション時にスナップショットテストを追加 (VOICEVOX#2357)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Dec 21, 2024
1 parent 586ac69 commit b91830e
Show file tree
Hide file tree
Showing 3 changed files with 270 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/backend/common/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,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
256 changes: 256 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.

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

Expand Down Expand Up @@ -85,6 +86,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

0 comments on commit b91830e

Please sign in to comment.