Skip to content

Commit 71f7e98

Browse files
authored
create a FE rpc mock (#3014)
1 parent 6871998 commit 71f7e98

3 files changed

Lines changed: 194 additions & 2 deletions

File tree

cmd/generatets/main-generatets.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ func generateWshClientApiFile(tsTypeMap map[reflect.Type]string) error {
112112
fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n")
113113
fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n")
114114
fmt.Fprintf(&buf, "import { WshClient } from \"./wshclient\";\n\n")
115+
fmt.Fprintf(&buf, "export interface MockRpcClient {\n")
116+
fmt.Fprintf(&buf, " mockWshRpcCall(client: WshClient, command: string, data: any, opts?: RpcOpts): Promise<any>;\n")
117+
fmt.Fprintf(&buf, " mockWshRpcStream(client: WshClient, command: string, data: any, opts?: RpcOpts): AsyncGenerator<any, void, boolean>;\n")
118+
fmt.Fprintf(&buf, "}\n\n")
119+
fmt.Fprintf(&buf, "let mockClient: MockRpcClient = null;\n\n")
120+
fmt.Fprintf(&buf, "export function setMockRpcClient(client: MockRpcClient): void {\n")
121+
fmt.Fprintf(&buf, " mockClient = client;\n")
122+
fmt.Fprintf(&buf, "}\n\n")
115123
orderedKeys := utilfn.GetOrderedMapKeys(declMap)
116124
fmt.Fprintf(&buf, "// WshServerCommandToDeclMap\n")
117125
fmt.Fprintf(&buf, "class RpcApiType {\n")

0 commit comments

Comments
 (0)