@@ -6,6 +6,91 @@ describe('Parser Test Suite', () => {
66 let parser , tree , file ;
77 const fs = require ( 'fs' ) ;
88
9+ // TEST 0: ONE CHILD
10+ describe ( 'It works for simple apps' , ( ) => {
11+ beforeAll ( ( ) => {
12+ // console.log('-----test 0----------')
13+ file = path . join ( __dirname , '../../../../src/test/test_cases/tc_0/index.js' ) ;
14+ parser = new Parser ( file ) ;
15+ tree = parser . parse ( ) ;
16+ } ) ;
17+
18+ test ( 'Tree should not be undefined' , ( ) => {
19+ expect ( tree ) . toBeDefined ( ) ;
20+ expect ( typeof ( tree ) ) . toBe ( 'object' ) ;
21+ } ) ;
22+
23+ test ( 'Parsed tree has a property called name with value index, and a child with the name App' , ( ) => {
24+ expect ( tree ) . toHaveProperty ( 'name' , 'index' ) ;
25+ expect ( tree . children [ 0 ] ) . toHaveProperty ( 'name' , 'App' ) ;
26+ } ) ;
27+ } ) ;
28+
29+ // these are the 14 tests we need to test for
30+
31+ // TEST 1: NESTED CHILDREN
32+
33+ describe ( 'It checks for nested Children' , ( ) => {
34+ beforeEach ( ( ) => {
35+ file = path . join ( __dirname , '../../../../src/test/test_cases/tc_1/index.js' ) ;
36+ parser = new Parser ( file ) ;
37+ tree = parser . parse ( ) ;
38+ } )
39+
40+ 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' , ( ) => {
41+ expect ( tree ) . toHaveProperty ( 'name' , 'index' ) ;
42+ expect ( tree . children [ 0 ] ) . toHaveProperty ( 'name' , 'App' ) ;
43+ // console.log(tree.children[0].children);
44+ expect ( tree . children [ 0 ] . children [ 0 ] ) . toHaveProperty ( 'name' , 'Main' ) ;
45+ } )
46+
47+ test ( 'Parsed tree has correct amount of child components' , ( ) => {
48+ expect ( tree . children ) . toHaveLength ( 1 ) ;
49+ expect ( tree . children [ 0 ] . children ) . toHaveLength ( 1 ) ;
50+ } )
51+
52+ test ( 'Parsed tree depth is accurate' , ( ) => {
53+ expect ( tree ) . toHaveProperty ( 'depth' , 0 ) ;
54+ expect ( tree . children [ 0 ] ) . toHaveProperty ( 'depth' , 1 ) ;
55+ expect ( tree . children [ 0 ] . children [ 0 ] ) . toHaveProperty ( 'depth' , 2 ) ;
56+ } )
57+ } )
58+
59+ // TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS
60+ describe ( 'It works for third party, React Router, and destructured imports' , ( ) => {
61+ beforeAll ( ( ) => {
62+ file = path . join ( __dirname , '../../../../src/test/test_cases/tc_2/index.js' ) ;
63+ parser = new Parser ( file ) ;
64+ tree = parser . parse ( ) ;
65+ } )
66+
67+ test ( 'Should parse destructured and third party imports' , ( ) => {
68+ expect ( tree ) . toHaveProperty ( 'thirdParty' , false ) ;
69+ expect ( tree . children [ 0 ] ) . toHaveProperty ( 'thirdParty' , true ) ;
70+ expect ( tree . children [ 1 ] ) . toHaveProperty ( 'thirdParty' , true ) ;
71+
72+ try {
73+ expect ( tree . children [ 0 ] . name ) . toContain ( 'Switch' )
74+ } catch {
75+ expect ( tree . children [ 0 ] . name ) . toContain ( 'Route' )
76+
77+ }
78+ try {
79+ expect ( tree . children [ 1 ] . name ) . toContain ( 'Switch' )
80+ } catch {
81+ expect ( tree . children [ 1 ] . name ) . toContain ( 'Route' )
82+
83+ }
84+ } )
85+
86+ test ( 'third party should be reactRouter' , ( ) => {
87+ expect ( tree . children [ 0 ] ) . toHaveProperty ( 'reactRouter' , true ) ;
88+ expect ( tree . children [ 1 ] ) . toHaveProperty ( 'reactRouter' , true ) ;
89+ } )
90+
91+ } )
92+
93+
994 // TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT
1095 describe ( 'Catches bad imports' , ( ) => {
1196 beforeEach ( ( ) => {
@@ -38,6 +123,7 @@ describe('Parser Test Suite', () => {
38123 file = path . join ( __dirname , '../../../../src/test/test_cases/tc_11/index.js' ) ;
39124 parser = new Parser ( file ) ;
40125 tree = parser . parse ( ) ;
126+ // console.log('tree11', tree);
41127 } ) ;
42128
43129 test ( 'Tree should not be undefined' , ( ) => {
@@ -153,25 +239,18 @@ describe('Parser Test Suite', () => {
153239 expect ( tree . children [ 0 ] . children [ 6 ] ) . toHaveProperty ( 'name' , 'Component7' ) ;
154240 expect ( tree . children [ 0 ] . children [ 6 ] ) . toHaveProperty ( 'isClientComponent' , false ) ;
155241 } ) ;
156- } ) ;
242+ } ) ;
243+
244+
157245
158- // these are the 14 tests we need to test for
159246
160- // TEST 1: NESTED CHILDREN
161- // TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS
162247 // TEST 3: IDENTIFIES REDUX STORE CONNECTION
163248 // TEST 4: ALIASED IMPORTS
164249 // TEST 5: MISSING EXTENSIONS AND UNUSED IMPORTS
165- // TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT
166- // TEST 7: SYNTAX ERROR IN APP FILE CAUSES PARSER ERROR
250+
167251 // TEST 8: MULTIPLE PROPS ON ONE COMPONENT
168252 // TEST 9: FINDING DIFFERENT PROPS ACROSS TWO OR MORE IDENTICAL COMPONENTS
169- // TEST 10: CHECK CHILDREN WORKS AND COMPONENTS WORK
170- // TEST 11: PARSER DOESN'T BREAK UPON RECURSIVE COMPONENTS
171- // TEST 12: NEXT.JS APPS (pages version & app router version)
172- // TEST 13: Variable Declaration Imports and React.lazy Imports
173- // TEST 14: CHECK IF COMPONENT IS CLIENT OR SERVER (USING HOOKS & DIRECTIVES) => BOOLEAN (priority)
174-
253+
175254 // LOU is doing EXTENSION TEST in extension.test.ts
176255
177256} ) ;
0 commit comments