@@ -9,6 +9,7 @@ import { createCollection } from "@tanstack/db"
99import { electricCollectionOptions } from "../src/electric"
1010import { makePgClient } from "../../db-collection-e2e/support/global-setup"
1111import {
12+ createAccumulatedDataTestSuite ,
1213 createCollationTestSuite ,
1314 createDeduplicationTestSuite ,
1415 createJoinsTestSuite ,
@@ -314,3 +315,96 @@ describe(`Electric Collection E2E Tests`, () => {
314315 createLiveUpdatesTestSuite ( getConfig )
315316 createRegressionTestSuite ( getConfig )
316317} )
318+
319+ // Separate describe block for tests that expect accumulated data
320+ // These tests do NOT cleanup between tests to preserve data accumulation
321+ describe ( `Electric Collection E2E Tests - Accumulated Data` , ( ) => {
322+ let config : E2ETestConfig
323+ let dbClient : Client
324+ let usersTable : string
325+
326+ beforeAll ( async ( ) => {
327+ const baseUrl = inject ( `baseUrl` )
328+ const testSchema = inject ( `testSchema` )
329+ const seedData = generateSeedData ( )
330+
331+ const testId = Date . now ( ) . toString ( 16 )
332+ usersTable = `"users_accum_${ testId } "`
333+
334+ dbClient = makePgClient ( { options : `-csearch_path=${ testSchema } ` } )
335+ await dbClient . connect ( )
336+ await dbClient . query ( `SET search_path TO ${ testSchema } ` )
337+
338+ // Create and populate tables
339+ await dbClient . query ( `CREATE TABLE ${ usersTable } (
340+ id UUID PRIMARY KEY, name TEXT NOT NULL, email TEXT, age INTEGER NOT NULL,
341+ "isActive" BOOLEAN NOT NULL DEFAULT true, "createdAt" TIMESTAMP NOT NULL DEFAULT NOW(),
342+ metadata JSONB, "deletedAt" TIMESTAMP
343+ )` )
344+
345+ for ( const user of seedData . users ) {
346+ await dbClient . query (
347+ `INSERT INTO ${ usersTable } (id, name, email, age, "isActive", "createdAt", metadata, "deletedAt")
348+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8)` ,
349+ [
350+ user . id ,
351+ user . name ,
352+ user . email ,
353+ user . age ,
354+ user . isActive ,
355+ user . createdAt ,
356+ user . metadata ? JSON . stringify ( user . metadata ) : null ,
357+ user . deletedAt ,
358+ ]
359+ )
360+ }
361+
362+ // Create on-demand collection (NO cleanup between tests)
363+ const onDemandUsers = createCollection (
364+ electricCollectionOptions ( {
365+ id : `electric-accum-users-${ testId } ` ,
366+ shapeOptions : {
367+ url : `${ baseUrl } /v1/shape` ,
368+ params : { table : `${ testSchema } .${ usersTable } ` } ,
369+ } ,
370+ syncMode : `on-demand` ,
371+ getKey : ( item : any ) => item . id ,
372+ startSync : true ,
373+ } )
374+ )
375+
376+ await onDemandUsers . preload ( )
377+
378+ config = {
379+ collections : {
380+ eager : {
381+ users : onDemandUsers as any ,
382+ posts : null as any ,
383+ comments : null as any ,
384+ } ,
385+ onDemand : {
386+ users : onDemandUsers as any ,
387+ posts : null as any ,
388+ comments : null as any ,
389+ } ,
390+ } ,
391+ setup : async ( ) => { } ,
392+ teardown : async ( ) => {
393+ await onDemandUsers . cleanup ( )
394+ await dbClient . query ( `DROP TABLE IF EXISTS ${ usersTable } ` )
395+ await dbClient . end ( )
396+ } ,
397+ }
398+ } , 60000 )
399+
400+ afterAll ( async ( ) => {
401+ await config . teardown ( )
402+ } )
403+
404+ function getConfig ( ) {
405+ return Promise . resolve ( config )
406+ }
407+
408+ // Run accumulated data tests (no cleanup between these tests)
409+ createAccumulatedDataTestSuite ( getConfig )
410+ } )
0 commit comments