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

test: 音声書き出しe2eテスト #2473

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
529c58e
wip-音声書き出しe2eテスト
Hiroshiba Jan 4, 2025
6c559a6
filechooserは発火しないっぽい。仕様をファイル選択ではなくダウンロードに書き換えるのが良さそう?
Hiroshiba Jan 4, 2025
c16383f
Merge branch 'main' into wip-音声書き出しe2eテスト
Hiroshiba Jan 18, 2025
39f682f
?
Hiroshiba Jan 18, 2025
67411ce
fix: ブラウザ版でファイル保存できない問題を解決
Hiroshiba Jan 18, 2025
c660368
fix: fakePathの正規表現を修正
Hiroshiba Jan 18, 2025
53600c9
test: fakePathのテストケースを更新し、ファイル名の例を改善
Hiroshiba Jan 18, 2025
fa8f624
Merge branch 'hiho-20250118-232008' into wip-音声書き出しe2eテスト
Hiroshiba Jan 18, 2025
b4d35a6
feat: E2Eテスト用のファイル書き出しスパイを追加
Hiroshiba Jan 18, 2025
1a89577
[update snapshots]
Hiroshiba Jan 18, 2025
8cbebf8
fix: Node.jsのバージョンを22.11.0に更新し、デバッグ用のconsole.logを削除
Hiroshiba Jan 18, 2025
6ce4a26
[update snapshots]
Hiroshiba Jan 18, 2025
0d53426
(スナップショットを更新)
github-actions[bot] Jan 18, 2025
d0631c2
fix: バッファをUint8Arrayに変換する処理を修正
Hiroshiba Jan 18, 2025
727ce50
Merge branch 'main' into wip-音声書き出しe2eテスト
Hiroshiba Jan 18, 2025
03be644
fix: Windows以外のプラットフォームでのテストをスキップするように変更
Hiroshiba Jan 18, 2025
84295c5
feat: spyWriteFile関数にTODOコメントを追加
Hiroshiba Jan 18, 2025
19e05a6
[update snapshots]
Hiroshiba Jan 18, 2025
9ab5b02
(スナップショットを更新)
github-actions[bot] Jan 18, 2025
a78b3f6
Merge branch 'main' into wip-音声書き出しe2eテスト
Hiroshiba Jan 25, 2025
c48533f
feat: ファイル書き出しのモック関数を追加し、テストを更新
Hiroshiba Jan 25, 2025
3e0ef71
refactor: ヘルパーファイルをユーティリティファイルにリネーム
Hiroshiba Jan 25, 2025
97f2d44
refactor: mockShowExportFileDialogから未使用のoriginalプロパティを削除
Hiroshiba Jan 25, 2025
5587acb
feat: モック関数にコメントを追加し、可読性を向上
Hiroshiba Jan 25, 2025
664516c
Merge remote-tracking branch 'upstream/main' into wip-音声書き出しe2eテスト
Hiroshiba Feb 8, 2025
f0809d7
[update snapshots]
Hiroshiba Feb 8, 2025
b4e016a
(スナップショットを更新)
github-actions[bot] Feb 8, 2025
afc51d0
fix: 書き出しファイルバッファの関数名を修正
Hiroshiba Feb 8, 2025
c97e3e5
fix: READMEのコマンドオプションを修正し、スナップショット更新の引数を簡略化
Hiroshiba Feb 8, 2025
80b6d54
Merge branch 'main' into wip-音声書き出しe2eテスト
Hiroshiba Mar 1, 2025
6d2d43c
refactor: ファイル書き出しダイアログのモック関数名を変更
Hiroshiba Mar 1, 2025
007f179
refactor: 書き出しダイアログのモック関数名を変更
Hiroshiba Mar 1, 2025
e48405b
refactor: モック関数にTODOコメントを追加して戻せるようにする
Hiroshiba Mar 1, 2025
ba6f855
refactor: テストステップを追加して音声書き出しの処理を明確化
Hiroshiba Mar 1, 2025
370e2e9
Merge branch 'main' into wip-音声書き出しe2eテスト
Hiroshiba Mar 1, 2025
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
2 changes: 2 additions & 0 deletions src/mock/engineMock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export function createOpenAPIEngineMock(): DefaultApiInterface {
volumeScale: 1.0,
prePhonemeLength: 0.1,
postPhonemeLength: 0.1,
pauseLength: null,
pauseLengthScale: 1.0,
outputSamplingRate: getEngineManifestMock().defaultSamplingRate,
outputStereo: false,
};
Expand Down
3 changes: 2 additions & 1 deletion src/mock/engineMock/manifestMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function getEngineManifestMock() {
adjustPitchScale: true,
adjustIntonationScale: true,
adjustVolumeScale: true,
interrogativeUpspeak: false,
adjustPauseLength: true,
interrogativeUpspeak: true,
Comment on lines -29 to +30
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ポーズの長さを変えるのもテストしたかったのでモックを修正しました。

synthesisMorphing: false,
sing: true,
manageLibrary: false,
Expand Down
2 changes: 1 addition & 1 deletion src/mock/engineMock/talkModelMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export async function textToActtentPhrasesMock(text: string, styleId: number) {
const pauseMora = {
text: "、",
vowel: "pau",
vowelLength: 1 - 1 / (accentPhrases.length + 1),
vowelLength: 1 - 1 / (accentPhrases.length + 2),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今のaccentPhrasesの数がaccentPhrases.lengthに入っていて、最初は0なので1 - 1/1になって0(ポーズの長さが0)になってしまってたので、+2にしてみました。

pitch: 0,
};

Expand Down
81 changes: 81 additions & 0 deletions tests/e2e/browser/utility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Page } from "@playwright/test";
import { Brand } from "@/type/utility";
import { success } from "@/type/result";

type TestFileId = Brand<string, "TestFileId">;

/** ファイル書き出し選択ダイアログをモックにする */
// TODO: モックを戻せるようにする
export async function mockShowSaveFileDialog(page: Page): Promise<{
getFileIds: () => Promise<TestFileId[]>;
}> {
type _Window = Window & {
_mockShowSaveFileDialog: {
returnValues: TestFileId[];
};
};

// モックを差し込む
await page.evaluate(() => {
const _window = window as unknown as _Window;
_window._mockShowSaveFileDialog = {
returnValues: [],
};

_window.backend.showSaveFileDialog = async () => {
const id = `${Date.now()}` as TestFileId;
_window._mockShowSaveFileDialog.returnValues.push(id);
return id;
};
});

return {
getFileIds: async () => {
return page.evaluate(() => {
const _window = window as unknown as _Window;
return _window._mockShowSaveFileDialog.returnValues;
});
},
};
}

/** ファイル書き出しをモックにする */
// TODO: モックを戻せるようにする
export async function mockWriteFile(page: Page): Promise<{
getWrittenFileBuffers: () => Promise<Record<string | TestFileId, Buffer>>;
}> {
type _Window = Window & {
_mockWriteFile: Record<string | TestFileId, Uint8Array>;
};

// モックを差し込む
await page.evaluate(
({ sucecssResult }) => {
const _window = window as unknown as _Window;
_window._mockWriteFile = {};

_window.backend.writeFile = async ({ filePath, buffer }) => {
_window._mockWriteFile[filePath] = new Uint8Array(buffer);
return sucecssResult;
};
},
{ sucecssResult: success(undefined) },
);

return {
getWrittenFileBuffers: async () => {
const arrays = await page.evaluate(() => {
const _window = window as unknown as _Window;
return Object.fromEntries(
Object.entries(_window._mockWriteFile).map(([key, value]) => [
key,
Array.from(value),
]),
);
});
return Object.fromEntries(
Object.entries(arrays).map(([key, value]) => [key, Buffer.from(value)]),
);
},
};
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions tests/e2e/browser/音声書き出し.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { test, expect, Page } from "@playwright/test";
import { gotoHome, navigateToMain } from "../navigators";
import { getQuasarMenu } from "../locators";
import { mockShowSaveFileDialog, mockWriteFile } from "./utility";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window.backends関数のモックを作るにあたっていくつか妥協したポイントもあったのでコメント。
より良い解決策があれば試したいかも。

  • mockを戻せるように作ってない
    • 今モック化したのはダイアログ表示の部分と、ファイル書き出しの部分
    • ダイアログは表示した瞬間ハングするのと、ファイル書き出しもできないので、まあどちらも戻さなくても問題にならないかなと思い、とりあえずそのままにしています
    • 戻せるようにも作れそうだけど、汎用的に書くのは結構難しいかも(全部のモックを戻す関数を作るとかが難しそう)
  • 一般化していない
    • 他にモックを刺したかった時にさくっとモックをさせるように作れてない
    • 今のうちに共通化した方がいいかもだけど・・・良い方法がパッと思いつかなかったので一旦そのままにしています


test.beforeEach(gotoHome);

/** 選択音声を書き出し、その音声ファイルのバイナリをスナップショットテストする */
async function exportSelectedAudioAndSnapshot(page: Page, name: string) {
const { getFileIds } = await mockShowSaveFileDialog(page);
const { getWrittenFileBuffers } = await mockWriteFile(page);

await page.getByRole("button", { name: "ファイル" }).click();
await getQuasarMenu(page, "選択音声を書き出し").click();
await expect(page.getByText("音声を書き出しました")).toBeVisible();

const fileId = (await getFileIds())[0];
const buffer = (await getWrittenFileBuffers())[fileId];
expect(buffer).toMatchSnapshot(`${name}.wav`);
}

test.describe("音声書き出し", () => {
test.skip(process.platform !== "win32", "Windows以外のためスキップします");

test.beforeEach(async ({ page }) => {
await navigateToMain(page);

const audioCell = page.getByRole("textbox", { name: "1行目" });
const accentPhrase = page.locator(".accent-phrase");

await audioCell.click();
await audioCell.fill("こんにちは、テストです");
await audioCell.press("Enter");
await expect(accentPhrase).not.toHaveCount(0);
});

test("各パラメータを変更して音声書き出し", async ({ page }) => {
await exportSelectedAudioAndSnapshot(page, "デフォルト");

const parameters = [
["話速", "1.5"],
["音高", "0.5"],
["抑揚", "1.5"],
["音量", "1.5"],
["間の長さ", "1.5"],
["開始無音", "0.3"],
["終了無音", "0.3"],
] as const;

for (const [name, newValue] of parameters) {
await test.step(`${name}変更`, async () => {
const input = page.getByLabel(name);
const originalValue = await input.inputValue();

await input.fill(newValue);
await input.press("Enter");

await exportSelectedAudioAndSnapshot(page, `${name}変更`);

await input.fill(originalValue);
await input.press("Enter");
});
}
});
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/unit/mock/engineMock/__snapshots__/index.spec.ts.snap

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

Loading