@@ -6,96 +6,97 @@ describe('Parser Test Suite', () => {
66 let parser , tree , file ;
77
88 // TEST 11: PARSER DOESN'T BREAK UPON RECURSIVE COMPONENTS
9- describe ( 'It should render the second call of mutually recursive components, but no further' , ( ) => {
10- beforeAll ( ( ) => {
11- file = path . join ( __dirname , '../../../../src/test/test_cases/tc_11/index.js' ) ;
12- parser = new Parser ( file ) ;
13- tree = parser . parse ( ) ;
14- } ) ;
15-
16- test ( 'Tree should not be undefined' , ( ) => {
17- expect ( tree ) . toBeDefined ( ) ;
18- } ) ;
19-
20- test ( 'Tree should have an index component while child App1, grandchild App2, great-grandchild App1' , ( ) => {
21- expect ( tree ) . toHaveProperty ( 'name' , 'index' ) ;
22- expect ( tree . children ) . toHaveLength ( 1 ) ;
23- expect ( tree . children [ 0 ] ) . toHaveProperty ( 'name' , 'App1' ) ;
24- expect ( tree . children [ 0 ] . children ) . toHaveLength ( 1 ) ;
25- expect ( tree . children [ 0 ] . children [ 0 ] ) . toHaveProperty ( 'name' , 'App2' ) ;
26- expect ( tree . children [ 0 ] . children [ 0 ] . children ) . toHaveLength ( 1 ) ;
27- expect ( tree . children [ 0 ] . children [ 0 ] . children [ 0 ] ) . toHaveProperty ( 'name' , 'App1' ) ;
28- expect ( tree . children [ 0 ] . children [ 0 ] . children [ 0 ] . children ) . toHaveLength ( 0 ) ;
29- } ) ;
30- } ) ;
31-
32- // TEST 12A: NEXT.JS APPS (pages router)
33- describe ( 'It should parse Next.js applications using Pages Router' , ( ) => {
34- beforeAll ( ( ) => {
35- file = path . join ( __dirname , '../../../../src/test/test_cases/tc_12a/pages/index.js' ) ;
36- parser = new Parser ( file ) ;
37- tree = parser . parse ( ) ;
38- } ) ;
39-
40- test ( 'Root should be named index, children should be named Head and Navbar, children of Navbar should be named Link and Image' , ( ) => {
41- expect ( tree ) . toHaveProperty ( 'name' , 'index' ) ;
42- expect ( tree . children ) . toHaveLength ( 2 ) ;
43- expect ( tree . children [ 0 ] ) . toHaveProperty ( 'name' , 'Head' ) ;
44- expect ( tree . children [ 1 ] ) . toHaveProperty ( 'name' , 'Navbar' ) ;
45-
46- expect ( tree . children [ 1 ] . children ) . toHaveLength ( 2 ) ;
47- expect ( tree . children [ 1 ] . children [ 0 ] ) . toHaveProperty ( 'name' , 'Link' ) ;
48- expect ( tree . children [ 1 ] . children [ 1 ] ) . toHaveProperty ( 'name' , 'Image' ) ;
49- } ) ;
50- } ) ;
51-
52- // TEST 12B: NEXT.JS APPS (app router)
53- describe ( 'It should parser Next.js applications using Apps Router' , ( ) => {
54- beforeAll ( ( ) => {
55- file = path . join ( __dirname , '../../../../src/test/test_cases/tc_12b/app/page.jsx' ) ;
56- parser = new Parser ( file ) ;
57- tree = parser . parse ( ) ;
58- } ) ;
59-
60- test ( 'Root should be named page, it should have one child named Homepage' , ( ) => {
61- expect ( tree ) . toHaveProperty ( 'name' , 'page' ) ;
62- expect ( tree . children ) . toHaveLength ( 1 ) ;
63- expect ( tree . children [ 0 ] ) . toHaveProperty ( 'name' , 'HomePage' ) ;
64- } ) ;
65- } ) ;
9+ // describe('It should render the second call of mutually recursive components, but no further', () => {
10+ // beforeAll(() => {
11+ // file = path.join(__dirname, '../../../../src/test/test_cases/tc_11/index.js');
12+ // parser = new Parser(file);
13+ // tree = parser.parse();
14+ // });
15+
16+ // test('Tree should not be undefined', () => {
17+ // expect(tree).toBeDefined();
18+ // });
19+
20+ // test('Tree should have an index component while child App1, grandchild App2, great-grandchild App1', () => {
21+ // expect(tree).toHaveProperty('name', 'index');
22+ // expect(tree.children).toHaveLength(1);
23+ // expect(tree.children[0]).toHaveProperty('name', 'App1');
24+ // expect(tree.children[0].children).toHaveLength(1);
25+ // expect(tree.children[0].children[0]).toHaveProperty('name', 'App2');
26+ // expect(tree.children[0].children[0].children).toHaveLength(1);
27+ // expect(tree.children[0].children[0].children[0]).toHaveProperty('name', 'App1');
28+ // expect(tree.children[0].children[0].children[0].children).toHaveLength(0);
29+ // });
30+ // });
31+
32+ // // TEST 12A: NEXT.JS APPS (pages router)
33+ // describe('It should parse Next.js applications using Pages Router', () => {
34+ // beforeAll(() => {
35+ // file = path.join(__dirname, '../../../../src/test/test_cases/tc_12a/pages/index.js');
36+ // parser = new Parser(file);
37+ // tree = parser.parse();
38+ // });
39+
40+ // test('Root should be named index, children should be named Head and Navbar, children of Navbar should be named Link and Image', () => {
41+ // expect(tree).toHaveProperty('name', 'index');
42+ // expect(tree.children).toHaveLength(2);
43+ // expect(tree.children[0]).toHaveProperty('name', 'Head');
44+ // expect(tree.children[1]).toHaveProperty('name', 'Navbar');
45+
46+ // expect(tree.children[1].children).toHaveLength(2);
47+ // expect(tree.children[1].children[0]).toHaveProperty('name', 'Link');
48+ // expect(tree.children[1].children[1]).toHaveProperty('name', 'Image');
49+ // });
50+ // });
51+
52+ // // TEST 12B: NEXT.JS APPS (app router)
53+ // describe('It should parser Next.js applications using Apps Router', () => {
54+ // beforeAll(() => {
55+ // file = path.join(__dirname, '../../../../src/test/test_cases/tc_12b/app/page.jsx');
56+ // parser = new Parser(file);
57+ // tree = parser.parse();
58+ // });
59+
60+ // test('Root should be named page, it should have one child named Homepage', () => {
61+ // expect(tree).toHaveProperty('name', 'page');
62+ // expect(tree.children).toHaveLength(1);
63+ // expect(tree.children[0]).toHaveProperty('name', 'HomePage');
64+ // });
65+ // });
6666
67- // TEST 13: VARIABLE DECLARATION IMPORTS AND REACT.LAZY IMPORTS
68- describe ( 'It should parse VariableDeclaration imports including React.lazy imports' , ( ) => {
69- beforeAll ( ( ) => {
70- file = path . join ( __dirname , '../../../../src/test/test_cases/tc_13/index.js' ) ;
71- parser = new Parser ( file ) ;
72- tree = parser . parse ( ) ;
73- } ) ;
74-
75- test ( 'Root should be named index, it should have one child named App' , ( ) => {
76- expect ( tree ) . toHaveProperty ( 'name' , 'index' ) ;
77- expect ( tree . children ) . toHaveLength ( 1 ) ;
78- expect ( tree . children [ 0 ] ) . toHaveProperty ( 'name' , 'App' ) ;
79- } ) ;
80-
81- test ( 'App should have three children, Component1, Component2 and Component3, all found successfully' , ( ) => {
82- expect ( tree . children [ 0 ] . children [ 0 ] ) . toHaveProperty ( 'name' , 'Component1' ) ;
83- expect ( tree . children [ 0 ] . children [ 0 ] ) . toHaveProperty ( 'thirdParty' , false ) ;
84-
85- expect ( tree . children [ 0 ] . children [ 1 ] ) . toHaveProperty ( 'name' , 'Component2' ) ;
86- expect ( tree . children [ 0 ] . children [ 1 ] ) . toHaveProperty ( 'thirdParty' , false ) ;
87-
88- expect ( tree . children [ 0 ] . children [ 2 ] ) . toHaveProperty ( 'name' , 'Component3' ) ;
89- expect ( tree . children [ 0 ] . children [ 2 ] ) . toHaveProperty ( 'thirdParty' , false ) ;
90- } ) ;
91- } ) ;
67+ // // TEST 13: VARIABLE DECLARATION IMPORTS AND REACT.LAZY IMPORTS
68+ // describe('It should parse VariableDeclaration imports including React.lazy imports', () => {
69+ // beforeAll(() => {
70+ // file = path.join(__dirname, '../../../../src/test/test_cases/tc_13/index.js');
71+ // parser = new Parser(file);
72+ // tree = parser.parse();
73+ // });
74+
75+ // test('Root should be named index, it should have one child named App', () => {
76+ // expect(tree).toHaveProperty('name', 'index');
77+ // expect(tree.children).toHaveLength(1);
78+ // expect(tree.children[0]).toHaveProperty('name', 'App');
79+ // });
80+
81+ // test('App should have three children, Component1, Component2 and Component3, all found successfully', () => {
82+ // expect(tree.children[0].children[0]).toHaveProperty('name', 'Component1');
83+ // expect(tree.children[0].children[0]).toHaveProperty('thirdParty', false);
84+
85+ // expect(tree.children[0].children[1]).toHaveProperty('name', 'Component2');
86+ // expect(tree.children[0].children[1]).toHaveProperty('thirdParty', false);
87+
88+ // expect(tree.children[0].children[2]).toHaveProperty('name', 'Component3');
89+ // expect(tree.children[0].children[2]).toHaveProperty('thirdParty', false);
90+ // });
91+ // });
9292
9393 // TEST 14: CHECK IF COMPONENT IS A CLIENT COMPONENT USING HOOKS AND DIRECTIVES
9494 describe ( 'It should parse components and determine if the component type' , ( ) => {
9595 beforeAll ( ( ) => {
9696 file = path . join ( __dirname , '../../../../src/test/test_cases/tc_14/index.js' ) ;
9797 parser = new Parser ( file ) ;
9898 tree = parser . parse ( ) ;
99+ // console.log('tree:', tree.children[0].children[0]);
99100 } ) ;
100101
101102 test ( 'Root should be named index, it should have one children named App' , ( ) => {
@@ -107,9 +108,6 @@ describe('Parser Test Suite', () => {
107108 test ( 'App should have three children, Component1 is a client component using hooks (variable declaration, export default declaration, and function declaration), Component2 is a client component using directives, and Component3 is not a client component' , ( ) => {
108109 expect ( tree . children [ 0 ] . children [ 0 ] ) . toHaveProperty ( 'name' , 'Component1' ) ;
109110 expect ( tree . children [ 0 ] . children [ 0 ] ) . toHaveProperty ( 'isClientComponent' , true ) ;
110- expect ( typeof tree . children [ 0 ] . children [ 0 ] ) . toBe ( 'function' ) ;
111- expect ( typeof tree . children [ 0 ] . children [ 0 ] ) . not . toBe ( 'undefined' ) ;
112- expect ( typeof tree . children [ 0 ] . children [ 0 ] ) . not . toBe ( 'function' ) ;
113111
114112 expect ( tree . children [ 0 ] . children [ 1 ] ) . toHaveProperty ( 'name' , 'Component2' ) ;
115113 expect ( tree . children [ 0 ] . children [ 1 ] ) . toHaveProperty ( 'isClientComponent' , true ) ;
0 commit comments