MCPcopy Create free account
hub / github.com/Snapchat/Valdi / TestWorkspace

Class TestWorkspace

compiler/companion/src/cache/CachingWorkspace.spec.ts:21–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21class TestWorkspace implements IWorkspace {
22 initialized: boolean = true;
23 workspaceRoot: string = '/';
24
25 responseHandlers: TestWorkspaceResponseHandler[] = [];
26 private fileManager = new FileManager(this.workspaceRoot);
27 private importPathResolver = new ImportPathResolver(() => {
28 return {};
29 });
30
31 initialize(): void {}
32
33 destroy(): void {}
34
35 registerInMemoryFile(fileName: string, fileContent: string): void {
36 this.importPathResolver.registerAlias(this.fileManager.resolvePath(fileName));
37 }
38
39 registerDiskFile(fileName: string, absoluteDiskPath: string): void {
40 this.importPathResolver.registerAlias(this.fileManager.resolvePath(fileName));
41 }
42
43 resolveImportPath(fromPath: string, toPath: string): string {
44 return this.importPathResolver.resolveImportPath(fromPath, toPath);
45 }
46
47 getFileNameForImportPath(importPath: string): string {
48 return this.importPathResolver.getAlias(this.fileManager.resolvePath(importPath))?.absolutePath ?? importPath;
49 }
50
51 appendNextRequestHandler<T>(method: string, fileName: string, position: number | undefined, response: T): void {
52 this.responseHandlers.push({ method, fileName, position, response });
53 }
54
55 private async handleRequest<T>(method: string, fileName: string, position?: number): Promise<T> {
56 for (let i = 0; i < this.responseHandlers.length; i++) {
57 const responseHandler = this.responseHandlers[i];
58 if (
59 responseHandler.method === method &&
60 responseHandler.fileName === fileName &&
61 responseHandler.position === position
62 ) {
63 const response = responseHandler.response;
64 this.responseHandlers.splice(i, 1);
65 return response as T;
66 }
67 }
68
69 throw new Error(`No request handler for method '${method}' with fileName '${fileName}'`);
70 }
71
72 openFile(fileName: string): Promise<OpenFileResult> {
73 return this.handleRequest<OpenFileResult>('openFile', fileName);
74 }
75
76 emitFile(fileName: string): Promise<EmitResult> {
77 return this.handleRequest<EmitResult>('emitFile', fileName);
78 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected