Skip to content

Commit

Permalink
画像ファイルの場所を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Nov 3, 2024
1 parent 968a2bc commit 815dd56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 128 deletions.
9 changes: 6 additions & 3 deletions src/mock/engineMock/characterResourceMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
* なんとなくVOICEVOX ENGINEリポジトリのモック実装と揃えている。
*/

import { assetsPath } from "./constants";
import { Speaker, SpeakerInfo } from "@/openapi";

/** 画像ファイルなどがあるURLのベース */
const assetsUrl =
"https://raw.githubusercontent.com/VOICEVOX/voicevox/e1304cce2b7bf23798023f6d61354893a8b93566/tests/e2e/browser/assets";

const baseCharactersMock = [
// トーク2つ・ハミング2つ
{
Expand Down Expand Up @@ -95,11 +98,11 @@ export function getCharacterInfoMock(speakerUuid: string): SpeakerInfo {

return {
policy: `Dummy policy for ${speakerUuid}`,
portrait: `${assetsPath}/portrait_${speakerIndex + 1}.png`,
portrait: `${assetsUrl}/portrait_${speakerIndex + 1}.png`,
styleInfos: styleIds.map((id) => {
return {
id,
icon: `${assetsPath}/icon_${speakerIndex + 1}.png`,
icon: `${assetsUrl}/icon_${speakerIndex + 1}.png`,
voiceSamples: [],
};
}),
Expand Down
5 changes: 0 additions & 5 deletions src/mock/engineMock/constants.ts

This file was deleted.

120 changes: 0 additions & 120 deletions tests/e2e/browser/スクリーンショット.spec.ts
Original file line number Diff line number Diff line change
@@ -1,126 +1,6 @@
import path from "path";
import fs from "fs/promises";
import { test, expect } from "@playwright/test";
import { gotoHome, navigateToMain } from "../navigators";
import {
Speaker,
SpeakerFromJSON,
SpeakerInfo,
SpeakerInfoFromJSON,
SpeakerInfoToJSON,
SpeakerToJSON,
} from "@/openapi";

let speakerImages:
| {
portrait: string;
icon: string;
}[]
| undefined = undefined;

/**
* 差し替え用の立ち絵・アイコンを取得する。
*/
async function getSpeakerImages(): Promise<
{
portrait: string;
icon: string;
}[]
> {
if (!speakerImages) {
const assetsPath = path.resolve(__dirname, "../../assets");
const images = await fs.readdir(assetsPath);
const icons = images.filter((image) => image.startsWith("icon"));
icons.sort(
(a, b) =>
parseInt(a.split(".")[0].split("_")[1]) -
parseInt(b.split(".")[0].split("_")[1]),
);
speakerImages = await Promise.all(
icons.map(async (iconPath) => {
const portraitPath = iconPath.replace("icon_", "portrait_");
const portrait = await fs.readFile(
path.join(assetsPath, portraitPath),
"base64",
);
const icon = await fs.readFile(
path.join(assetsPath, iconPath),
"base64",
);

return { portrait, icon };
}),
);
}
return speakerImages;
}

test.beforeEach(async ({ page }) => {
let speakers: Speaker[];
const speakerImages = await getSpeakerImages();
// Voicevox Nemo EngineでもVoicevox Engineでも同じ結果が選られるように、
// GET /speakers、GET /speaker_infoの話者名、スタイル名、画像を差し替える。
await page.route(/\/speakers$/, async (route) => {
const response = await route.fetch();
const json: Speaker[] = await response
.json()
.then((json: unknown[]) => json.map(SpeakerFromJSON));
let i = 0;
for (const speaker of json) {
i++;
speaker.name = `Speaker ${i}`;
let j = 0;
for (const style of speaker.styles) {
j++;
style.name = `Style ${i}-${j}`;
}
}
speakers = json;
await route.fulfill({
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
},
body: JSON.stringify(json.map(SpeakerToJSON)),
});
});
await page.route(/\/speaker_info\?/, async (route) => {
if (!speakers) {
// Unreachableのはず
throw new Error("speakers is not initialized");
}
const url = new URL(route.request().url());
const speakerUuid = url.searchParams.get("speaker_uuid");
if (!speakerUuid) {
throw new Error("speaker_uuid is not set");
}
const response = await route.fetch();
const json: SpeakerInfo = await response.json().then(SpeakerInfoFromJSON);
const speakerIndex = speakers.findIndex(
(speaker) => speaker.speakerUuid === speakerUuid,
);
if (speakerIndex === -1) {
throw new Error(`speaker_uuid=${speakerUuid} is not found`);
}
const image = speakerImages[speakerIndex % speakerImages.length];
json.portrait = image.portrait;
for (const style of json.styleInfos) {
style.icon = image.icon;
if ("portrait" in style) {
delete style.portrait;
}
}
await route.fulfill({
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
},
body: JSON.stringify(SpeakerInfoToJSON(json)),
});
});
});
test.beforeEach(gotoHome);

test("メイン画面の表示", async ({ page }) => {
Expand Down

0 comments on commit 815dd56

Please sign in to comment.