Skip to content

Commit 119f609

Browse files
committed
fix tests
1 parent 58fff3f commit 119f609

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

packages/editor/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@
116116
"test-watch": "vitest watch",
117117
"unittest:vitest": "vitest",
118118
"unittest:playwright": "playwright-test '**/*.browsertest.ts'",
119-
"test": "npm run unittest:playwright",
120-
"testFIXME": "npm run unittest:vitest",
119+
"test": "npm run unittest:vitest && npm run unittest:playwright",
121120
"vite:dev": "vite",
122121
"vite:build": "vite build --mode=$MODE",
123122
"vite:preview": "vite preview",

packages/editor/src/store/BaseResource.test.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { enableMobxBindings } from "@syncedstore/yjs-reactive-bindings";
66
import * as mobx from "mobx";
77
import { beforeEach, describe, expect, it } from "vitest";
8-
import { uri } from "vscode-lib";
8+
import { async, uri } from "vscode-lib";
99
import * as Y from "yjs";
1010
import { Identifier } from "../identifiers/Identifier";
1111
import {
@@ -76,7 +76,7 @@ function createDocAndAllowAccess(forUsers: User[], docId: DocId) {
7676
const resourceAsInbox = inboxBaseResource.getSpecificType<InboxResource>(
7777
InboxResource as any
7878
);
79-
resourceAsInbox.inboxTarget = docId;
79+
resourceAsInbox.inboxTarget = "test:test/" + docId;
8080
user.docs[docId + "-inbox"] = {
8181
resourceAsInbox,
8282
resource: inboxBaseResource,
@@ -86,24 +86,27 @@ function createDocAndAllowAccess(forUsers: User[], docId: DocId) {
8686

8787
// create main doc
8888
const ydoc = new Y.Doc();
89-
const resource = new BaseResource(ydoc, new TestIdentifier(docId), {
90-
...UnimplementedBaseResourceExternalManager,
91-
loadInboxResource: async (id) => {
92-
const testIdentifier = new TestIdentifier(id.toString());
93-
const inbox = user.docs[testIdentifier.id + "-inbox"].resourceAsInbox;
89+
const manager: any = {
90+
loadInboxResource: async (id: TestIdentifier) => {
91+
// const testIdentifier = new TestIdentifier(id.toString());
92+
const inbox = user.docs[id.id + "-inbox"].resourceAsInbox;
9493
if (!inbox) {
9594
throw new Error("can't resolve inbox id " + id);
9695
}
9796
return inbox;
9897
},
99-
});
98+
};
99+
manager.prototype = UnimplementedBaseResourceExternalManager;
100+
const resource = new BaseResource(ydoc, new TestIdentifier(docId), manager);
100101

101102
const validator = new InboxValidator(
102103
resourceAsInbox!,
103104
ChildReference,
104-
async (identifier) => {
105-
const testIdentifier = identifier.uri.path.substring(1);
106-
return user.docs[testIdentifier].resource;
105+
async (idStr) => {
106+
// hacky
107+
const testIdentifier = uri.URI.parse(idStr.replace("test:", "test://"));
108+
const docId = testIdentifier.path.substring(1);
109+
return user.docs[docId].resource;
107110
}
108111
);
109112

@@ -158,7 +161,7 @@ describe("links", () => {
158161
expect(user2.docs.doc1.ydoc.getMap("test").get("hello")).toBeUndefined();
159162
});
160163

161-
it.only("adds a ref", async () => {
164+
it("adds a ref", async () => {
162165
createDocAndAllowAccess([user1, user2], "doc1");
163166
createDocAndAllowAccess([user1, user2], "doc2");
164167

@@ -174,6 +177,8 @@ describe("links", () => {
174177

175178
await new Promise((resolve) => setImmediate(resolve)); // allow autorun to fire
176179

180+
await async.timeout(100);
181+
177182
expect(user1.docs.doc2.validator!.validRefMessages.length).toBe(1);
178183
expect(user2.docs.doc2.validator!.validRefMessages.length).toBe(0);
179184

packages/editor/src/store/InboxValidatorStore.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { autorun } from "mobx";
22
import { lifecycle } from "vscode-lib";
33
import * as Y from "yjs";
4-
import { parseIdentifier } from "../identifiers";
5-
import { Identifier } from "../identifiers/Identifier";
64
import { UnreachableCaseError } from "../util/UnreachableCaseError";
75
import { BaseResource } from "./BaseResource";
86
import { InboxResource, RefInboxMessage } from "./InboxResource";
@@ -49,7 +47,7 @@ export class InboxValidator<
4947
constructor(
5048
private readonly inbox: InboxResource,
5149
private referenceDefinition: T,
52-
loader: (identifier: Identifier) => Promise<BaseResource>
50+
loader: (idString: string) => Promise<BaseResource>
5351
) {
5452
super();
5553
const dispose = autorun(() => {
@@ -61,7 +59,7 @@ export class InboxValidator<
6159
this.seenMessages.add(message.id);
6260
this.pendingMessages.add(message.id);
6361

64-
const resource = await loader(parseIdentifier(message.source));
62+
const resource = await loader(message.source);
6563
const handler = () => {
6664
this.updateMessageStateFromResource(message, resource);
6765
};
@@ -130,7 +128,7 @@ export class InboxValidator<
130128
const state = Y.getState(resource.ydoc.store, clientNum);
131129
if (state < clockNum) {
132130
// we need to wait for the document to be updated
133-
// console.log("wait");
131+
console.log("wait");
134132
return "wait";
135133
}
136134

@@ -139,10 +137,10 @@ export class InboxValidator<
139137
this.inbox.inboxTarget
140138
);
141139
if (!ref || ref.target !== this.inbox.inboxTarget) {
142-
// console.log("invalid");
140+
// console.log("invalid", ref?.target, this.inbox.inboxTarget);
143141
return false;
144142
}
145-
// console.log("valid");
143+
// console.log("valid", ref.target, this.inbox.inboxTarget);
146144
return true;
147145
}
148146

0 commit comments

Comments
 (0)