WRITE UNIT TESTS!!!
first async command working, no unit tests done AGAING
This commit is contained in:
+19
-7
@@ -14,6 +14,7 @@ export class Process {
|
||||
private _StdoutChunks: Uint8Array[] = [];
|
||||
private _StderrChunks: Uint8Array[] = [];
|
||||
private _Settled: boolean = false;
|
||||
private _EventEmitter: EventEmitter<ShellEventMap>;
|
||||
private readonly _MaxChunkByteSize: number;
|
||||
|
||||
readonly PID: number;
|
||||
@@ -21,7 +22,6 @@ export class Process {
|
||||
readonly State: ShellState;
|
||||
readonly Args: string[];
|
||||
readonly Flags: string[];
|
||||
EventEmitter: EventEmitter<ShellEventMap>;
|
||||
|
||||
constructor(pid: number, state: ShellState, descriptor: CommandDescriptor, flags: string[], args: string[]) {
|
||||
this.PID = pid;
|
||||
@@ -31,7 +31,7 @@ export class Process {
|
||||
this.Args = args;
|
||||
// Check if positive later and throw an error if so
|
||||
this._MaxChunkByteSize = 1024;
|
||||
this.EventEmitter = new EventEmitter<ShellEventMap>();
|
||||
this._EventEmitter = new EventEmitter<ShellEventMap>();
|
||||
}
|
||||
|
||||
private concatUint8Arrays(arrays: Uint8Array[]): Uint8Array {
|
||||
@@ -67,13 +67,13 @@ export class Process {
|
||||
|
||||
if (data.length <= this._MaxChunkByteSize) {
|
||||
chunks.push(data);
|
||||
this.EventEmitter.emit(eventType, { pid: this.PID, data });
|
||||
this._EventEmitter.emit(eventType, { pid: this.PID, data });
|
||||
return;
|
||||
} else {
|
||||
const arr = this.divideToChunks(data);
|
||||
for (const ent of arr) {
|
||||
chunks.push(ent);
|
||||
this.EventEmitter.emit(eventType, { pid: this.PID, data: ent });
|
||||
this._EventEmitter.emit(eventType, { pid: this.PID, data: ent });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ export class Process {
|
||||
};
|
||||
}
|
||||
|
||||
this.EventEmitter.emit("result", { pid: this.PID, result, state: output.state });
|
||||
this._EventEmitter.emit("result", { pid: this.PID, result, state: output.state });
|
||||
this._Settled = true;
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -137,7 +137,7 @@ export class Process {
|
||||
},
|
||||
);
|
||||
|
||||
this.EventEmitter.emit("result", { pid: this.PID, result, state: this.State });
|
||||
this._EventEmitter.emit("result", { pid: this.PID, result, state: this.State });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ export class Process {
|
||||
this.CommandDescriptor.name,
|
||||
);
|
||||
|
||||
this.EventEmitter.emit("result", { pid: this.PID, result, state: this.State });
|
||||
this._EventEmitter.emit("result", { pid: this.PID, result, state: this.State });
|
||||
return;
|
||||
} else {
|
||||
if (this._SignalHandler !== null) {
|
||||
@@ -172,4 +172,16 @@ export class Process {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public on<K extends keyof ShellEventMap>(type: K, handler: (payload: ShellEventMap[K]) => void): () => void {
|
||||
return this._EventEmitter.on(type, handler);
|
||||
}
|
||||
|
||||
public once<K extends keyof ShellEventMap>(type: K, handler: (payload: ShellEventMap[K]) => void): () => void {
|
||||
return this._EventEmitter.once(type, handler);
|
||||
}
|
||||
|
||||
public off<K extends keyof ShellEventMap>(type: K, handler: (payload: ShellEventMap[K]) => void): void {
|
||||
this._EventEmitter.off(type, handler);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user