1- import "dotenv/config" ;
2-
3- import fetch from "node-fetch" ;
4- import type { URL } from "url" ;
51import { expect , onTestFinished } from "vitest" ;
62import WebSocket from "ws" ;
73
@@ -19,9 +15,7 @@ import { mapValues, wait, withTimeout } from "../src/lib/utils";
1915import type { BaseUserMeta } from "../src/protocol/BaseUserMeta" ;
2016import type { Room , RoomEventMessage } from "../src/room" ;
2117
22- const BASE_URL =
23- process . env . NEXT_PUBLIC_LIVEBLOCKS_BASE_URL ?? "https://api.liveblocks.io" ;
24- console . log ( `Running against Liveblocks base URL: ${ BASE_URL } ` ) ;
18+ const BASE_URL = "http://localhost:1154" ;
2519
2620async function initializeRoomForTest <
2721 P extends JsonObject = JsonObject ,
@@ -31,12 +25,6 @@ async function initializeRoomForTest<
3125 TM extends BaseMetadata = BaseMetadata ,
3226 CM extends BaseMetadata = BaseMetadata ,
3327> ( roomId : string , initialPresence : NoInfr < P > , initialStorage : NoInfr < S > ) {
34- const publicApiKey = process . env . LIVEBLOCKS_PUBLIC_KEY ;
35-
36- if ( ! publicApiKey ) {
37- throw new Error ( 'Environment variable "LIVEBLOCKS_PUBLIC_KEY" is missing.' ) ;
38- }
39-
4028 let ws : PausableWebSocket | null = null ;
4129
4230 class PausableWebSocket extends WebSocket {
@@ -80,11 +68,8 @@ async function initializeRoomForTest<
8068
8169 const client = createClient < U > ( {
8270 __DANGEROUSLY_disableThrottling : true ,
83- enableDebugLogging : true ,
84- publicApiKey,
71+ publicApiKey : "pk_localdev" ,
8572 polyfills : {
86- // @ts -expect-error fetch from Node isn't compatible?
87- fetch,
8873 WebSocket : PausableWebSocket ,
8974 } ,
9075 baseUrl : BASE_URL ,
@@ -193,7 +178,7 @@ export function prepareTestsConflicts<S extends LsonObject>(
193178 // Unfortunately there is no public API to know this has happened. It
194179 // typically happens within ~5 ms, so we'll wait a multitude of that
195180 // here, just to be sure.
196- setTimeout ( resolve , 150 ) ;
181+ setTimeout ( resolve , 50 ) ;
197182 }
198183 beacons . delete ( event . beacon ) ;
199184 }
@@ -338,7 +323,7 @@ export function prepareSingleClientTest<S extends LsonObject>(
338323
339324 // Waiting until every messages are received by all clients.
340325 // We don't have a public way to know if everything has been received so we have to rely on time
341- await wait ( 600 ) ;
326+ await wait ( 200 ) ;
342327
343328 actor . ws . pause ( ) ;
344329
@@ -354,7 +339,7 @@ export function prepareSingleClientTest<S extends LsonObject>(
354339 actor . ws . resume ( ) ;
355340 // Waiting until every messages are received by all clients.
356341 // We don't have a public way to know if everything has been received so we have to rely on time
357- await wait ( 600 ) ;
342+ await wait ( 200 ) ;
358343 } ,
359344 } ) ;
360345 actor . leave ( ) ;
0 commit comments