Skip to content

Commit bbfc7c1

Browse files
committed
feat(api): add node tests
1 parent 49c36ff commit bbfc7c1

156 files changed

Lines changed: 13835 additions & 198 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/api/env.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@ declare module "cloudflare:test" {
22
// Controls the type of `import("cloudflare:test").env`
33
interface ProvidedEnv extends Env {
44
AI: Ai;
5+
DB: D1Database;
6+
DATASETS_AUTORAG: string;
7+
CLOUDFLARE_ACCOUNT_ID: string;
8+
CLOUDFLARE_API_TOKEN: string;
59
}
610
}

apps/api/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devDependencies": {
2525
"@cloudflare/puppeteer": "^1.0.2",
2626
"@cloudflare/vitest-pool-workers": "^0.8.56",
27-
"@cloudflare/workers-types": "^4.20250723.0",
27+
"@cloudflare/workers-types": "^4.20250724.0",
2828
"@eslint/js": "^9.26.0",
2929
"@types/mailparser": "^3.4.6",
3030
"@types/node": "^22.15.3",
@@ -36,19 +36,19 @@
3636
"prettier": "^3.5.3",
3737
"typescript": "^5.8.3",
3838
"typescript-eslint": "^8.31.1",
39-
"vitest": "^3.1.2",
39+
"vitest": "^3.2.4",
4040
"wrangler": "^4.20.0"
4141
},
4242
"dependencies": {
4343
"@aws-sdk/client-ses": "^3.812.0",
44-
"@cf-wasm/photon": "^0.1.30",
44+
"@cf-wasm/photon": "^0.1.31",
4545
"@cf-wasm/quickjs": "^0.0.6",
4646
"@dafthunk/types": "workspace:*",
4747
"@hono-rate-limiter/cloudflare": "^0.2.2",
4848
"@hono/oauth-providers": "^0.7.1",
4949
"@hono/zod-validator": "^0.5.0",
5050
"@sendgrid/mail": "^8.1.5",
51-
"cloudflare": "^4.2.0",
51+
"cloudflare": "^4.5.0",
5252
"cron-parser": "^5.2.0",
5353
"drizzle-orm": "0.43.1",
5454
"exifreader": "^4.31.0",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
3+
import fs from "fs";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
// Read the MP3 file and convert it to a Uint8Array
11+
const mp3Path = path.join(
12+
__dirname,
13+
"..",
14+
"test",
15+
"fixtures",
16+
"en-us-hello.mp3"
17+
);
18+
const mp3Bytes = fs.readFileSync(mp3Path);
19+
20+
// Generate the fixture file content
21+
const fixtureContent = `// Auto-generated from en-us-hello.mp3
22+
export const enUsHelloBytes = new Uint8Array([
23+
${Array.from(mp3Bytes).join(", ")}
24+
]);
25+
26+
// Export audio data in a format suitable for testing
27+
export const testAudioData = {
28+
data: enUsHelloBytes,
29+
mimeType: "audio/mpeg",
30+
};
31+
`;
32+
33+
// Write the fixture file
34+
const fixturePath = path.join(
35+
__dirname,
36+
"..",
37+
"test",
38+
"fixtures",
39+
"audio-fixtures.ts"
40+
);
41+
fs.writeFileSync(fixturePath, fixtureContent);
42+
43+
console.log(`Generated audio fixtures at: ${fixturePath}`);
44+
console.log(`Audio file size: ${mp3Bytes.length} bytes`);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env node
2+
3+
import fs from "fs";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
// Read the lenna.png file
11+
const lennaPath = path.join(__dirname, "..", "test", "fixtures", "lenna.png");
12+
const lennaBytes = fs.readFileSync(lennaPath);
13+
14+
// Generate the fixture file content
15+
const fixtureContent = `// Auto-generated from lenna.png
16+
export const lennaBytes = new Uint8Array([
17+
${Array.from(lennaBytes).join(", ")}
18+
]);
19+
20+
// Export image data in a format suitable for testing
21+
export const testImageData = {
22+
data: lennaBytes,
23+
mimeType: "image/png",
24+
};
25+
`;
26+
27+
// Write the fixture file
28+
const fixturePath = path.join(
29+
__dirname,
30+
"..",
31+
"test",
32+
"fixtures",
33+
"image-fixtures.ts"
34+
);
35+
fs.writeFileSync(fixturePath, fixtureContent);
36+
37+
console.log(`Generated image fixtures at: ${fixturePath}`);
38+
console.log(`Image size: ${lennaBytes.length} bytes`);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env node
2+
3+
import fs from "fs";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
// Read the hello.pdf file
11+
const pdfPath = path.join(__dirname, "..", "test", "fixtures", "hello.pdf");
12+
const pdfBytes = fs.readFileSync(pdfPath);
13+
14+
// Generate the fixture file content
15+
const fixtureContent = `// Auto-generated from hello.pdf
16+
export const helloPdfBytes = new Uint8Array([
17+
${Array.from(pdfBytes).join(", ")}
18+
]);
19+
20+
// Export PDF data in a format suitable for testing
21+
export const testPdfData = {
22+
data: helloPdfBytes,
23+
mimeType: "application/pdf",
24+
};
25+
`;
26+
27+
// Write the fixture file
28+
const fixturePath = path.join(
29+
__dirname,
30+
"..",
31+
"test",
32+
"fixtures",
33+
"pdf-fixtures.ts"
34+
);
35+
fs.writeFileSync(fixturePath, fixtureContent);
36+
37+
console.log(`Generated PDF fixtures at: ${fixturePath}`);
38+
console.log(`PDF size: ${pdfBytes.length} bytes`);

0 commit comments

Comments
 (0)