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

[WIP] Create a custom Logger to gather the data from the test run #271

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3e5bcda
Started implementing a DataCollector
GeorchW Jun 9, 2020
2aa35dc
Implement basic TCP server in the extension
GeorchW Jun 9, 2020
e8cfd4e
Tidying up executor, part 1
GeorchW Jun 9, 2020
429f945
Tidying up executor, part 2
GeorchW Jun 9, 2020
b58f8bd
Add code to set the server port for the subprocess
GeorchW Jun 9, 2020
5f277ad
Add publish dir to .gitignore
GeorchW Jun 9, 2020
edddb24
Add process env back in
GeorchW Jun 9, 2020
ce6b03f
Add data collector arguments to dotnet test
GeorchW Jun 9, 2020
b84e3a1
Send some slightly less nonsense data
GeorchW Jun 9, 2020
8b2fc4f
Send data as JSON
GeorchW Jun 9, 2020
4511b76
Make Executor.exec awaitable
GeorchW Jun 9, 2020
0d665bb
Make use of the received data
GeorchW Jun 9, 2020
a0db0fd
Use Logger instead of DataCollector API
GeorchW Jun 10, 2020
b4db6e3
Minor corrections
GeorchW Jun 10, 2020
560222f
Tidy up a little
GeorchW Jun 10, 2020
37353bc
Don't parse trx
GeorchW Jun 10, 2020
79527ef
Rename ITestResult => ITestResults
GeorchW Jun 10, 2020
3abb168
Fix event surface
GeorchW Jun 10, 2020
2bee683
Remove testResultsFile
GeorchW Jun 10, 2020
7062995
Clean up TestResult class
GeorchW Jun 10, 2020
3e7a541
Make an interface out of TestResult
GeorchW Jun 10, 2020
3a77b44
Use logger for test discovery
GeorchW Jun 10, 2020
d3e96f8
Remove unused usings
GeorchW Jun 11, 2020
50bfeee
Notify watcher of start/end of test run
GeorchW Jun 11, 2020
358bc47
Rework tree code
GeorchW Jun 11, 2020
8df96c9
Clean up subprocess logging
GeorchW Jun 11, 2020
acacf60
Spam less output
GeorchW Jun 11, 2020
c83800b
Apply old test results after discovery
GeorchW Jun 11, 2020
974ae83
Fix watch, remove tests that are not found
GeorchW Jun 11, 2020
8e96ffd
Fix gotoTest
GeorchW Jun 11, 2020
3d3df54
Log child process output by default
GeorchW Jun 11, 2020
044955c
Fix weird XUnit names
GeorchW Jun 11, 2020
d410eeb
Replace then with async/await
GeorchW Jun 11, 2020
5403938
Send messages asynchronously
GeorchW Jun 12, 2020
579e9d0
Rebuild tree when tests are removed
GeorchW Jun 12, 2020
09f7e83
Add proper names
GeorchW Jun 12, 2020
18effd7
Update language version
GeorchW Feb 26, 2022
f6fef75
Update packages
GeorchW Feb 26, 2022
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
Prev Previous commit
Next Next commit
Use logger for test discovery
  • Loading branch information
GeorchW committed Jun 10, 2020
commit 3a77b442cce3880ed359fffcdaafda8578b0b81a
5 changes: 2 additions & 3 deletions src/appInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AppInsightsClient } from "./appInsightsClient";
import { Logger } from "./logger";
import { TestCommands } from "./testCommands";
import { TestDirectories } from "./testDirectories";
import { IDiscoverTestsResult } from "./testDiscovery";

export class AppInsights {

Expand All @@ -20,12 +19,12 @@ export class AppInsights {
}
}

