Skip to content

Commit

Permalink
mockSandbox足した
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Nov 4, 2024
1 parent d0febc3 commit a70082d
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
94 changes: 94 additions & 0 deletions tests/unit/store/__snapshots__/audio.browser.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`GENERATE_AUDIO_ITEM > テキストを指定するとtextに値が入る 1`] = `
{
"presetKey": undefined,
"query": {
"accentPhrases": [
{
"accent": 5,
"moras": [
{
"consonant": "k",
"consonantLength": 0.0220625,
"pitch": 4.7734375,
"text": "",
"vowel": "o",
"vowelLength": 0.1140625,
},
{
"consonant": undefined,
"consonantLength": undefined,
"pitch": 3.609375,
"text": "",
"vowel": "N",
"vowelLength": 0.08312499999999999,
},
{
"consonant": "n",
"consonantLength": 0.022625,
"pitch": 4.75,
"text": "",
"vowel": "i",
"vowelLength": 0.10843749999999999,
},
{
"consonant": "ch",
"consonantLength": 0.0400625,
"pitch": 4.0234375,
"text": "",
"vowel": "i",
"vowelLength": 0.10843749999999999,
},
{
"consonant": "h",
"consonantLength": 0.0315,
"pitch": 4.796875,
"text": "",
"vowel": "a",
"vowelLength": 0.1509375,
},
],
"pauseMora": undefined,
},
],
"intonationScale": 1,
"outputSamplingRate": 24000,
"outputStereo": false,
"pitchScale": 0,
"postPhonemeLength": 0.1,
"prePhonemeLength": 0.1,
"speedScale": 1,
"volumeScale": 1,
},
"text": "こんにちは",
"voice": {
"engineId": "c7b58856-bd56-4aa1-afb7-b8415f824b06",
"speakerId": "7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff",
"styleId": 0,
},
}
`;

exports[`GENERATE_AUDIO_ITEM > 何も指定しない場合は空のAudioItemを作る 1`] = `
{
"presetKey": undefined,
"query": {
"accentPhrases": [],
"intonationScale": 1,
"outputSamplingRate": 24000,
"outputStereo": false,
"pitchScale": 0,
"postPhonemeLength": 0.1,
"prePhonemeLength": 0.1,
"speedScale": 1,
"volumeScale": 1,
},
"text": "",
"voice": {
"engineId": "c7b58856-bd56-4aa1-afb7-b8415f824b06",
"speakerId": "7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff",
"styleId": 0,
},
}
`;
3 changes: 2 additions & 1 deletion tests/unit/store/audio.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initializeStateAsSoftwareStarted } from "./utils";
import { initializeStateAsSoftwareStarted, mockSandbox } from "./utils";

import { createStoreWrapper } from "@/store";
import { resetMockMode } from "@/helpers/random";
Expand All @@ -15,6 +15,7 @@ beforeEach(() => {
store.replaceState(initialState);

resetMockMode();
mockSandbox();
});

describe("GENERATE_AUDIO_ITEM", () => {
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/store/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ import {
getCharacterInfoMock,
getCharactersMock,
} from "@/mock/engineMock/characterResourceMock";
import { SandboxKey, Sandbox } from "@/type/preload";

/** バックエンド向けAPIにmockを差し込む */
export function mockSandbox() {
const sandbox = {
logError(...params: unknown[]) {
console.error(...params);
},
logWarn(...params: unknown[]) {
console.warn(...params);
},
logInfo(...params: unknown[]) {
console.info(...params);
},
} satisfies Partial<Sandbox>;
// @ts-expect-error readonlyになっているがmockのため問題ない
window[SandboxKey] = sandbox;
}

/** ソフトウェアが正しく起動した場合のようにVuex.stateを初期化する */
export function initializeStateAsSoftwareStarted(
Expand Down

0 comments on commit a70082d

Please sign in to comment.