Skip to content

Commit c108892

Browse files
committed
all tests
1 parent 003f33c commit c108892

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

tests/main.test.ts

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,66 @@
11
import { expect, test } from 'vitest';
22

3-
test('speech-to-text', async () => {
3+
test('text-to-speech', async () => {
44
return new Promise(async (resolve) => {
5-
const { transcribeAudioFile } = await import("../src/index");
5+
const { textToSpeech } = await import("../src/index");
6+
7+
const audio = await textToSpeech("Hello, World!");
8+
expect(audio).toBeDefined();
69

7-
const input = document.createElement("button");
10+
resolve(true);
11+
});
12+
});
813

9-
input.onclick = async (e) => {
10-
const response = await fetch("https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/ted_60_16k.wav");
11-
const blob = await response.blob();
14+
test('speech-to-text', async () => {
15+
return new Promise(async (resolve) => {
16+
const { transcribeAudioFile } = await import("../src/index");
1217

13-
const text = await transcribeAudioFile(blob);
14-
console.log(text);
15-
expect(text).toBeDefined();
18+
const response = await fetch("https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/ted_60_16k.wav");
19+
const blob = await response.blob();
1620

17-
resolve(true);
18-
};
21+
const text = await transcribeAudioFile(blob);
22+
expect(text).toBeDefined();
1923

20-
document.body.appendChild(input);
24+
resolve(true);
2125
});
2226
});
2327

2428
test('ocr', async () => {
2529
return new Promise(async (resolve) => {
2630
const { ocr } = await import("../src/index");
2731

28-
const input = document.createElement("input");
29-
input.type = "file";
30-
input.accept = "image/*";
32+
const response = await fetch("https://picsum.photos/200/300");
33+
const blob = await response.blob();
34+
35+
const text = await ocr(blob);
36+
37+
expect(text).toBeDefined();
38+
resolve(true);
39+
});
40+
});
41+
42+
test('image-classification', async () => {
43+
return new Promise(async (resolve) => {
44+
const { classifyImage } = await import("../src/index");
45+
46+
const response = await fetch("https://picsum.photos/200/300");
47+
const blob = await response.blob();
3148

32-
input.onchange = async (e) => {
33-
const file = (e.target as any).files[0];
34-
const text = await ocr(URL.createObjectURL(file) as any);
49+
const text = await classifyImage(blob);
50+
51+
expect(text).toBeDefined();
52+
resolve(true);
53+
});
54+
});
55+
56+
test('summarize', async () => {
57+
return new Promise(async (resolve) => {
58+
const { summarize } = await import("../src/index");
3559

36-
expect(text).toBeDefined();
37-
resolve(true);
38-
};
60+
const text = "the red fox is a small fox that lives in the forest. it has a red coat and a bushy tail. the red fox is a carnivore, which means it eats meat. it hunts small animals like rabbits";
61+
const summary = await summarize(text);
3962

40-
document.body.appendChild(input);
63+
expect(summary).toBeDefined();
64+
resolve(true);
4165
});
4266
});

vitest.workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineWorkspace([
99
testTimeout: 2000000,
1010
browser: {
1111
enabled: true,
12-
name: 'edge-canary',
12+
name: 'edge',
1313
provider: 'preview',
1414
},
1515
},

0 commit comments

Comments
 (0)