Skip to content

Commit

Permalink
add test tree -3
Browse files Browse the repository at this point in the history
Signed-off-by: issacto <[email protected]>
  • Loading branch information
issacto committed Aug 21, 2023
1 parent 6d0a48d commit 4c96ebc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
16 changes: 9 additions & 7 deletions vs code extension/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ export function activate(context: ExtensionContext) {
run.enqueued(test);
queue.push({ test, data });
} else {
if (data instanceof TestFile ) {
if (data instanceof TestFile ) {
await data.updateFromDisk(ctrl, test);
}

await discoverTests(gatherTestItems(test));

}
if(data instanceof TestFile && test.children.size!=0 )
if(!(data instanceof TestFile) || !data.isDirectory(test.uri.fsPath))
{
if (test.uri && !coveredLines.has(test.uri.toString())) {
try {
Expand Down Expand Up @@ -251,9 +252,10 @@ function createDirItems( controller:vscode.TestController, uri: vscode.Uri){
if(!controller.items.get(rootUri)){
file = controller.createTestItem(rootUri, dirArr[0], tmpUri);
controller.items.add(file);
data = new TestFile()
testData.set(file, data);
data = new TestFile();
file.canResolveChildren = true;
testData.set(file, data);

}
else{
file = controller.items.get(rootUri)
Expand All @@ -266,17 +268,17 @@ function createDirItems( controller:vscode.TestController, uri: vscode.Uri){
var tmpDir = rootUri
var tmpFile = null
var tmpData = null

for(var i =1;i<dirArr.length;i++){
tmpDir = tmpDir + "/" + dirArr[i]

const existing = prevFile.children.get(tmpDir);

if(!existing){
tmpUri = vscode.Uri.file(tmpDir);
tmpFile = controller.createTestItem(tmpDir, dirArr[i], tmpUri);
tmpData = new TestFile();
testData.set(tmpFile, tmpData);
tmpFile.canResolveChildren = true;

testData.set(tmpFile, tmpData);
// add to existing tree structure
prevFile.children.add(tmpFile)

Expand Down
18 changes: 16 additions & 2 deletions vs code extension/client/src/services/TestTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ export class TestFile {

public async updateFromDisk(controller: vscode.TestController, item: vscode.TestItem) {
try {
if(item.children.size==0){
if(!this.isDirectory(item.uri.fsPath)){
var content= await getContentFromFilesystem(item.uri!, (item.children.size==0));
item.error = undefined;
this.updateFromContents(controller, content, item, item.children.size);

}else{
for (const nestedItem of item.children) {
const data = testData.get(nestedItem[1]);
if(data instanceof TestFile){
await this.updateFromDisk(controller,nestedItem[1] )
}
}
}
} catch (e) {
item.error = (e as Error).stack;
}
Expand Down Expand Up @@ -87,6 +95,12 @@ export class TestFile {
// else ascend(0) // finish and assign children for all remaining items
}


public isDirectory(fileName:string){
if(fileName.includes(".cut")) return false
else return true
}



}
Expand Down Expand Up @@ -120,7 +134,7 @@ export class TestCase {

async run(item: vscode.TestItem, options: vscode.TestRun): Promise<void> {
const start = Date.now();
await new Promise(resolve => setTimeout(resolve, 1000 + Math.random() * 1000));
await new Promise(resolve => setTimeout(resolve, 1 + Math.random() * 1));
const duration = Date.now() - start;
options.passed(item, duration);

Expand Down

0 comments on commit 4c96ebc

Please sign in to comment.