e2e: add vite client build (#4643)

This commit is contained in:
Alex Yang
2025-09-23 23:07:50 +00:00
committed by GitHub
parent ca8e326ea4
commit cd84ef5c8b
7 changed files with 115 additions and 3 deletions
+13
View File
@@ -0,0 +1,13 @@
{
"name": "vite",
"private": true,
"scripts": {
"build": "vite build"
},
"dependencies": {
"better-auth": "workspace:*"
},
"devDependencies": {
"vite": "^7.1.5"
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference types="vite/client" />
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: [],
});
+11
View File
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "bundler",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
+19
View File
@@ -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",
},
});
+52
View File
@@ -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<void>((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",
);
});
});
+2 -1
View File
@@ -8,5 +8,6 @@
"strict": true,
"skipLibCheck": true,
"moduleResolution": "node16"
}
},
"include": ["./test/**/*"]
}
+10 -2
View File
@@ -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': {}