Skip to content
Snippets Groups Projects
Commit ecf88b79 authored by chrigiBisig's avatar chrigiBisig
Browse files

test Execution working

parent e01051ed
No related branches found
No related tags found
1 merge request!2Feature/linting
......@@ -17,7 +17,7 @@ export class TestSuite implements TestElement {
controller: vscode.TestController
) {
this.identifier = uuid.v4();
this.testItem = controller.createTestItem(this.identifier, name);
this.testItem.canResolveChildren = true;
controller.items.add(this.testItem);
......@@ -35,12 +35,16 @@ export class TestSuite implements TestElement {
this.testItem.children.add(testCase.testItem);
}
public getChildren() : TestElement []{
return this.children;
}
public getChildren(predicate: (testElement: TestElement) => boolean, recursive: boolean = false) : TestElement []{
const result = this.children.filter(predicate);
this.children.forEach(child => {
if (child instanceof TestSuite){
result.push(...child.getChildren(predicate));
}
});
public getChild(name: string) : TestElement | undefined {
return this.children.find(tc => tc.name === name);
return result;
}
public getTestCases() : TestCase[] {
......@@ -51,7 +55,7 @@ export class TestSuite implements TestElement {
testCases.push(child);
}
else if (child instanceof TestSuite){
testCases.concat(...child.getTestCases());
testCases.push(...child.getTestCases());
}
});
......
import * as vscode from 'vscode';
import { TestFinder } from '../TestFinder/TestFinder';
import { TestCase } from './TestCase';
import { TestElement } from "./TestElement";
import { TestSuite } from "./TestSuite";
......@@ -9,29 +10,30 @@ export class TestTree {
private readonly testFinder: TestFinder
) {}
private testCases = new Map<string, TestElement>();
private testCases: TestElement[] = [];
public set(name : string, data : TestElement) : void {
this.testCases.set(name, data);
public add(testElement : TestElement) : void {
this.testCases.push(testElement);
}
public has(name: string): boolean {
return this.testCases.get(name) !== undefined;
public any(predicate: (testElement: TestElement) => boolean): boolean{
return this.testCases.find(predicate)!== undefined;
}
public get(name: string) : TestElement | undefined {
const data = this.testCases.get(name);
if(data){
return data;
}
public find(predicate: (testElement: TestElement) => boolean) : TestElement | undefined {
return this.filter(predicate)[0];
}
const containingSuite = [...this.testCases].find(testCase => {
if(testCase[1] instanceof TestSuite){
return (testCase[1] as TestSuite).getChild(name);
public filter(predicate: (testElement: TestElement) => boolean): TestElement[]{
const data = this.testCases.filter(predicate);
this.testCases.forEach(tc => {
if(tc instanceof TestSuite){
data.push(...tc.getChildren(predicate, true));
}
});
return (containingSuite?.[1] as TestSuite)?.getChild(name);
return data;
}
public clear(): void {
......@@ -39,7 +41,7 @@ export class TestTree {
this.testController.items.delete(testCase.testItem.id);
});
this.testCases.clear();
this.testCases.length = 0;
}
public async refresh(): Promise<void> {
......
......@@ -47,17 +47,17 @@ export class ExecutableTestFinder implements TestFinder {
}
if(testDeclaration.length === 2){
if(!testData.has(testDeclaration[0])){
testData.set(testDeclaration[0], new TestSuite(testDeclaration[0], controller));
if(!testData.any(tc => tc.name === testDeclaration[0])){
testData.add(new TestSuite(testDeclaration[0], controller));
}
const testElement = testData.get(testDeclaration[0]) as TestSuite;
const testElement = testData.filter(tc => tc.name === testDeclaration[0])[0] as TestSuite;
const testCase = new TestCase(testDeclaration[1], testPath, lineNumber, uri, controller);
testElement.addChild(testCase);
}
else{
const testCase = new TestCase(testDeclaration[0], testPath, lineNumber, uri, controller);
testData.set(testDeclaration[0], testCase);
testData.add(testCase);
}
}
});
......
......@@ -31,7 +31,7 @@ export abstract class RunHandler {
continue;
}
const testElement = testData.get(test.id);
const testElement = testData.find(tc => tc.identifier === test.id);
if (testElement instanceof TestCase) {
run.enqueued(test);
queue.push(testElement);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment