Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testsupport] - Add support for client-side verbose logs #224

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testSupport/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions testSupport/src/debugClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,26 @@ export class DebugClient extends ProtocolClient {
this._adapterProcess = cp.spawn(this._runtime, [ this._executable ], this._spawnOptions);
const sanitize = (s: string) => s.toString().replace(/\r?\n$/mg, '');
this._adapterProcess.stderr.on('data', (data: string) => {
this.log(`adapter - incoming data on stderr`);
if (this._enableStderr) {
console.log(sanitize(data));
console.log(`adapter stderr: ${sanitize(data)}`);
}
});

this._adapterProcess.on('error', (err) => {
console.log(err);
this.log(`adapter - error: ${err}`);
reject(err);
});

this._adapterProcess.on('exit', (code: number, signal: string) => {
this.log(`adapter - exit (code ${code}, signal ${signal})`);
if (code) {
// done(new Error('debug adapter exit code: ' + code));
}
});

this.connect(this._adapterProcess.stdout, this._adapterProcess.stdin);
this.log(`spawned debug adapter process successfully - runtime:${this._runtime}, executable:${this._executable}`);
resolve();
}
});
Expand Down
15 changes: 15 additions & 0 deletions testSupport/src/protocolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ProtocolClient extends ee.EventEmitter {
private pendingRequests = new Map<number, (e: DebugProtocol.Response) => void>();
private rawData = new Buffer(0);
private contentLength: number;
protected verboseOutput = false;

constructor() {
super();
Expand All @@ -32,6 +33,16 @@ export class ProtocolClient extends ee.EventEmitter {
});
}

protected log(msg: string) {
if (this.verboseOutput) {
console.log(msg);
}
}

public setVerboseLog(value: boolean) {
this.verboseOutput = value;
}

public send(command: 'initialize', args: DebugProtocol.InitializeRequestArguments) : Promise<DebugProtocol.InitializeResponse>;
public send(command: 'configurationDone', args: DebugProtocol.ConfigurationDoneArguments) : Promise<DebugProtocol.ConfigurationDoneResponse>;
public send(command: 'launch', args: DebugProtocol.LaunchRequestArguments) : Promise<DebugProtocol.LaunchResponse>;
Expand Down Expand Up @@ -69,10 +80,13 @@ export class ProtocolClient extends ee.EventEmitter {
public send(command: string, args?: any): Promise<DebugProtocol.Response> {

return new Promise((completeDispatch, errorDispatch) => {
this.log(`send call on '${command}' command`)
this.doSend(command, args, (result: DebugProtocol.Response) => {
if (result.success) {
this.log(`send '${command}' call success`);
completeDispatch(result);
} else {
this.log(`send '${command}' call error: ${result.message}`)
errorDispatch(new Error(result.message));
}
});
Expand All @@ -94,6 +108,7 @@ export class ProtocolClient extends ee.EventEmitter {
this.pendingRequests.set(request.seq, clb);

const json = JSON.stringify(request);
this.log(`doSend: begin write on stream - events:${JSON.stringify(this.outputStream.eventNames())}, listeners:${JSON.stringify(this.outputStream.listeners)}'`);
this.outputStream.write(`Content-Length: ${Buffer.byteLength(json, 'utf8')}\r\n\r\n${json}`, 'utf8');
}

Expand Down