Skip to content

Commit 02171cb

Browse files
Louis KuczykowskiLouis Kuczykowski
authored andcommitted
fixed test cases that were broken
1 parent 86bba6b commit 02171cb

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

media/RL(Final).png

301 KB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
{
4545
"id": "react-labyrinth",
4646
"title": "React Labyrinth",
47-
"icon": "/media/test1.svg"
47+
"icon": "/media/RL(Final).png"
4848
}
4949
]
5050
},

src/panel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function createPanel(context: vscode.ExtensionContext, data: Tree, column
1818
);
1919

2020
// Set the icon logo of extension webview
21-
panel.iconPath = vscode.Uri.joinPath(context.extensionUri, 'media', 'favicon.ico');
21+
panel.iconPath = vscode.Uri.joinPath(context.extensionUri, 'media', 'RL(Final).png');
2222

2323
// Set URI to be the path to bundle
2424
const bundlePath: vscode.Uri = vscode.Uri.joinPath(context.extensionUri, 'build', 'bundle.js');

src/parser.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,28 @@ export class Parser {
5757
};
5858
this.tree = root;
5959
this.parser(root);
60+
// clean up nodes with error: 'File not found'
61+
this.removeTreesWithError(this.tree);
6062
return this.tree;
6163
}
6264

65+
private removeTreesWithError(tree: Tree): void {
66+
// base case
67+
if(tree.children.length === 0) return;
68+
// iterate over tree.children array to check for error.
69+
for(let i = 0; i < tree.children.length; i++){
70+
// call removeTreesWithError on every tree in the children array
71+
if(tree.children[i].children.length !== 0){
72+
this.removeTreesWithError(tree.children[i]);
73+
}
74+
if(tree.children[i].error && (tree.children[i].error === 'File not found' || tree.children[i].error === 'Error while processing this file/node')){
75+
// when an error is found, splice the tree out of the children array
76+
tree.children.splice(i,1);
77+
i--; // decrement to account for change in children array length
78+
}
79+
}
80+
};
81+
6382
public getTree(): Tree {
6483
return this.tree;
6584
}
@@ -278,7 +297,7 @@ export class Parser {
278297
}
279298
};
280299

281-
console.log('directive: ', directive);
300+
// console.log('directive: ', directive);
282301
// Initial check for use of directives (ex: 'use client', 'use server', 'use strict')
283302
// Accounts for more than one directive
284303
for (let i = 0; i < directive.length; i++) {

src/test/suite/parser.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ describe('Parser Test Suite', () => {
5555
file = path.join(__dirname, '../../../../src/test/test_cases/tc_6/component/App.jsx');
5656
parser = new Parser(file);
5757
tree = parser.parse();
58-
console.log(tree)
5958
});
6059

61-
test("Child component that doesn't exist still shows up on the node tree", () => {
62-
expect(tree.children[0].name).toBe('anotherApp');
63-
expect(tree.children[0].error).not.toBe('');
60+
test("Child component with bad file path does not show up on the node tree", () => {
61+
expect(tree.children.length).toBe(0);
6462
})
6563
})
6664

@@ -71,10 +69,9 @@ describe('Parser Test Suite', () => {
7169
parser = new Parser(file);
7270
tree = parser.parse();
7371
});
72+
7473
test("Parser stops parsing when there is a syntax error in a component", () => {
75-
expect(tree.children[0].name).toBe('App');
76-
expect(tree.children[0].error).not.toBeUndefined;
77-
expect((tree.children[0].children).length).toBe(0);
74+
expect(tree.children.length).toBe(0);
7875
});
7976
})
8077

0 commit comments

Comments
 (0)