test: enable cloudflare smoke test (#4240)

This commit is contained in:
Alex Yang
2025-08-26 16:01:22 -07:00
committed by GitHub
parent af8a684381
commit 37b0fe22e4
33 changed files with 8961 additions and 1304 deletions

View File

@@ -0,0 +1,35 @@
import { describe, it } from "node:test";
import { spawn } from "node:child_process";
import { fileURLToPath } from "node:url";
import { join } from "node:path";
const fixturesDir = fileURLToPath(new URL("./fixtures", import.meta.url));
describe("(cloudflare) simple server", () => {
it("check repo", async (t) => {
const cp = spawn("npm", ["run", "check"], {
cwd: join(fixturesDir, "cloudflare"),
stdio: "pipe",
});
t.after(() => {
cp.kill("SIGINT");
});
cp.stdout.on("data", (data) => {
console.log(data.toString());
});
cp.stderr.on("data", (data) => {
console.error(data.toString());
});
await new Promise<void>((resolve) => {
cp.stdout.on("data", (data) => {
if (data.toString().includes("exiting now.")) {
resolve();
}
});
});
});
});

View File

@@ -1,105 +1,114 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
# Created by https://www.toptal.com/developers/gitignore/api/node,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=node,macos
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Node ###
# Logs
logs
_.log
npm-debug.log_
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Caches
.cache
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
_.pid
_.seed
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
# Moved from ./templates for ignoring all locks in templates
templates/**/*-lock.*
templates/**/*.lock
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
@@ -107,69 +116,73 @@ web_modules/
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# IntelliJ based IDEs
.idea
### Node Patch ###
# Serverless Webpack directories
.webpack/
# Finder (MacOS) folder config
.DS_Store
# Optional stylelint cache
# SvelteKit build / generate output
.svelte-kit
# End of https://www.toptal.com/developers/gitignore/api/node,macos
# Wrangler output
.wrangler/
build/
# Turbo output
.turbo/
.dev.vars*
!.dev.vars.example
.env*
!.env.example

View File

@@ -0,0 +1,22 @@
{
"name": "cloudflare",
"private": true,
"dependencies": {
"better-auth": "workspace:*",
"drizzle-orm": "^0.44.5",
"hono": "^4.9.4"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.8.67",
"@cloudflare/workers-types": "^4.20250826.0",
"drizzle-kit": "^0.31.4",
"wrangler": "4.33.0"
},
"scripts": {
"check": "tsc && wrangler deploy --dry-run",
"dev": "wrangler dev",
"migrate:local": "wrangler d1 migrations apply db --local",
"cf-typegen": "wrangler types --env-interface CloudflareBindings",
"e2e:smoke": "vitest"
}
}

View File

@@ -1,5 +1,26 @@
import { Hono } from "hono";
import { Auth, createAuth } from "./auth";
import { betterAuth } from "better-auth";
import { createDrizzle } from "./db";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
interface CloudflareBindings {
DB: D1Database;
}
const createAuth = (env: CloudflareBindings) =>
betterAuth({
baseURL: "http://localhost:4000",
database: drizzleAdapter(createDrizzle(env.DB), { provider: "sqlite" }),
emailAndPassword: {
enabled: true,
},
logger: {
level: "debug",
},
});
type Auth = ReturnType<typeof createAuth>;
const app = new Hono<{
Bindings: CloudflareBindings;

View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "esnext",
"lib": ["esnext"],
"module": "esnext",
"outDir": "./dist",
"moduleResolution": "bundler",
"types": [
"@cloudflare/workers-types/2023-07-01",
"@cloudflare/workers-types/experimental",
"@cloudflare/vitest-pool-workers"
],
"noEmit": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"strict": true
}
}

View File

