Archived
1
0

Move and refactor fs tests

This commit is contained in:
Asher
2019-02-19 14:21:04 -06:00
parent 2889b3fede
commit d80f82ab98
11 changed files with 726 additions and 682 deletions

View File

@ -7,7 +7,7 @@ import { retry } from "../retry";
* A connection based on a web socket. Automatically reconnects and buffers
* messages during connection.
*/
class Connection implements ReadWriteConnection {
class WebsocketConnection implements ReadWriteConnection {
private activeSocket: WebSocket | undefined;
private readonly messageBuffer = <Uint8Array[]>[];
private readonly socketTimeoutDelay = 60 * 1000;
@ -129,4 +129,4 @@ class Connection implements ReadWriteConnection {
}
// Global instance so all fills can use the same client.
export const client = new Client(new Connection());
export const client = new Client(new WebsocketConnection());

View File

@ -116,7 +116,7 @@ class FS {
const ae = this.client.run((ae, path, options) => {
const fs = __non_webpack_require__("fs") as typeof import("fs");
const str = fs.createWriteStream(path, options);
ae.on("write", (d) => str.write(_Buffer.from(d, "utf8")));
ae.on("write", (d: string) => str.write(_Buffer.from(d, "utf8")));
ae.on("close", () => str.close());
str.on("close", () => ae.emit("close"));
str.on("open", (fd) => ae.emit("open", fd));
@ -141,7 +141,7 @@ class FS {
},
});
ae.on("open", (a) => this.emit("open", a));
ae.on("open", (fd: number) => this.emit("open", fd));
ae.on("close", () => this.emit("close"));
}
@ -597,7 +597,15 @@ class FS {
});
}
public write = <TBuffer extends Buffer | Uint8Array>(fd: number, buffer: TBuffer, offset: number | undefined, length: number | undefined, position: number | undefined | ((err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void), callback?: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void): void => {
public write = <TBuffer extends Buffer | Uint8Array>(fd: number, buffer: TBuffer, offset: number | undefined | ((err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void), length: number | undefined | ((err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void), position: number | undefined | ((err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void), callback?: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void): void => {
if (typeof offset === "function") {
callback = offset;
offset = undefined;
}
if (typeof length === "function") {
callback = length;
length = undefined;
}
if (typeof position === "function") {
callback = position;
position = undefined;
@ -662,9 +670,9 @@ class FS {
return new class Watcher extends EventEmitter implements fs.FSWatcher {
public constructor() {
super();
ae.on("change", (event, filename) => this.emit("change", event, filename));
ae.on("error", (error) => this.emit("error", error));
ae.on("listener", (event, filename) => listener && listener(event, filename));
ae.on("change", (event: string, filename: string) => this.emit("change", event, filename));
ae.on("error", (error: Error) => this.emit("error", error));
ae.on("listener", (event: string, filename: string) => listener && listener(event, filename));
}
public close(): void {