Working setup
This commit is contained in:
parent
e3a90833ff
commit
2dfb8b71e5
1 changed files with 460 additions and 319 deletions
|
|
@ -64,7 +64,8 @@ export class MockClient implements FileSystemOperations {
|
|||
|
||||
public async create(
|
||||
path: RelativePath,
|
||||
newContent: Uint8Array
|
||||
newContent: Uint8Array,
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = { ignoreSlowFileEvents: false }
|
||||
): Promise<void> {
|
||||
if (this.localFiles.has(path)) {
|
||||
throw new Error(`File ${path} already exists`);
|
||||
|
|
@ -74,9 +75,9 @@ export class MockClient implements FileSystemOperations {
|
|||
);
|
||||
this.localFiles.set(path, newContent);
|
||||
|
||||
this.executeFileOperation(async () =>
|
||||
this.executeFileOperation((async () =>
|
||||
this.client.syncLocallyCreatedFile(path)
|
||||
);
|
||||
), ignoreSlowFileEvents);
|
||||
}
|
||||
|
||||
public async createDirectory(_path: RelativePath): Promise<void> {
|
||||
|
|
@ -85,7 +86,8 @@ export class MockClient implements FileSystemOperations {
|
|||
|
||||
public async atomicUpdateText(
|
||||
path: RelativePath,
|
||||
updater: (currentContent: TextWithCursors) => TextWithCursors
|
||||
updater: (currentContent: TextWithCursors) => TextWithCursors,
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = { ignoreSlowFileEvents: false }
|
||||
): Promise<string> {
|
||||
const file = this.localFiles.get(path);
|
||||
if (!file) {
|
||||
|
|
@ -102,13 +104,13 @@ export class MockClient implements FileSystemOperations {
|
|||
.map((part) => part.trim());
|
||||
const newParts = newContent.split(" ").map((part) => part.trim());
|
||||
existingParts.forEach((part) =>
|
||||
// all changes should be additive
|
||||
{
|
||||
assert(
|
||||
newParts.includes(part),
|
||||
`Part ${part} not found in new content: ${newContent}`
|
||||
);
|
||||
}
|
||||
// all changes should be additive
|
||||
{
|
||||
assert(
|
||||
newParts.includes(part),
|
||||
`Part ${part} not found in new content: ${newContent}`
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -116,11 +118,11 @@ export class MockClient implements FileSystemOperations {
|
|||
`Updated file ${path} with:\n current content: ${currentContent}\n new content: ${newContent}`
|
||||
);
|
||||
|
||||
this.executeFileOperation(async () =>
|
||||
this.executeFileOperation((async () =>
|
||||
this.client.syncLocallyUpdatedFile({
|
||||
relativePath: path
|
||||
})
|
||||
);
|
||||
), ignoreSlowFileEvents);
|
||||
|
||||
return newContent;
|
||||
}
|
||||
|
|
@ -144,20 +146,21 @@ export class MockClient implements FileSystemOperations {
|
|||
});
|
||||
}
|
||||
|
||||
public async delete(path: RelativePath): Promise<void> {
|
||||
public async delete(path: RelativePath, { ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = { ignoreSlowFileEvents: false }): Promise<void> {
|
||||
this.client.logger.info(
|
||||
`Deleting file: ${path} with:\n content ${new TextDecoder().decode(this.localFiles.get(path))}`
|
||||
);
|
||||
this.localFiles.delete(path);
|
||||
|
||||
this.executeFileOperation(async () =>
|
||||
this.executeFileOperation((async () =>
|
||||
this.client.syncLocallyDeletedFile(path)
|
||||
);
|
||||
), ignoreSlowFileEvents);
|
||||
}
|
||||
|
||||
public async rename(
|
||||
oldPath: RelativePath,
|
||||
newPath: RelativePath
|
||||
newPath: RelativePath,
|
||||
{ ignoreSlowFileEvents }: { ignoreSlowFileEvents: boolean } = { ignoreSlowFileEvents: false }
|
||||
): Promise<void> {
|
||||
const file = this.localFiles.get(oldPath);
|
||||
if (!file) {
|
||||
|
|
@ -172,16 +175,16 @@ export class MockClient implements FileSystemOperations {
|
|||
`Renamed file: ${oldPath} -> ${newPath} with:\n content ${new TextDecoder().decode(file)}`
|
||||
);
|
||||
|
||||
this.executeFileOperation(async () =>
|
||||
this.executeFileOperation((async () =>
|
||||
this.client.syncLocallyUpdatedFile({
|
||||
oldPath,
|
||||
relativePath: newPath
|
||||
})
|
||||
);
|
||||
), ignoreSlowFileEvents);
|
||||
}
|
||||
|
||||
private executeFileOperation(callback: () => unknown): void {
|
||||
if (this.useSlowFileEvents) {
|
||||
private executeFileOperation(callback: () => unknown, ignoreSlowFileEvents: boolean = false): void {
|
||||
if (this.useSlowFileEvents && !ignoreSlowFileEvents) {
|
||||
// we aren't the best client and it takes some time to notice changes
|
||||
setTimeout(callback, Math.random() * 100);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue