Skip to content

Commit b9d518b

Browse files
test 1 pass
1 parent 9a66c04 commit b9d518b

File tree

7 files changed

+56
-21
lines changed

7 files changed

+56
-21
lines changed

src/test/suite/parser.test.ts

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ describe('Parser Test Suite', () => {
1010
describe('It works for simple apps', () => {
1111
beforeAll(() => {
1212
// console.log('-----test 0----------')
13-
file = path.join(__dirname, '../test_cases/tc_0/index.js');
13+
file = path.join(__dirname, '../../../../src/test/test_cases/tc_0/index.js');
1414
parser = new Parser(file);
1515
tree = parser.parse();
16-
console.log('tree', tree);
16+
// console.log('tree', tree);
1717
});
1818

1919
test('Tree should not be undefined', () => {
2020
expect(tree).toBeDefined();
2121
expect(typeof(tree)).toBe('object');
2222
});
2323

24-
test('Parsed tree has a property called name with value index and one child with name App', () => {
24+
test('Parsed tree has a property called name with value index, and a child with the name App', () => {
2525
expect(tree).toHaveProperty('name', 'index');
26-
// console.log('--------------index---------');
2726
expect(tree.children[0]).toHaveProperty('name', 'App');
2827
});
2928
});
@@ -34,16 +33,44 @@ describe('Parser Test Suite', () => {
3433

3534
describe('It checks for nested Children', () => {
3635
beforeEach(() => {
37-
file = path.join(__dirname, '../../../../test_cases/tc_1/index.js');
38-
// file = path.join(__dirname, '../../../src/test/test_apps/test_0/index.js');
36+
file = path.join(__dirname, '../../../../src/test/test_cases/tc_1/index.js');
3937
parser = new Parser(file);
38+
tree = parser.parse();
39+
console.log('tree 1', tree);
40+
})
41+
42+
test('Parsed tree should have a property called name with the value index, and one child with name App, which has its own child, Main', () => {
43+
expect(tree).toHaveProperty('name', 'index');
44+
expect(tree.children[0]).toHaveProperty('name', 'App');
45+
// console.log(tree.children[0].children);
46+
expect(tree.children[0].children[0]).toHaveProperty('name', 'Main');
4047
})
4148

42-
console.log('inside Test 1')
49+
test('Parsed tree has correct amount of child components', () => {
50+
expect(tree.children).toHaveLength(1);
51+
expect(tree.children[0].children).toHaveLength(1);
52+
})
53+
54+
test('Parsed tree depth is accurate', () => {
55+
expect(tree).toHaveProperty('depth', 0);
56+
expect(tree.children[0]).toHaveProperty('depth', 1);
57+
expect(tree.children[0].children[0]).toHaveProperty('depth', 2);
58+
})
4359
})
4460

61+
// TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS
62+
describe('It works for third party, React Router, and destructured imports', () => {
63+
beforeAll(() => {
64+
file = path.join(__dirname, '../../../../src/test/test_cases/tc_2/index.js');
65+
parser = new Parser(file);
66+
tree = parser.parse();
67+
console.log(tree);
68+
})
69+
70+
71+
})
72+
4573

46-
4774
// TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT
4875
describe('Catches bad imports', () => {
4976
beforeEach(() => {
@@ -76,6 +103,7 @@ describe('Parser Test Suite', () => {
76103
file = path.join(__dirname, '../../../../src/test/test_cases/tc_11/index.js');
77104
parser = new Parser(file);
78105
tree = parser.parse();
106+
// console.log('tree11', tree);
79107
});
80108

81109
test('Tree should not be undefined', () => {
@@ -195,20 +223,14 @@ describe('Parser Test Suite', () => {
195223

196224

197225

198-
// TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS
226+
199227
// TEST 3: IDENTIFIES REDUX STORE CONNECTION
200228
// TEST 4: ALIASED IMPORTS
201229
// TEST 5: MISSING EXTENSIONS AND UNUSED IMPORTS
202-
// TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT
203-
// TEST 7: SYNTAX ERROR IN APP FILE CAUSES PARSER ERROR
230+
204231
// TEST 8: MULTIPLE PROPS ON ONE COMPONENT
205232
// TEST 9: FINDING DIFFERENT PROPS ACROSS TWO OR MORE IDENTICAL COMPONENTS
206-
// TEST 10: CHECK CHILDREN WORKS AND COMPONENTS WORK
207-
// TEST 11: PARSER DOESN'T BREAK UPON RECURSIVE COMPONENTS
208-
// TEST 12: NEXT.JS APPS (pages version & app router version)
209-
// TEST 13: Variable Declaration Imports and React.lazy Imports
210-
// TEST 14: CHECK IF COMPONENT IS CLIENT OR SERVER (USING HOOKS & DIRECTIVES) => BOOLEAN (priority)
211-
233+
212234
// LOU is doing EXTENSION TEST in extension.test.ts
213235

214236
});
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export default function App() {
22
return (
3-
<div>This is the App.</div>
3+
<section>
4+
<div>This is the App.</div>
5+
</section>
46
)
57
};

src/test/test_cases/tc_0/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React from 'react';
44
import { createRoot } from 'react-dom/client';
5-
import App from './component/App';
5+
import App from './component/App.jsx';
66

77
const root = createRoot(document.getElementById('root'));
88
root.render(<App />);

src/test/test_cases/tc_1/component/App.jsx renamed to src/test/test_cases/tc_1/components/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import Main from './Main';
2+
import Main from './Main.jsx';
33

44
const App = () => {
55
return (

src/test/test_cases/tc_1/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import { render } from "react-dom";
3-
import App from "./component/App";
3+
import App from "./components/App.jsx";
44

55
//TEST 1 - Simple App with 2 components, App and Main
66
//App renders Main

src/test/test_cases/tc_2/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
import { render } from "react-dom";
3+
4+
5+
// TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS
6+
7+
render(
8+
<div>
9+
10+
</div>, document.getElementById('root')
11+
);

0 commit comments

Comments
 (0)