@@ -14,7 +14,7 @@ export default defineWorkersProject(async () => {
poolOptions: {
workers: {
singleWorker: true,
wrangler: { configPath: "./wrangler.jsonc" },
wrangler: { configPath: "./wrangler.json" },
miniflare: {
d1Databases: ["DB"],
bindings: { TEST_MIGRATIONS: migrations },

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
{
"$schema": "node_modules/wrangler/config-schema.json",
"compatibility_date": "2025-04-01",
"main": "src/index.ts",
"name": "cloudflare",
"upload_source_maps": true,
"d1_databases": [
{
"binding": "DB",
"database_id": "d1-db-id",
"database_name": "db",
"migrations_dir": "./drizzle"
}
],
"observability": {
"enabled": true
}
}

View File

@@ -1,15 +0,0 @@
# bun
To install dependencies:
```bash
bun install
```
To run:
```bash
bun run index.ts
```
This project was created using `bun init` in bun v1.1.26. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

View File

@@ -1,12 +0,0 @@
import { betterAuth } from "better-auth";
import { twoFactor } from "better-auth/plugins";
import Database from "bun:sqlite";
export const auth = betterAuth({
baseURL: "http://localhost:4000",
database: new Database("./auth.db"),
emailAndPassword: {
enabled: true,
},
plugins: [twoFactor()],
});

View File

@@ -1,13 +0,0 @@
await fetch("http://localhost:4000/api/auth/sign-up/email", {
method: "POST",
body: JSON.stringify({
email: "test-2@test.com",
password: "password",
name: "test-2",
}),
headers: {
"content-type": "application/json",
},
})
.then((res) => res.json())
.then((data) => console.log(data));

View File

@@ -1,7 +0,0 @@
import { auth } from "./auth";
Bun.serve({
fetch: auth.handler,
port: 4000,
});
console.log("Server running on port 4000");

View File

@@ -1,22 +0,0 @@
{
"name": "@better-auth/bun",
"module": "index.ts",
"type": "module",
"private": true,
"scripts": {
"dev": "bun index.ts --hot"
},
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.7.2"
},
"dependencies": {
"@noble/ciphers": "^0.6.0",
"@types/better-sqlite3": "^7.6.12",
"better-auth": "workspace:*",
"better-sqlite3": "^11.6.0",
"pg": "^8.13.1"
}
}

View File

@@ -1,24 +0,0 @@
{
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
"declaration": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false,
"paths": {
"@/*": ["./src/*"]
}
}
}

View File

@@ -1,33 +0,0 @@
# prod
dist/
# dev
.yarn/
!.yarn/releases
.vscode/*
!.vscode/launch.json
!.vscode/*.code-snippets
.idea/workspace.xml
.idea/usage.statistics.xml
.idea/shelf
# deps
node_modules/
.wrangler
# env
.env
.env.production
.dev.vars
# logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
# misc
.DS_Store

View File

@@ -1,7 +0,0 @@
## How to run in dev
```
pnpm install
pnpm run migrate:local
pnpm run dev
```

View File

@@ -1,22 +0,0 @@
{
"name": "@better-auth/cloudflare",
"type": "module",
"private": true,
"scripts": {
"dev": "wrangler dev",
"migrate:local": "wrangler d1 migrations apply db --local",
"cf-typegen": "wrangler types --env-interface CloudflareBindings",
"test": "vitest"
},
"dependencies": {
"better-auth": "workspace:^",
"drizzle-orm": "^0.39.3",
"hono": "^4.7.2"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.8.60",
"@cloudflare/workers-types": "^4.20250805.0",
"drizzle-kit": "^0.30.4",
"wrangler": "^3.109.2"
}
}

View File

@@ -1,14 +0,0 @@
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { createDrizzle } from "./db";
export const createAuth = (env: CloudflareBindings) =>
betterAuth({
database: drizzleAdapter(createDrizzle(env.DB), { provider: "sqlite" }),
secret: "some-secret-value-here",
emailAndPassword: {
enabled: true,
},
});
export type Auth = ReturnType<typeof createAuth>;

View File

@@ -1,17 +0,0 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"skipLibCheck": true,
"lib": ["ESNext"],
"types": [
"@cloudflare/workers-types/2023-07-01",
"@cloudflare/workers-types/experimental",
"@cloudflare/vitest-pool-workers"
],
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx"
}
}

View File

@@ -1,5 +0,0 @@
// Generated by Wrangler by running `wrangler types --env-interface CloudflareBindings`
interface CloudflareBindings {
DB: D1Database;
}

View File

@@ -1,14 +0,0 @@
{
"$schema": "../../node_modules/wrangler/config-schema.json",
"name": "cloudflare",
"main": "src/index.ts",
"compatibility_date": "2025-02-14",
"d1_databases": [
{
"binding": "DB",
"database_id": "d1-db-id",
"database_name": "db",
"migrations_dir": "./drizzle"
}
]
}

View File

@@ -39,7 +39,8 @@
"remark-mdx": "3.0.0",
"remark-parse": "11.0.0",
"unified": "11.0.4",
"whatwg-url": "^14.0.0"
"whatwg-url": "^14.0.0",
"miniflare>zod": "^3"
}
},
"resolutions": {

1164
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,8 @@
packages:
- packages/**
- docs
- integration-tests/**
- demo/*
- e2e/*
- e2e/**
catalogs:
react18:
'@types/react': ^19.1.0