Skip to content

Commit

Permalink
fix: Wrap cozy-dataproxy-lib imports in a mockable file
Browse files Browse the repository at this point in the history
For some reasons, the ReactNative API fails to resolve
`cozy-dataproxy-lib/api` path so we must use `/dist` version instead

On the opposite, Jest will fail to resolve the `/dist` version so we
cannot mock cozy-dataproxy-lib

To fix this, we wrap the imports in a local file so we can mock this
local file in Jest
  • Loading branch information
Ldoppea committed Jan 17, 2025
1 parent 94af15c commit 235beab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions __tests__/jestSetupFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,7 @@ jest.mock('cozy-pouch-link', () => {
jest.mock('react-native-mail', () => ({
mail: jest.fn()
}))

jest.mock('/app/domain/search/dataproxy-wrapper', () => ({
SearchEngine: jest.fn()
}))
5 changes: 5 additions & 0 deletions src/app/domain/search/dataproxy-wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// We cannot use `cozy-dataproxy-lib/api` here due to our bundler configuration
// even if it is declared in the package.json file. Instead we should target the
// 'dist' directory.
// In the future we should find a way to homogenize bundlers configuration.
export { SearchEngine } from 'cozy-dataproxy-lib/dist/api'
5 changes: 2 additions & 3 deletions src/app/domain/search/search.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import CozyClient from 'cozy-client'
// We cannot use `cozy-dataproxy-lib/api` here due to our bundler configuration.
// In the future we should find a way to homogenize bundlers configuration.
import { SearchEngine } from 'cozy-dataproxy-lib/dist/api'
import type { SearchOptions } from 'cozy-dataproxy-lib/dist/search/types'
import Minilog from 'cozy-minilog'

import { SearchEngine } from '/app/domain/search/dataproxy-wrapper'

const log = Minilog('📱🗂️ Search')

let searchEngine: SearchEngine | undefined = undefined
Expand Down

0 comments on commit 235beab

Please sign in to comment.