Skip to content

Commit 1a2a5c1

Browse files
committed
Display tests final results on status bar
1 parent bdd0bf0 commit 1a2a5c1

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/features/commands.ts

+29-4
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,22 @@ export function runTests(server: OmnisharpServer, testType) {
187187

188188
return server.makeRequest<proto.GetTestContextResponse>(proto.GetTestContext, request).then(value => {
189189
let cwd = dirname(activeEditor.document.fileName);
190-
return runCommandInOutputChannel(value.TestCommand, channel, cwd);
190+
return runTestsInOutputChannel(value.TestCommand, channel, cwd);
191191
});
192192
}
193193

194-
export function runCommandInOutputChannel(command: string, channel: OutputChannel, cwd: string): Promise<ChildProcess> {
194+
export function runTestsInOutputChannel(command: string, channel: OutputChannel, cwd: string): Promise<ChildProcess> {
195195

196196
return new Promise<ChildProcess>((resolve, reject) => {
197+
198+
window.setStatusBarMessage("Running tests...");
199+
197200
let args = command.split(" ");
198201
let cmd = args.shift();
199202
let childprocess: ChildProcess;
200203
try {
201204
channel.appendLine("[INFO] Running command: " + command);
202-
childprocess = spawn(cmd, args, { cwd: cwd});
205+
childprocess = spawn(cmd, args, { cwd: cwd });
203206
} catch (e) {
204207
channel.appendLine("[ERROR]" + e);
205208
}
@@ -209,9 +212,31 @@ export function runCommandInOutputChannel(command: string, channel: OutputChanne
209212
});
210213

211214
childprocess.stdout.on('data', (data: NodeBuffer) => {
212-
channel.append(data.toString());
215+
var line = data.toString();
216+
var match = parseTestsResults(line);
217+
if (match.success) {
218+
if (match.errors + match.failures > 0)
219+
channel.show();
220+
221+
window.setStatusBarMessage(line);
222+
}
223+
channel.append(line);
213224
});
214225

215226
resolve(childprocess);
216227
});
228+
}
229+
230+
231+
function parseTestsResults(text: string): any {
232+
233+
const finalResultRegex = /(?:Total|Tests run): \d+, Errors: (\d+), (?:Failed|Failures): (\d+)/i;
234+
235+
var match = text.match(finalResultRegex);
236+
if (match && match.length > 0) {
237+
var errors = parseInt(match[1]);
238+
var failures = parseInt(match[2]);
239+
return { success: true, errors, failures };
240+
}
241+
return { success: false, errors: 0, failures: 0 };
217242
}

0 commit comments

Comments
 (0)