1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-29 05:35:25 +00:00
code-server-2/packages/server/test/helpers.ts

29 lines
682 B
TypeScript
Raw Normal View History

2019-01-11 19:33:44 +00:00
import { Emitter } from "@coder/events";
import { Client } from "../src/browser/client";
import { Server } from "../src/node/server";
export const createClient = (): Client => {
2019-01-11 19:58:31 +00:00
const s2c = new Emitter<Uint8Array | Buffer>();
const c2s = new Emitter<Uint8Array | Buffer>();
2019-01-11 19:33:44 +00:00
2019-01-11 19:58:31 +00:00
new Server({
close: () => undefined,
onClose: () => undefined,
onMessage: (cb) => {
c2s.event((d) => cb(d));
},
send: (data) => setTimeout(() => s2c.emit(data), 0),
});
2019-01-11 19:33:44 +00:00
2019-01-11 19:58:31 +00:00
const client = new Client({
close: () => undefined,
onClose: () => undefined,
onMessage: (cb) => {
s2c.event((d) => cb(d));
},
send: (data) => setTimeout(() => c2s.emit(data), 0),
});
2019-01-11 19:33:44 +00:00
2019-01-11 19:58:31 +00:00
return client;
2019-01-11 19:33:44 +00:00
};