Skip to content

Commit

Permalink
Ensure fake-indexeddb isn't included in BG script
Browse files Browse the repository at this point in the history
  • Loading branch information
poltak committed Feb 27, 2024
1 parent dc133b1 commit 4d05c39
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/content-sharing/background/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import * as data from './index.test.data'
import { BackgroundIntegrationTestSetupOpts } from 'src/tests/background-integration-tests'
import { StorageHooksChangeWatcher } from '@worldbrain/memex-common/lib/storage/hooks'
import { createMemoryServerStorage } from 'src/storage/server'
import { createMemoryServerStorage } from 'src/storage/server.tests'
import { FakeFetch } from 'src/util/tests/fake-fetch'
import { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types'
import { SharingTestHelper } from './index.tests'
Expand Down
2 changes: 1 addition & 1 deletion src/discord/event-processor.test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import flatten from 'lodash/flatten'
import expect from 'expect'
import { createDiscordEventProcessor } from '@worldbrain/memex-common/lib/discord/event-processor'
import { DiscordChannelManager } from '@worldbrain/memex-common/lib/discord/channel-manager'
import { createMemoryServerStorage } from 'src/storage/server'
import { createMemoryServerStorage } from 'src/storage/server.tests'
import type { DiscordMessageCreateInfo } from '@worldbrain/memex-common/lib/discord/types'
import { extractListShareUrlParts } from 'src/content-sharing/utils'

Expand Down
24 changes: 19 additions & 5 deletions src/storage/server.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { FirestoreStorageBackend } from '@worldbrain/storex-backend-firestore'
import { initializeTestEnvironment } from '@firebase/rules-unit-testing'
import { documentId, Timestamp, serverTimestamp } from '@firebase/firestore'
import type { ServerStorage } from './types'
import {
createMemoryServerStorage,
createStorageManager,
createServerStorage,
} from './server'
import { createStorageManager, createServerStorage } from './server'
import { DexieStorageBackend } from '@worldbrain/storex-backend-dexie'
import inMemory from '@worldbrain/storex-backend-dexie/lib/in-memory'

async function createFirestoreEmulatorStorageBackend(options: {
firebaseProjectId?: string
Expand Down Expand Up @@ -81,3 +79,19 @@ export async function createTestServerStorage(options: {
return createMemoryServerStorage(options)
}
}

export function createMemoryServerStorage(options?: {
setupMiddleware?(manager: StorageManager): StorageMiddleware[]
}): Promise<ServerStorage> {
const backend = new DexieStorageBackend({
dbName: 'server',
idbImplementation: inMemory(),
legacyMemexCompatibility: true,
})
const storageManager = createStorageManager(backend, options)

return createServerStorage(storageManager, {
autoPkType: 'number',
skipApplicationLayer: true,
})
}
18 changes: 0 additions & 18 deletions src/storage/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { SharedSyncLogStorage } from '@worldbrain/storex-sync/lib/shared-sync-lo
import UserStorage from '@worldbrain/memex-common/lib/user-management/storage'
import { ALLOWED_STORAGE_MODULE_OPERATIONS } from '@worldbrain/memex-common/lib/firebase-backend/app-layer/allowed-operations'
import { createClientApplicationLayer } from '@worldbrain/memex-common/lib/firebase-backend/app-layer/client'
import { DexieStorageBackend } from '@worldbrain/storex-backend-dexie'
import inMemory from '@worldbrain/storex-backend-dexie/lib/in-memory'
import { ContentSharingStorage } from 'src/content-sharing/background/storage'
import type { ServerStorage } from './types'
import ContentConversationStorage from '@worldbrain/memex-common/lib/content-conversations/storage'
Expand Down Expand Up @@ -144,22 +142,6 @@ export async function createServerStorage(
return serverStorage
}

export function createMemoryServerStorage(options?: {
setupMiddleware?(manager: StorageManager): StorageMiddleware[]
}): Promise<ServerStorage> {
const backend = new DexieStorageBackend({
dbName: 'server',
idbImplementation: inMemory(),
legacyMemexCompatibility: true,
})
const storageManager = createStorageManager(backend, options)

return createServerStorage(storageManager, {
autoPkType: 'number',
skipApplicationLayer: true,
})
}

export function createStorageManager(
backend: StorageBackend,
options?: {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/background-integration-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { MemorySubscriptionsService } from '@worldbrain/memex-common/lib/subscri
import { FakeAnalytics } from 'src/analytics/mock'
import AnalyticsManager from 'src/analytics/analytics'
import { setStorageMiddleware } from 'src/storage/middleware'
import { createMemoryServerStorage } from 'src/storage/server'
import { createMemoryServerStorage } from 'src/storage/server.tests'
import { ServerStorage } from 'src/storage/types'
import { Browser } from 'webextension-polyfill'
import { createServices } from 'src/services'
Expand Down

0 comments on commit 4d05c39

Please sign in to comment.