Repository: maxnowack/signaldb
Pull request #179 (2023-09-20 11:22:41)

test: improve coverage

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/maxnowack/signaldb/pull/179?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Max+Nowack) Report
> Merging [#179](https://app.codecov.io/gh/maxnowack/signaldb/pull/179?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Max+Nowack) (5fc6ce2) into [main](https://app.codecov.io/gh/maxnowack/signaldb/commit/54847905ed02f8bc2ca3c2f68f30067d4f6a6b73?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Max+Nowack) (5484790) will **increase** coverage by `0.67%`.
> The diff coverage is `50.00%`.

```diff
@@            Coverage Diff             @@
##             main     #179      +/-   ##
==========================================
+ Coverage   97.45%   98.13%   +0.67%     
==========================================
  Files          20       20              
  Lines         746      749       +3     
  Branches      195      197       +2     
==========================================
+ Hits          727      735       +8     
+ Misses         19       14       -5     
```


| [Files Changed](https://app.codecov.io/gh/maxnowack/signaldb/pull/179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Max+Nowack) | Coverage Δ | |
|---|---|---|
| [src/utils/sortItems.ts](https://app.codecov.io/gh/maxnowack/signaldb/pull/179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Max+Nowack#diff-c3JjL3V0aWxzL3NvcnRJdGVtcy50cw==) | `46.66% <50.00%> (+5.00%)` | :arrow_up: |

... and [2 files with indirect coverage changes](https://app.codecov.io/gh/maxnowack/signaldb/pull/179/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Max+Nowack)



Patch:
diff --git a/src/Collection/Observer.ts b/src/Collection/Observer.ts
index 3d41685..d546601 100644
--- a/src/Collection/Observer.ts
+++ b/src/Collection/Observer.ts
@@ -18,7 +18,7 @@ export default class Observer<T extends { id: any }> {
   constructor(
     callbacks: ObserveCallbacks<T>,
     bindEvents: () => () => void,
-    skipInitial = false,
+    skipInitial: boolean,
   ) {
     this.callbacks = callbacks
     this.skipInitial = skipInitial
diff --git a/src/utils/sortItems.spec.ts b/src/utils/sortItems.spec.ts
index a1a382a..0bcab34 100644
--- a/src/utils/sortItems.spec.ts
+++ b/src/utils/sortItems.spec.ts
@@ -45,4 +45,18 @@ describe('sortItems', () => {
       { id: 2, name: 'Charlie', age: 35 },
     ])
   })
+
+  it('should sort items in descending order based on name', () => {
+    const items: Item[] = [
+      { id: 3, name: 'Alice', age: 25 },
+      { id: 1, name: 'Bob', age: 30 },
+      { id: 2, name: 'Charlie', age: 35 },
+    ]
+    const result = sortItems(items, { name: -1 })
+    expect(result).toEqual([
+      { id: 2, name: 'Charlie', age: 35 },
+      { id: 1, name: 'Bob', age: 30 },
+      { id: 3, name: 'Alice', age: 25 },
+    ])
+  })
 })


Test patch:
diff --git a/__tests__/Collection.spec.ts b/__tests__/Collection.spec.ts
index bd55b13..0f8588a 100644
--- a/__tests__/Collection.spec.ts
+++ b/__tests__/Collection.spec.ts
@@ -1,12 +1,12 @@
 import { vi, beforeEach, describe, it, expect } from 'vitest'
-import { Collection } from '../src/index'
+import { Collection, createMemoryAdapter } from '../src/index'
 
 describe('Collection', () => {
   let collection: Collection<{ id: string, name: string }>
 
   beforeEach(() => {
     collection = new Collection<{ id: string, name: string }>({
-      memory: [],
+      memory: createMemoryAdapter([]),
     })
   })
 
diff --git a/__tests__/Reactivity.spec.ts b/__tests__/Reactivity.spec.ts
index 0aac93e..d81584c 100644
--- a/__tests__/Reactivity.spec.ts
+++ b/__tests__/Reactivity.spec.ts
@@ -35,12 +35,11 @@ import S from 's-js'
 //   onCleanup as solidCleanup,
 //   createRoot as solidCreateRoot,
 // } from 'solid-js'
-import type { ReactivityAdapter } from '../src/index'
-import { Collection } from '../src/index'
+import { Collection, createReactivityAdapter } from '../src/index'
 
 describe('Reactivity', () => {
   describe('Tracker', () => {
-    const reactivity: ReactivityAdapter = {
+    const reactivity = createReactivityAdapter({
       create: () => {
         const dep = new Tracker.Dependency()
         return {
@@ -56,7 +55,7 @@ describe('Reactivity', () => {
         if (!Tracker.active) return
         Tracker.onInvalidate(callback)
       }),
-    }
+    })
 
     it('should be reactive with Tracker', () => {
       const collection = new Collection({ reactivity })
@@ -91,7 +90,7 @@ describe('Reactivity', () => {
   })
 
   describe('@maverick-js/signals', () => {
-    const reactivity: ReactivityAdapter = {
+    const reactivity = createReactivityAdapter({
       create: () => {
         const dep = maverickSignal(0)
         return {
@@ -107,7 +106,7 @@ describe('Reactivity', () => {
       onDispose: vi.fn((callback) => {
         maverickOnDispose(callback)
       }),
-    }
+    })
 
     it('should be reactive with @maverick-js/signals', () => {
       const collection = new Collection({ reactivity })
@@ -126,7 +125,7 @@ describe('Reactivity', () => {
   })
 
   describe('oby', () => {
-    const reactivity: ReactivityAdapter = {
+    const reactivity = createReactivityAdapter({
       create: () => {
         const dep = $oby(0)
         return {
@@ -142,7 +141,7 @@ describe('Reactivity', () => {
       onDispose: vi.fn((callback) => {
         obyCleanup(callback)
       }),
-    }
+    })
 
     it('should be reactive with oby', () => {
       const collection = new Collection({ reactivity })
@@ -161,7 +160,7 @@ describe('Reactivity', () => {
   })
 
   describe('usignal', () => {
-    const reactivity: ReactivityAdapter = {
+    const reactivity = createReactivityAdapter({
       create: () => {
         const dep = uSignal(0)
         return {
@@ -174,7 +173,7 @@ describe('Reactivity', () => {
           },
         }
       },
-    }
+    })
 
     it('should be reactive with usignal', () => {
       const collection = new Collection({ reactivity })
@@ -197,7 +196,7 @@ describe('Reactivity', () => {
   })
 
   describe('sinuous', () => {
-    const reactivity: ReactivityAdapter = {
+    const reactivity = createReactivityAdapter({
       create: () => {
         const dep = sinuousObservable(0)
         return {
@@ -212,7 +211,7 @@ describe('Reactivity', () => {
       onDispose: vi.fn((callback) => {
         sinuousApi.cleanup(callback)
       }),
-    }
+    })
 
     it('should be reactive with sinuous', () => {
       const collection = new Collection({ reactivity })
@@ -230,7 +229,7 @@ describe('Reactivity', () => {
   })
 
   describe('preact', () => {
-    const reactivity: ReactivityAdapter = {
+    const reactivity = createReactivityAdapter({
       create: () => {
         const dep = preactSignal(0)
         return {
@@ -243,7 +242,7 @@ describe('Reactivity', () => {
           },
         }
       },
-    }
+    })
 
     it('should be reactive with preact', () => {
       const collection = new Collection({ reactivity })
@@ -266,7 +265,7 @@ describe('Reactivity', () => {
   })
 
   describe('@reactively/core', () => {
-    const reactivity: ReactivityAdapter = {
+    const reactivity = createReactivityAdapter({
       create: () => {
         const dep = reactively(0)
         return {
@@ -281,7 +280,7 @@ describe('Reactivity', () => {
       onDispose: vi.fn((callback) => {
         reactivelyOnCleanup(callback)
       }),
-    }
+    })
 
     it('should be reactive with reactively', () => {
       const collection = new Collection({ reactivity })
@@ -302,7 +301,7 @@ describe('Reactivity', () => {
   })
 
   describe('S.js', () => {
-    const reactivity: ReactivityAdapter = {
+    const reactivity = createReactivityAdapter({
       create: () => {
         const dep = S.data(true)
         return {
@@ -317,7 +316,7 @@ describe('Reactivity', () => {
       onDispose: vi.fn((callback) => {
         S.cleanup(callback)
       }),
-    }
+    })
 
     it('should be reactive with S.js', () => {
       const collection = new Collection({ reactivity })
@@ -337,7 +336,7 @@ describe('Reactivity', () => {
   // solid doenst work in a node environment since createEffect won't run
   // eslint-disable-next-line vitest/no-commented-out-tests
   // describe('solid', () => {
-  //   const reactivity: ReactivityAdapter = {
+  //   const reactivity = createReactivityAdapter({
   //     create: () => {
   //       const [depend, rerun] = solidSignal(undefined, { equals: false })
   //       return {
@@ -352,7 +351,7 @@ describe('Reactivity', () => {
   //     onDispose: (callback) => {
   //       solidCleanup(callback)
   //     },
-  //   }
+  //   })
 
   // eslint-disable-next-line vitest/no-commented-out-tests
   //   it('should be reactive with solid', () => {
diff --git a/__tests__/persistence.spec.ts b/__tests__/persistence.spec.ts
index 89e9f47..fe0c7f9 100644
--- a/__tests__/persistence.spec.ts
+++ b/__tests__/persistence.spec.ts
@@ -179,6 +179,13 @@ describe('Persistence', () => {
     collection.on('persistence.error', fn)
     await waitForEvent(collection, 'persistence.init')
     collection.insert({ id: '1' })
+
+    collection.updateOne({ id: '1' }, { $set: { name: 'John' } })
+    await waitForEvent(collection, 'persistence.error')
+
+    collection.removeOne({ id: '1' })
+    await waitForEvent(collection, 'persistence.error')
+
     await waitForEvent(collection, 'persistence.error')
     expect(fn).toHaveBeenCalledWith(new Error('test'))
   })
@@ -233,6 +240,13 @@ describe('Persistence', () => {
     await waitForEvent(collection, 'persistence.init')
     collection.insert({ id: '1' })
     await waitForEvent(collection, 'persistence.error')
+
+    collection.updateOne({ id: '1' }, { $set: { name: 'John' } })
+    await waitForEvent(collection, 'persistence.error')
+
+    collection.removeOne({ id: '1' })
+    await waitForEvent(collection, 'persistence.error')
+
     expect(fn).toHaveBeenCalledWith(new Error('test'))
   })
 })