Create initial server layout (#11)
* Create initial server layout * Adjust command name to entry * Add @oclif/config as dependency * Implement build process for outputting single binary * Add init message * Remove unused import, add tsconfig.json to .gitignore * Accidently pushed wacky change to output host FS files * Add options to createApp
This commit is contained in:
@ -1,27 +1,28 @@
|
||||
import { Emitter } from "@coder/events";
|
||||
import { Client } from "../src/browser/client";
|
||||
import { Server } from "../src/node/server";
|
||||
import { Server, ServerOptions } from "../src/node/server";
|
||||
|
||||
export const createClient = (): Client => {
|
||||
export const createClient = (serverOptions?: ServerOptions): Client => {
|
||||
const s2c = new Emitter<Uint8Array | Buffer>();
|
||||
const c2s = new Emitter<Uint8Array | Buffer>();
|
||||
|
||||
// tslint:disable-next-line
|
||||
new Server({
|
||||
close: () => undefined,
|
||||
onClose: () => undefined,
|
||||
onMessage: (cb) => {
|
||||
close: (): void => undefined,
|
||||
onClose: (): void => undefined,
|
||||
onMessage: (cb): void => {
|
||||
c2s.event((d) => cb(d));
|
||||
},
|
||||
send: (data) => setTimeout(() => s2c.emit(data), 0),
|
||||
});
|
||||
send: (data): NodeJS.Timer => setTimeout(() => s2c.emit(data), 0),
|
||||
}, serverOptions);
|
||||
|
||||
const client = new Client({
|
||||
close: () => undefined,
|
||||
onClose: () => undefined,
|
||||
onMessage: (cb) => {
|
||||
close: (): void => undefined,
|
||||
onClose: (): void => undefined,
|
||||
onMessage: (cb): void => {
|
||||
s2c.event((d) => cb(d));
|
||||
},
|
||||
send: (data) => setTimeout(() => c2s.emit(data), 0),
|
||||
send: (data): NodeJS.Timer => setTimeout(() => c2s.emit(data), 0),
|
||||
});
|
||||
|
||||
return client;
|
||||
|
18
packages/protocol/test/server.test.ts
Normal file
18
packages/protocol/test/server.test.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { createClient } from "./helpers";
|
||||
|
||||
describe("Server", () => {
|
||||
const dataDirectory = "/tmp/example";
|
||||
const workingDirectory = "/working/dir";
|
||||
const client = createClient({
|
||||
dataDirectory,
|
||||
workingDirectory,
|
||||
});
|
||||
|
||||
it("should get init msg", (done) => {
|
||||
client.onInitData((data) => {
|
||||
expect(data.dataDirectory).toEqual(dataDirectory);
|
||||
expect(data.workingDirectory).toEqual(workingDirectory);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user