Skip to content

Commit a841168

Browse files
committed
feat: sdk tests
1 parent 932271f commit a841168

File tree

6 files changed

+453
-197
lines changed

6 files changed

+453
-197
lines changed

sdk/test/fakes.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,6 @@ export function streamFromString(input: string): ReadableStream<Uint8Array> {
77
});
88
}
99

10-
export class FakeWebSocket {
11-
sent: string[] = [];
12-
closed = false;
13-
14-
private listeners = new Map<string, Set<(...args: unknown[]) => void>>();
15-
16-
addEventListener(type: 'open' | 'close' | 'error' | 'message', listener: (event: unknown) => void): void {
17-
this.on(type, listener);
18-
}
19-
20-
on(type: string, listener: (...args: unknown[]) => void): void {
21-
const set = this.listeners.get(type) ?? new Set();
22-
set.add(listener);
23-
this.listeners.set(type, set);
24-
}
25-
26-
private emit(type: string, ...args: unknown[]): void {
27-
const set = this.listeners.get(type);
28-
if (!set) return;
29-
for (const cb of set) cb(...args);
30-
}
31-
32-
send(data: string): void {
33-
this.sent.push(data);
34-
}
35-
36-
close(): void {
37-
this.closed = true;
38-
this.emit('close', { code: 1000, reason: '' });
39-
}
40-
41-
emitOpen(): void {
42-
this.emit('open', {});
43-
}
44-
45-
emitMessageJson(obj: unknown): void {
46-
this.emit('message', { data: JSON.stringify(obj) });
47-
}
48-
49-
emitError(err: unknown): void {
50-
this.emit('error', err);
51-
}
52-
}
53-
5410
export type FetchCall = {
5511
url: string;
5612
init?: RequestInit;

sdk/test/integration/integration.test.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { describe, expect, it } from 'bun:test';
22

3-
import { PhasicClient } from '../../src/phasic';
4-
import { createNodeWebSocketFactory } from '../../src/node';
3+
// Native WebSocket is available in Node.js 22+, Bun, and browsers
4+
import { PhasicClient } from '../../src/index';
55

6-
function requireEnv(name: string): string {
7-
const v = process.env[name];
6+
function getEnv(name: string, fallback?: string): string | undefined {
7+
return process.env[name] ?? fallback;
8+
}
9+
10+
function requireEnv(name: string, altName?: string): string {
11+
const v = process.env[name] ?? (altName ? process.env[altName] : undefined);
812
if (!v) {
913
throw new Error(
1014
`Missing ${name}. Create an API key in Settings → API Keys and run: ${name}=<key> bun run test:integration`,
@@ -13,21 +17,20 @@ function requireEnv(name: string): string {
1317
return v;
1418
}
1519

16-
const describeIntegration =
17-
process.env.VIBESDK_RUN_INTEGRATION_TESTS === '1' &&
18-
process.env.VIBESDK_INTEGRATION_API_KEY
19-
? describe
20-
: describe.skip;
20+
// Support both VIBESDK_API_KEY (from .env) and VIBESDK_INTEGRATION_API_KEY
21+
const apiKeyAvailable = !!(process.env.VIBESDK_API_KEY || process.env.VIBESDK_INTEGRATION_API_KEY);
22+
const runIntegration = process.env.VIBESDK_RUN_INTEGRATION_TESTS === '1' || apiKeyAvailable;
23+
24+
const describeIntegration = runIntegration ? describe : describe.skip;
2125

2226
function previewUrlFromState(state: { previewUrl?: string; preview?: { status: string; previewURL?: string } }): string | undefined {
2327
if (state.preview?.status === 'complete' && state.preview.previewURL) return state.preview.previewURL;
2428
return state.previewUrl;
2529
}
2630

2731
describeIntegration('SDK integration (local platform)', () => {
28-
const apiKey = requireEnv('VIBESDK_INTEGRATION_API_KEY');
29-
const baseUrl = process.env.VIBESDK_INTEGRATION_BASE_URL ?? 'http://localhost:5173';
30-
const wsFactory = createNodeWebSocketFactory();
32+
const apiKey = requireEnv('VIBESDK_API_KEY', 'VIBESDK_INTEGRATION_API_KEY');
33+
const baseUrl = getEnv('VIBESDK_BASE_URL', getEnv('VIBESDK_INTEGRATION_BASE_URL', 'http://localhost:5173')) as string;
3134

3235
const fetchFn: typeof fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
3336
return await fetch(input, init);
@@ -56,7 +59,6 @@ describeIntegration('SDK integration (local platform)', () => {
5659
baseUrl,
5760
apiKey,
5861
fetchFn,
59-
webSocketFactory: wsFactory,
6062
});
6163

6264
console.log('[integration] build: creating agent');

0 commit comments

Comments
 (0)