Skip to content

Commit

Permalink
fix: Attach output to running test (#137)
Browse files Browse the repository at this point in the history
Co-authored-by: Danielku15 <[email protected]>
  • Loading branch information
muhammadyusuf-kurbonov and Danielku15 authored Sep 13, 2024
1 parent 0cc5a2f commit a4f818e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class TestRunner {
private readonly env: ConfigValue<Record<string, string>>,
) {}

private currentRunningTest?: vscode.TestItem;

public makeHandler(
ctrl: vscode.TestController,
config: ConfigurationFile,
Expand All @@ -68,12 +70,12 @@ export class TestRunner {
let ranAnyTest = false;
let isOutsideTestRun = true;
const outputQueue = new OutputQueue();
const enqueueLine = (line: string) => {
const enqueueLine = (line: string, testItem?: vscode.TestItem) => {
// vscode can log some preamble as it boots: grey those out
if (isOutsideTestRun) {
line = `${styles.dim.open}${line}${styles.dim.close}`;
}
outputQueue.enqueue(() => run.appendOutput(`${line}\r\n`));
outputQueue.enqueue(() => run.appendOutput(`${line}\r\n`, undefined, testItem));
};

const spawnCts = new vscode.CancellationTokenSource();
Expand All @@ -88,7 +90,7 @@ export class TestRunner {
parsed = JSON.parse(line);
} catch {
// just normal output
enqueueLine(line);
enqueueLine(line, this.currentRunningTest);
return;
}
switch (parsed[0]) {
Expand All @@ -98,7 +100,10 @@ export class TestRunner {
case MochaEvent.TestStart: {
const { file, path } = parsed[1];
const test = compiledFileTests.lookup(file, path);
if (test) run.started(test);
if (test) {
this.currentRunningTest = test;
run.started(test);
}
break;
}
case MochaEvent.SuiteStart: {
Expand All @@ -115,13 +120,15 @@ export class TestRunner {
case MochaEvent.Pass: {
ranAnyTest = true;
const { file, path, duration } = parsed[1];
const test = compiledFileTests.lookup(file, path);
enqueueLine(
`${' '.repeat(path.length - 1)}${styles.green.open}${styles.green.close}${
path[path.length - 1]
}`,
test,
);
const test = compiledFileTests.lookup(file, path);
if (test) {
this.currentRunningTest = undefined;
run.passed(test, duration);
leafTests.delete(test);
}
Expand All @@ -136,6 +143,7 @@ export class TestRunner {
`${' '.repeat(path.length - 1)}${styles.red.open} x ${path.join(' ')}${
styles.red.close
}`,
tcase,
);
const rawErr = stack || err;

Expand Down Expand Up @@ -184,6 +192,7 @@ export class TestRunner {
}

message.location = location ?? testFirstLine;
this.currentRunningTest = undefined;
run.failed(tcase, message, duration);
});
break;
Expand All @@ -193,7 +202,9 @@ export class TestRunner {
break;
default:
// just normal output
outputQueue.enqueue(() => run.appendOutput(`${line}\r\n`));
outputQueue.enqueue(() =>
run.appendOutput(`${line}\r\n`, undefined, this.currentRunningTest),
);
}
},
token: spawnCts.token,
Expand Down Expand Up @@ -610,7 +621,7 @@ async function replaceAllLocations(store: SourceMapStore, str: string, workingDi
output.push(
locationPromise.then((location) =>
location
? `${location.uri}:${location.range.start.line + 1}:${location.range.start.character + 1}`
? `${location.uri}:${location.range.start.line}:${location.range.start.character + 1}`
: match[0],
),
);
Expand Down

0 comments on commit a4f818e

Please sign in to comment.