1- import { AbstractPowerSyncDatabase , Column , ColumnType , CrudEntry , Schema , Table , UpdateType } from '@powersync/common' ;
2- import { PowerSyncDatabase } from '@powersync/web' ;
1+ import { Column , ColumnType , CrudEntry , Schema , Table , UpdateType } from '@powersync/common' ;
32import pDefer from 'p-defer' ;
43import { v4 as uuid } from 'uuid' ;
5- import { afterEach , beforeEach , describe , expect , it } from 'vitest' ;
4+ import { describe , expect , it } from 'vitest' ;
65import { generateTestDb } from './utils/testDb' ;
76
87const testId = '2290de4f-0488-4e50-abed-f8e8eb1d0b42' ;
98
10- describe ( 'CRUD Tests' , ( ) => {
11- let powersync : AbstractPowerSyncDatabase ;
12-
13- beforeEach ( async ( ) => {
14- powersync = generateTestDb ( ) ;
15- } ) ;
16-
17- afterEach ( async ( ) => {
18- await powersync . disconnectAndClear ( ) ;
19- await powersync . close ( ) ;
20- } ) ;
21-
9+ describe ( 'CRUD Tests' , { sequential : true } , ( ) => {
2210 it ( 'INSERT' , async ( ) => {
11+ const powersync = generateTestDb ( ) ;
12+
2313 expect ( await powersync . getAll ( 'SELECT * FROM ps_crud' ) ) . empty ;
2414
2515 await powersync . execute ( 'INSERT INTO assets(id, description) VALUES(?, ?)' , [ testId , 'test' ] ) ;
@@ -37,6 +27,8 @@ describe('CRUD Tests', () => {
3727 } ) ;
3828
3929 it ( 'BATCH INSERT' , async ( ) => {
30+ const powersync = generateTestDb ( ) ;
31+
4032 expect ( await powersync . getAll ( 'SELECT * FROM ps_crud' ) ) . empty ;
4133
4234 const query = `INSERT INTO assets(id, description) VALUES(?, ?)` ;
@@ -63,6 +55,8 @@ describe('CRUD Tests', () => {
6355 } ) ;
6456
6557 it ( 'INSERT OR REPLACE' , async ( ) => {
58+ const powersync = generateTestDb ( ) ;
59+
6660 await powersync . execute ( 'INSERT INTO assets(id, description) VALUES(?, ?)' , [ testId , 'test' ] ) ;
6761 await powersync . execute ( 'DELETE FROM ps_crud WHERE 1' ) ;
6862
@@ -85,6 +79,8 @@ describe('CRUD Tests', () => {
8579 } ) ;
8680
8781 it ( 'UPDATE' , async ( ) => {
82+ const powersync = generateTestDb ( ) ;
83+
8884 await powersync . execute ( 'INSERT INTO assets(id, description, make) VALUES(?, ?, ?)' , [ testId , 'test' , 'test' ] ) ;
8985 await powersync . execute ( 'DELETE FROM ps_crud WHERE 1' ) ;
9086
@@ -105,6 +101,8 @@ describe('CRUD Tests', () => {
105101 } ) ;
106102
107103 it ( 'BATCH UPDATE' , async ( ) => {
104+ const powersync = generateTestDb ( ) ;
105+
108106 await powersync . executeBatch ( 'INSERT INTO assets(id, description, make) VALUES(?, ?, ?)' , [
109107 [ testId , 'test' , 'test' ] ,
110108 [ 'mockId' , 'test' , 'test' ]
@@ -137,6 +135,8 @@ describe('CRUD Tests', () => {
137135 } ) ;
138136
139137 it ( 'DELETE' , async ( ) => {
138+ const powersync = generateTestDb ( ) ;
139+
140140 await powersync . execute ( 'INSERT INTO assets(id, description, make) VALUES(?, ?, ?)' , [ testId , 'test' , 'test' ] ) ;
141141 await powersync . execute ( 'DELETE FROM ps_crud WHERE 1' ) ;
142142
@@ -153,6 +153,8 @@ describe('CRUD Tests', () => {
153153 } ) ;
154154
155155 it ( 'UPSERT not supported' , async ( ) => {
156+ const powersync = generateTestDb ( ) ;
157+
156158 // Just shows that we cannot currently do this
157159 await expect (
158160 powersync . execute ( 'INSERT INTO assets(id, description) VALUES(?, ?) ON CONFLICT DO UPDATE SET description = ?' , [
@@ -164,9 +166,7 @@ describe('CRUD Tests', () => {
164166 } ) ;
165167
166168 it ( 'INSERT-only tables' , async ( ) => {
167- await powersync . disconnectAndClear ( ) ;
168-
169- powersync = new PowerSyncDatabase ( {
169+ const powersync = generateTestDb ( {
170170 /**
171171 * Deleting the IndexDB seems to freeze the test.
172172 * Use a new DB for each run to keep CRUD counters
@@ -212,6 +212,8 @@ describe('CRUD Tests', () => {
212212 } ) ;
213213
214214 it ( 'big numbers - integer' , async ( ) => {
215+ const powersync = generateTestDb ( ) ;
216+
215217 const bigNumber = 1 << 62 ;
216218 await powersync . execute ( 'INSERT INTO assets(id, quantity) VALUES(?, ?)' , [ testId , bigNumber ] ) ;
217219
@@ -233,6 +235,8 @@ describe('CRUD Tests', () => {
233235 } ) ;
234236
235237 it ( 'big numbers - text' , async ( ) => {
238+ const powersync = generateTestDb ( ) ;
239+
236240 const bigNumber = 1 << 62 ;
237241 await powersync . execute ( 'INSERT INTO assets(id, quantity) VALUES(?, ?)' , [ testId , `${ bigNumber } ` ] ) ;
238242
@@ -263,6 +267,8 @@ describe('CRUD Tests', () => {
263267 } ) ;
264268
265269 it ( 'Transaction grouping' , async ( ) => {
270+ const powersync = generateTestDb ( ) ;
271+
266272 expect ( await powersync . getAll ( 'SELECT * FROM ps_crud' ) ) . empty ;
267273 await powersync . writeTransaction ( async ( tx ) => {
268274 await tx . execute ( 'INSERT INTO assets(id, description) VALUES(?, ?)' , [ testId , 'test1' ] ) ;
@@ -292,6 +298,8 @@ describe('CRUD Tests', () => {
292298 } ) ;
293299
294300 it ( 'Transaction exclusivity' , async ( ) => {
301+ const powersync = generateTestDb ( ) ;
302+
295303 const outside = pDefer ( ) ;
296304 const inTx = pDefer ( ) ;
297305
@@ -313,6 +321,8 @@ describe('CRUD Tests', () => {
313321 } ) ;
314322
315323 it ( 'CRUD Batch Limits' , async ( ) => {
324+ const powersync = generateTestDb ( ) ;
325+
316326 const initialBatch = await powersync . getCrudBatch ( ) ;
317327 expect ( initialBatch , 'Initial CRUD batch should be null' ) . null ;
318328
0 commit comments