digidem / mapeo-core-next

The upcoming version of Mapeo Core
MIT License
7 stars 1 forks source link

chore: add `createPersistentProject` helper for e2e tests #580

Closed tomasciccola closed 2 months ago

tomasciccola commented 2 months ago

This would help with testing with stuff related to persitent storage.

the function needs a path, and creates a project when run the first time. It will also saved the created projectId on a file in the passed path. On subsequent runs it will load the projectId from the path

gmaclennan commented 2 months ago

I'm not sure this is quite the right abstraction for the testing needs. It repeats code in other helpers there's not an easy way to use it for invitees. Also we don't need to persist the projectId to disk for tests, we just need to persist it between instances of Manager. How about modifying the existing createManager function to accept dbFolder and coreStorage options, then you can use it like this in a test (psuedo code):

const createRAM = RAM.reusable()
const dbFolder = createTempDir()
const seed = randomBytes(16)

const manager = createManager({ seed, dbFolder, coreStorage: createRAM })
const projectId = manager.createProject({ name })
const project = manager.getProject(projectId)

// add some data to the project

project.close()
manager.close()

const newManager = createManager({ seed, dbFolder, coreStorage: createRAM })
const project = manager.getProject(projectId)

// check the data added to the project above is in the project (e.g. data is persisted)
EvanHahn commented 2 months ago

See #581 for an alternate (weird) approach.

tomasciccola commented 2 months ago

Yeah, I think your approach gregor is the more straight away (I was actually doing it that way but somehow was suspicious that calling project.close() wouldn't be enough...), I kinda went with that approach on the last commit

tomasciccola commented 2 months ago

closing this PR in favor or #581