From cd84ef5c8ba2d8d49b41455be5a0230f71f6fbf7 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Tue, 23 Sep 2025 16:07:50 -0700 Subject: [PATCH] e2e: add vite client build (#4643) --- e2e/smoke/test/fixtures/vite/package.json | 13 ++++++ e2e/smoke/test/fixtures/vite/src/client.ts | 8 ++++ e2e/smoke/test/fixtures/vite/tsconfig.json | 11 +++++ e2e/smoke/test/fixtures/vite/vite.config.ts | 19 ++++++++ e2e/smoke/test/vite.spec.ts | 52 +++++++++++++++++++++ e2e/smoke/tsconfig.json | 3 +- pnpm-lock.yaml | 12 ++++- 7 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 e2e/smoke/test/fixtures/vite/package.json create mode 100644 e2e/smoke/test/fixtures/vite/src/client.ts create mode 100644 e2e/smoke/test/fixtures/vite/tsconfig.json create mode 100644 e2e/smoke/test/fixtures/vite/vite.config.ts create mode 100644 e2e/smoke/test/vite.spec.ts diff --git a/e2e/smoke/test/fixtures/vite/package.json b/e2e/smoke/test/fixtures/vite/package.json new file mode 100644 index 0000000000..77f9256cdd --- /dev/null +++ b/e2e/smoke/test/fixtures/vite/package.json @@ -0,0 +1,13 @@ +{ + "name": "vite", + "private": true, + "scripts": { + "build": "vite build" + }, + "dependencies": { + "better-auth": "workspace:*" + }, + "devDependencies": { + "vite": "^7.1.5" + } +} diff --git a/e2e/smoke/test/fixtures/vite/src/client.ts b/e2e/smoke/test/fixtures/vite/src/client.ts new file mode 100644 index 0000000000..729c07a6d5 --- /dev/null +++ b/e2e/smoke/test/fixtures/vite/src/client.ts @@ -0,0 +1,8 @@ +/// +export * from "better-auth/client/plugins"; +import { createAuthClient } from "better-auth/client"; + +export const authClient = createAuthClient({ + baseURL: import.meta.env.VITE_BASE_URL || "http://localhost:3000", + plugins: [], +}); diff --git a/e2e/smoke/test/fixtures/vite/tsconfig.json b/e2e/smoke/test/fixtures/vite/tsconfig.json new file mode 100644 index 0000000000..9b229e1a46 --- /dev/null +++ b/e2e/smoke/test/fixtures/vite/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "moduleResolution": "bundler", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + } +} diff --git a/e2e/smoke/test/fixtures/vite/vite.config.ts b/e2e/smoke/test/fixtures/vite/vite.config.ts new file mode 100644 index 0000000000..171ecaba78 --- /dev/null +++ b/e2e/smoke/test/fixtures/vite/vite.config.ts @@ -0,0 +1,19 @@ +import { defineConfig } from "vite"; +import { resolve } from "node:path"; + +export default defineConfig({ + build: { + rollupOptions: { + input: { + client: resolve(__dirname, "src", "client.ts"), + }, + output: { + entryFileNames: "[name].js", + format: "es", + }, + treeshake: false, + }, + minify: false, + sourcemap: "inline", + }, +}); diff --git a/e2e/smoke/test/vite.spec.ts b/e2e/smoke/test/vite.spec.ts new file mode 100644 index 0000000000..55bd6458c3 --- /dev/null +++ b/e2e/smoke/test/vite.spec.ts @@ -0,0 +1,52 @@ +import { describe, it } from "node:test"; +import { fileURLToPath } from "node:url"; +import { join } from "node:path"; +import { spawn } from "node:child_process"; +import { readFile } from "node:fs/promises"; +import * as assert from "node:assert"; + +const fixturesDir = fileURLToPath(new URL("./fixtures", import.meta.url)); + +describe("(vite) client build", () => { + it("builds client without better-call imports", async () => { + const viteDir = join(fixturesDir, "vite"); + + // Run vite build + const buildProcess = spawn("npx", ["vite", "build"], { + cwd: viteDir, + stdio: "pipe", + }); + + // Wait for build to complete + await new Promise((resolve, reject) => { + buildProcess.on("close", (code) => { + if (code === 0) { + resolve(); + } else { + reject(new Error(`Vite build failed with code ${code}`)); + } + }); + + buildProcess.on("error", (error) => { + reject(error); + }); + + // Log build output for debugging + buildProcess.stdout.on("data", (data) => { + console.log(data.toString()); + }); + + buildProcess.stderr.on("data", (data) => { + console.error(data.toString()); + }); + }); + + const clientFile = join(viteDir, "dist", "client.js"); + const clientContent = await readFile(clientFile, "utf-8"); + + assert.ok( + !clientContent.includes("createEndpoint"), + "Built output should not contain 'better-call' imports", + ); + }); +}); diff --git a/e2e/smoke/tsconfig.json b/e2e/smoke/tsconfig.json index ab4e716956..865dd2b443 100644 --- a/e2e/smoke/tsconfig.json +++ b/e2e/smoke/tsconfig.json @@ -8,5 +8,6 @@ "strict": true, "skipLibCheck": true, "moduleResolution": "node16" - } + }, + "include": ["./test/**/*"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index afeb23e628..b2e5251a0d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -644,6 +644,16 @@ importers: specifier: 4.33.2 version: 4.33.2(@cloudflare/workers-types@4.20250903.0) + e2e/smoke/test/fixtures/vite: + dependencies: + better-auth: + specifier: workspace:* + version: link:../../../../../packages/better-auth + devDependencies: + vite: + specifier: ^7.1.5 + version: 7.1.5(@types/node@24.4.0)(jiti@2.6.0)(less@4.4.1)(lightningcss@1.30.1)(sass@1.90.0)(terser@5.44.0)(tsx@4.20.5)(yaml@2.8.1) + packages/better-auth: dependencies: '@better-auth/utils': @@ -15971,9 +15981,7 @@ snapshots: metro-runtime: 0.83.1 transitivePeerDependencies: - '@babel/core' - - bufferutil - supports-color - - utf-8-validate optional: true '@react-native/normalize-colors@0.79.6': {}