Skip to content

Commit

Permalink
fix tests maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjg committed Jul 23, 2024
1 parent 752ff6c commit b6d70fc
Show file tree
Hide file tree
Showing 4 changed files with 6,644 additions and 5,283 deletions.
5 changes: 2 additions & 3 deletions packages/automerge-repo/src/Repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ export class Repo extends EventEmitter<RepoEvents> {
})
})

if (this.networkSubsystem.isReady()) {
handle.request()
} else {
if (!this.networkSubsystem.isReady()) {
handle.awaitNetwork()
this.networkSubsystem
.whenReady()
Expand Down Expand Up @@ -547,6 +545,7 @@ export class Repo extends EventEmitter<RepoEvents> {
return this.storageSubsystem!.saveDoc(handle.documentId, doc)
})
)
return
}
}

Expand Down
32 changes: 22 additions & 10 deletions packages/automerge-repo/test/Repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ describe("Repo", () => {
storage: storageAdapter,
})

await repo.flush()

const bobHandle = repo2.find<TestDoc>(handle.url)
await bobHandle.whenReady()
assert.equal(bobHandle.isReady(), true)
Expand All @@ -268,7 +270,7 @@ describe("Repo", () => {

assert.equal(handle.isReady(), true)

await pause(150)
await repo.flush()

const repo2 = new Repo({
storage: storageAdapter,
Expand Down Expand Up @@ -420,9 +422,17 @@ describe("Repo", () => {
})
}

await repo.flush()

const storageKeyTypes = storageAdapter.keys().map(k => k.split(".")[1])
const storedSnapshotCount = storageKeyTypes.filter(k => k === "snapshot").length
assert.equal(storedSnapshotCount, 1, `found ${storedSnapshotCount} snapshots in storage instead of 1`)
const storedSnapshotCount = storageKeyTypes.filter(
k => k === "snapshot"
).length
assert.equal(
storedSnapshotCount,
1,
`found ${storedSnapshotCount} snapshots in storage instead of 1`
)
})

it("can import an existing document", async () => {
Expand Down Expand Up @@ -474,8 +484,8 @@ describe("Repo", () => {
let resume = (documentIds?: DocumentId[]) => {
const savesToUnblock = documentIds
? Array.from(blockedSaves).filter(({ path }) =>
documentIds.some(documentId => path.includes(documentId))
)
documentIds.some(documentId => path.includes(documentId))
)
: Array.from(blockedSaves)
savesToUnblock.forEach(({ resolve }) => resolve())
}
Expand Down Expand Up @@ -946,6 +956,7 @@ describe("Repo", () => {
})
const unsyncedHandle = isolatedRepo.create<TestDoc>()
const url = unsyncedHandle.url
await isolatedRepo.flush()

// Now create a message channel to connect two repos
const abChannel = new MessageChannel()
Expand Down Expand Up @@ -1012,9 +1023,9 @@ describe("Repo", () => {
const doc =
Math.random() < 0.5
? // heads, create a new doc
repo.create<TestDoc>()
repo.create<TestDoc>()
: // tails, pick a random doc
(getRandomItem(docs) as DocHandle<TestDoc>)
(getRandomItem(docs) as DocHandle<TestDoc>)

// make sure the doc is ready
if (!doc.isReady()) {
Expand Down Expand Up @@ -1129,9 +1140,11 @@ describe("Repo", () => {
})
await pause(500)

// repo has no stored sync state for charlie so we should see 3 sync messages
// repo has no stored sync state for charlie so we should see 2 sync messages
assert.strictEqual(bobSyncMessages, 3)

await bobRepo.flush()

// setup new repo which uses bob's storage
const bob2Repo = new Repo({
storage: bobStorage,
Expand Down Expand Up @@ -1242,7 +1255,6 @@ describe("Repo", () => {
aliceDoc.change((doc: any) => (doc.text = "Hello world"))

const bobDoc = bobRepo.find(aliceDoc.url)
bobDoc.unavailable()
await eventPromise(bobDoc, "unavailable")

aliceAdapter.peerCandidate(bob)
Expand Down Expand Up @@ -1396,7 +1408,7 @@ describe("Repo", () => {
})

const warn = console.warn
const NO_OP = () => {}
const NO_OP = () => { }

const disableConsoleWarn = () => {
console.warn = NO_OP
Expand Down
Loading

0 comments on commit b6d70fc

Please sign in to comment.