private telemetryDiscoveredTests(results: IDiscoverTestsResult[]) {
private telemetryDiscoveredTests(results: string[]) {

// Dispose to unsubscribe, we only try to report these metrics first time tests are discovered
this.testDiscoveryFinishedEvent.dispose();

const numberOfTests = [].concat(...results.map( (r) => r.testNames)).length;
const numberOfTests = results.length;

if (numberOfTests < 1) {
return;
Expand Down
5 changes: 2 additions & 3 deletions src/dotnetTestExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Logger } from "./logger";
import { parseTestName } from "./parseTestName";
import { StatusBar } from "./statusBar";
import { ITestRunContext, TestCommands } from "./testCommands";
import { IDiscoverTestsResult } from "./testDiscovery";
import { TestNode } from "./testNode";
import { ITestResults, ITestResult } from "./testResult";
import { Utility } from "./utility";
Expand Down Expand Up @@ -120,9 +119,9 @@ export class DotnetTestExplorer implements TreeDataProvider<TestNode> {
this._onDidChangeTreeData.fire(null);
}

private updateWithDiscoveredTests(results: IDiscoverTestsResult[]) {
private updateWithDiscoveredTests(results: string[]) {
this.testNodes = [];
this.discoveredTests = [].concat(...results.map((r) => r.testNames));
this.discoveredTests = results;
this.statusBar.discovered(this.discoveredTests.length);
this._onDidChangeTreeData.fire(null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { TestResultsListener } from "./testResultsListener";
export async function activate(context: vscode.ExtensionContext) {
const testDirectories = new TestDirectories();
const listener = await TestResultsListener.create();
const testCommands = new TestCommands(testDirectories, `${context.extensionPath}/out/logger/`, listener.port);
const testCommands = new TestCommands(testDirectories, `${context.extensionPath}/out/logger/`, listener);
const gotoTest = new GotoTest();
const findTestInContext = new FindTestInContext();
const problems = new Problems(testCommands);
Expand Down
76 changes: 41 additions & 35 deletions src/testCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { AppInsightsClient } from "./appInsightsClient";
import { Executor } from "./executor";
import { Logger } from "./logger";
import { TestDirectories } from "./testDirectories";
import { discoverTests, IDiscoverTestsResult } from "./testDiscovery";
import { TestNode } from "./testNode";
import { ITestResults, ITestResult } from "./testResult";
import { Utility } from "./utility";
import { TestResultsListener } from "./testResultsListener";

export interface ITestRunContext {
testName: string;
Expand All @@ -18,7 +18,7 @@ export interface ITestRunContext {

export class TestCommands implements Disposable {
private onTestDiscoveryStartedEmitter = new EventEmitter<string>();
private onTestDiscoveryFinishedEmitter = new EventEmitter<IDiscoverTestsResult[]>();
private onTestDiscoveryFinishedEmitter = new EventEmitter<string[]>();
private onTestRunEmitter = new EventEmitter<ITestRunContext>();
private onNewTestResultsEmitter = new EventEmitter<ITestResults>();
private lastRunTestContext: ITestRunContext = null;
Expand All @@ -30,7 +30,7 @@ export class TestCommands implements Disposable {
constructor(
private testDirectories: TestDirectories,
public readonly loggerPath: string,
public readonly loggerPort: number) { }
public readonly loggerServer: TestResultsListener) { }

public dispose(): void {
try {
Expand All @@ -41,7 +41,7 @@ export class TestCommands implements Disposable {
}
}

public discoverTests() {
public async discoverTests(): Promise<void> {
this.onTestDiscoveryStartedEmitter.fire("");

this.testDirectories.clearTestsForDirectory();
Expand All @@ -52,50 +52,56 @@ export class TestCommands implements Disposable {

this.setupTestResultFolder();

const runSeqOrAsync = async () => {
const discoveredTests = [];

const addToDiscoveredTests = (discoverdTestResult: IDiscoverTestsResult, dir: string) => {
if (discoverdTestResult.testNames.length > 0) {
discoveredTests.push(discoverdTestResult);
}
};

const discoveredTests = [];
const discoverAndAdd = async (dir: string) => {
const tests = await this.discoverTestsInFolder(dir);
discoveredTests.push(...tests);
};

try {

if (Utility.runInParallel) {
await Promise.all(testDirectories.map(async (dir) => await addToDiscoveredTests(await this.discoverTestsInFolder(dir), dir)));
} else {
for (const dir of testDirectories) {
addToDiscoveredTests(await this.discoverTestsInFolder(dir), dir);
}
try {
if (Utility.runInParallel) {
await Promise.all(testDirectories.map(async (dir) => await discoverAndAdd(dir)));
} else {
for (const dir of testDirectories) {
await discoverAndAdd(dir);
}

this.onTestDiscoveryFinishedEmitter.fire(discoveredTests);
} catch (error) {
this.onTestDiscoveryFinishedEmitter.fire([]);
}
};

runSeqOrAsync();
}

public async discoverTestsInFolder(dir: string): Promise<IDiscoverTestsResult> {
const testsForDir: IDiscoverTestsResult = await discoverTests(dir, Utility.additionalArgumentsOption);
this.testDirectories.addTestsForDirectory(testsForDir.testNames.map((tn) => ({ dir, name: tn })));
return testsForDir;
this.onTestDiscoveryFinishedEmitter.fire(discoveredTests);
} catch (error) {
this.onTestDiscoveryFinishedEmitter.fire([]);
}
}

public get testResultFolder(): string {
return this.testResultsFolder;
public async discoverTestsInFolder(dir: string): Promise<string[]> {
const discoveredTests: string[] = []
const subscription = this.loggerServer.onMessage((message) => {
if (message.type === "discovery") {
discoveredTests.push(...message.discovered);
}
})
try {
const command = `dotnet test `
+ `${Utility.additionalArgumentsOption} `
+ `--list-tests `
+ `--verbosity=quiet `
+ `--test-adapter-path "${this.loggerPath}" `
+ `--logger "VsCodeLogger;port=${this.loggerServer.port}" `;
await Executor.exec(command, dir);
}
finally {
subscription.dispose();
}
return discoveredTests;
}

public get onTestDiscoveryStarted(): Event<string> {
return this.onTestDiscoveryStartedEmitter.event;
}

public get onTestDiscoveryFinished(): Event<IDiscoverTestsResult[]> {
public get onTestDiscoveryFinished(): Event<string[]> {
return this.onTestDiscoveryFinishedEmitter.event;
}

Expand Down Expand Up @@ -206,7 +212,7 @@ export class TestCommands implements Disposable {
let command = `dotnet test ${Utility.additionalArgumentsOption} `
+ `--no-build `
+ `--test-adapter-path "${this.loggerPath}" `
+ `--logger "VsCodeLogger;port=${this.loggerPort}" `;
+ `--logger "VsCodeLogger;port=${this.loggerServer.port}" `;

if (testName && testName.length) {
if (isSingleTest) {
Expand Down
168 changes: 0 additions & 168 deletions src/testDiscovery.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Watch {
const command = `dotnet watch test ${Utility.additionalArgumentsOption} `
+ `--verbosity:quiet `
+ `--test-adapter-path "${this.testCommands.loggerPath}" `
+ `--logger "VsCodeLogger;port=${this.testCommands.loggerPort}" `;
+ `--logger "VsCodeLogger;port=${this.testCommands.loggerServer.port}" `;

Logger.Log(`Executing ${command} in ${testDirectory}`);
const watcher = Executor.spawn(command, testDirectory);
Expand Down
Loading