Skip to content

Commit

Permalink
テスト可能にした
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Nov 8, 2024
1 parent 5a1bfbe commit b536c2b
Show file tree
Hide file tree
Showing 7 changed files with 84,220 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/mock/engineMock/talkModelMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ async function createOrGetTokenizer() {
}

return new Promise<Tokenizer<IpadicFeatures>>((resolve, reject) => {
// NOTE: kuromojiはブラウザのときfetch、Nodeのときfsを使うので、このコードが正常動作するのはブラウザ環境のみ
const dicPath = `https://cdn.jsdelivr.net/npm/kuromoji@${packageJson.devDependencies.kuromoji}/dict`;
// ブラウザのときはCDNから辞書を取得し、Nodeのときはローカルから取得する
console.log(window);

Check warning on line 22 in src/mock/engineMock/talkModelMock.ts

View workflow job for this annotation

GitHub Actions / build_preview_pages

Unexpected console statement

Check warning on line 22 in src/mock/engineMock/talkModelMock.ts

View workflow job for this annotation

GitHub Actions / build_preview_pages

Unexpected console statement

Check warning on line 22 in src/mock/engineMock/talkModelMock.ts

View workflow job for this annotation

GitHub Actions / build-test

Unexpected console statement
const isBrowser = global == undefined;
const dicPath = isBrowser
? `https://cdn.jsdelivr.net/npm/kuromoji@${packageJson.devDependencies.kuromoji}/dict`
: "node_modules/kuromoji/dict";
kuromoji
.builder({ dicPath })
.build((err: Error, tokenizer: Tokenizer<IpadicFeatures>) => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions tests/unit/mock/engineMock/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`mock > audioQueryAudioQueryPost 1`] = `
{
"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,
}
`;

exports[`mock > synthesisSynthesisPost 1`] = `"680a0b3cb0e937d56e3f99304de0d352599439502443bae11828bf875be13bc4"`;

exports[`mock > versionVersionGet 1`] = `"mock"`;
31 changes: 31 additions & 0 deletions tests/unit/mock/engineMock/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { hash } from "../../utils";
import { createOpenAPIEngineMock } from "@/mock/engineMock";

describe("mock", () => {
const mock = createOpenAPIEngineMock();

it("versionVersionGet", async () => {
const response = await mock.versionVersionGet();
expect(response).toMatchSnapshot();
});

it("audioQueryAudioQueryPost", async () => {
const response = await mock.audioQueryAudioQueryPost({
text: "こんにちは",
speaker: 0,
});
expect(response).toMatchSnapshot();
});

it("synthesisSynthesisPost", async () => {
const audioQuery = await mock.audioQueryAudioQueryPost({
text: "こんにちは",
speaker: 0,
});
const response = await mock.synthesisSynthesisPost({
audioQuery,
speaker: 0,
});
expect(await hash(await response.arrayBuffer())).toMatchSnapshot();
});
});
Loading

0 comments on commit b536c2b

Please sign in to comment.