@@ -58,6 +58,7 @@ afterAll(async () => {
58
58
59
59
// full test basic operations on collection
60
60
test ( 'Collections | basic CRUD operations' , async ( ) => {
61
+ console . time ( 'Collections | basic CRUD operations' ) ;
61
62
// check if collections exist
62
63
const userColExists = await lStorage . collectionExists ( 'userCol' ) ;
63
64
// expect to be bollean
@@ -121,9 +122,11 @@ test('Collections | basic CRUD operations', async () => {
121
122
expect ( listCollections4 ) . not . toContain ( 'testCol' ) ;
122
123
expect ( listCollections4 ) . not . toContain ( 'userCol' ) ;
123
124
expect ( listCollections4 . length ) . toBe ( 0 ) ;
125
+ console . timeEnd ( 'Collections | basic CRUD operations' ) ;
124
126
} ) ;
125
127
// test create collection
126
128
test ( 'Collections | create via createCollection' , async ( ) => {
129
+ console . time ( 'Collections | create via createCollection' ) ;
127
130
const preListCheck = await lStorage . listCollections ( ) ;
128
131
expect ( preListCheck . length ) . toBe ( 0 ) ;
129
132
@@ -143,8 +146,10 @@ test('Collections | create via createCollection', async () => {
143
146
const listCollections22 = await lStorage . listCollections ( ) ;
144
147
expect ( listCollections22 ) . not . toContain ( 'userCol' ) ;
145
148
expect ( listCollections22 . length ) . toBe ( 0 ) ;
149
+ console . timeEnd ( 'Collections | create via createCollection' ) ;
146
150
} ) ;
147
151
test ( 'Collections | create via constructor' , async ( ) => {
152
+ console . time ( 'Collections | create via constructor' ) ;
148
153
const preListCheck = await lStorage . listCollections ( ) ;
149
154
expect ( preListCheck . length ) . toBe ( 0 ) ;
150
155
@@ -163,16 +168,26 @@ test('Collections | create via constructor', async () => {
163
168
const listCollections3 = await lStorage . listCollections ( ) ;
164
169
expect ( listCollections3 ) . not . toContain ( 'userCol' ) ;
165
170
expect ( listCollections3 . length ) . toBe ( 0 ) ;
171
+ console . timeEnd ( 'Collections | create via constructor' ) ;
166
172
} ) ;
167
173
test ( 'Collections | error cases and error codes' , async ( ) => {
174
+ console . time ( 'Collections | error cases and error codes' ) ;
168
175
// Test create collection error
169
- await expect ( lStorage . createCollection ( ) ) . rejects . toThrow ( lowstorageError ) ;
170
- await expect ( lStorage . createCollection ( ) ) . rejects . toThrow ( lowstorage_ERROR_CODES . MISSING_ARGUMENT ) ;
176
+ try {
177
+ await lStorage . createCollection ( ) ;
178
+ } catch ( error ) {
179
+ expect ( error ) . toBeInstanceOf ( lowstorageError ) ;
180
+ expect ( error . code ) . toBe ( lowstorage_ERROR_CODES . CREATE_COLLECTION_ERROR ) ;
181
+ }
171
182
172
- // Test collection already exists error
173
183
const testCol = await lStorage . createCollection ( 'testCol' , testColSchema ) ;
174
- await expect ( lStorage . createCollection ( 'testCol' , testColSchema ) ) . rejects . toThrow ( lowstorageError ) ;
175
- await expect ( lStorage . createCollection ( 'testCol' , testColSchema ) ) . rejects . toThrow ( lowstorage_ERROR_CODES . COLLECTION_EXISTS ) ;
184
+ // Test collection already exists error
185
+ try {
186
+ await lStorage . createCollection ( 'testCol' , testColSchema ) ;
187
+ } catch ( error ) {
188
+ expect ( error ) . toBeInstanceOf ( lowstorageError ) ;
189
+ expect ( error . code ) . toBe ( lowstorage_ERROR_CODES . CREATE_COLLECTION_ERROR ) ;
190
+ }
176
191
177
192
const listCollections = await lStorage . listCollections ( ) ;
178
193
expect ( listCollections ) . toContain ( 'testCol' ) ;
@@ -186,25 +201,34 @@ test('Collections | error cases and error codes', async () => {
186
201
await expect ( tesCol2 ) . toBeDefined ( ) ;
187
202
await expect ( tesCol2 ) . toBeInstanceOf ( Object ) ;
188
203
189
- const tesCol2Exists = await lStorage . collectionExists ( 'testCol2' ) ;
190
- expect ( tesCol2Exists ) . toBe ( true ) ;
204
+ const testCol2Exists = await lStorage . collectionExists ( 'testCol2' ) ;
205
+ expect ( testCol2Exists ) . toBe ( true ) ;
191
206
192
207
const listCollectionsAfterRename = await lStorage . listCollections ( ) ;
193
208
console . log ( 'listCollectionsAfterRename::::: ' , listCollectionsAfterRename ) ;
194
209
expect ( listCollectionsAfterRename ) . not . toContain ( 'testCol' ) ;
195
210
expect ( listCollectionsAfterRename ) . toContain ( 'testCol2' ) ;
196
211
197
212
// Verify the collection exists after renaming
198
- const testCol2Exists = await lStorage . collectionExists ( 'testCol2' ) ;
199
- expect ( testCol2Exists ) . toBe ( true ) ;
213
+ const col2Exists = await lStorage . collectionExists ( 'testCol2' ) ;
214
+ expect ( col2Exists ) . toBe ( true ) ;
200
215
201
216
// Test rename collection error
202
- await expect ( testCol . renameCollection ( 'testCol2' ) ) . rejects . toThrow ( lowstorageError ) ;
203
- await expect ( testCol . renameCollection ( 'testCol2' ) ) . rejects . toThrow ( lowstorage_ERROR_CODES . COLLECTION_EXISTS ) ;
217
+ // await expect(testCol.renameCollection('testCol2')).rejects.toThrow(lowstorageError);
218
+ try {
219
+ await testCol . renameCollection ( 'testCol2' ) ;
220
+ } catch ( error ) {
221
+ expect ( error ) . toBeInstanceOf ( lowstorageError ) ;
222
+ expect ( error . code ) . toBe ( lowstorage_ERROR_CODES . COLLECTION_EXISTS ) ;
223
+ }
204
224
205
225
// // Test remove collection error
206
- await expect ( lStorage . removeCollection ( 'testCol' ) ) . rejects . toThrow ( lowstorageError ) ;
207
- await expect ( lStorage . removeCollection ( 'testCol' ) ) . rejects . toThrow ( lowstorage_ERROR_CODES . REMOVE_COLLECTION_ERROR ) ;
226
+ try {
227
+ await lStorage . removeCollection ( 'testCol' ) ;
228
+ } catch ( error ) {
229
+ expect ( error ) . toBeInstanceOf ( lowstorageError ) ;
230
+ expect ( error . code ) . toBe ( lowstorage_ERROR_CODES . REMOVE_COLLECTION_ERROR ) ;
231
+ }
208
232
209
233
// Test update collection schema error - NOT IMPLEMENTED
210
234
// const testColSchema = {
@@ -255,9 +279,11 @@ test('Collections | error cases and error codes', async () => {
255
279
256
280
// Clean up
257
281
await lStorage . removeCollection ( 'testCol2' ) ;
282
+ console . timeEnd ( 'Collections | error cases and error codes' ) ;
258
283
} ) ;
259
284
260
285
test ( 'Document | CRUD operations' , async ( ) => {
286
+ console . time ( 'Document | CRUD operations' ) ;
261
287
// Test insert
262
288
const colName = 'testColXXXX' ;
263
289
const col = await lStorage . collection ( colName ) ;
@@ -412,9 +438,11 @@ test('Document | CRUD operations', async () => {
412
438
413
439
// cleanup
414
440
await lStorage . removeCollection ( colName ) ;
441
+ console . timeEnd ( 'Document | CRUD operations' ) ;
415
442
} ) ;
416
443
417
444
test ( 'Document | cachcing and race conditions' , async ( ) => {
445
+ console . time ( 'Document | cachcing and race conditions' ) ;
418
446
const colName = 'testColX1' ;
419
447
const exsists = await lStorage . collectionExists ( colName ) ;
420
448
if ( exsists ) {
@@ -494,4 +522,5 @@ test('Document | cachcing and race conditions', async () => {
494
522
expect ( updateCheck [ 0 ] ) . toHaveProperty ( 'name' , 'Carlos2' ) ;
495
523
expect ( updateCheck [ 0 ] ) . toHaveProperty ( 'age' , 25 ) ;
496
524
expect ( updateCheck [ 0 ] ) . not . toHaveProperty ( 'surname' , 'CarlosesSurname' ) ;
525
+ console . timeEnd ( 'Document | cachcing and race conditions' ) ;
497
526
} ) ;
0 commit comments