From ecc047beff5d2c30e9e8bff6025ec68d555ed107 Mon Sep 17 00:00:00 2001 From: ChristinaRaether Date: Sat, 27 Jan 2024 10:55:09 -0800 Subject: [PATCH 1/5] set up of test 0 and 1 --- src/test/suite/parser.test.ts | 22 +++++++++++++++++---- src/test/test_cases/tc_1/component/App.jsx | 13 ++++++++++++ src/test/test_cases/tc_1/component/Main.jsx | 9 +++++++++ src/test/test_cases/tc_1/index.js | 12 +++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 src/test/test_cases/tc_1/component/App.jsx create mode 100644 src/test/test_cases/tc_1/component/Main.jsx create mode 100644 src/test/test_cases/tc_1/index.js diff --git a/src/test/suite/parser.test.ts b/src/test/suite/parser.test.ts index e1784d2..5e6387d 100644 --- a/src/test/suite/parser.test.ts +++ b/src/test/suite/parser.test.ts @@ -31,9 +31,10 @@ describe('Parser Test Suite', () => { }); // TEST 0: ONE CHILD - describe('It works for simple apps', () => { - before(() => { - file = path.join(__dirname, ''); + it('It works for simple apps', () => { + beforeAll(() => { + console.log('-----test 0----------') + file = path.join(__dirname, '../test_cases/tc_0/index.js'); parser = new Parser(file); tree = parser.parse(); }); @@ -44,11 +45,24 @@ describe('Parser Test Suite', () => { }); test('Parsed tree has a property called name with value index and one child with name App', () => { - + expect(tree).toHaveProperty('index'); + console.log('--------------index---------'); }); }); // TEST 1: NESTED CHILDREN + + describe('It checks for nested Children', () => { + beforeEach(() => { + file = path.join(__dirname, '../test_cases/tc_1/index.js'); + // file = path.join(__dirname, '../../../src/test/test_apps/test_0/index.js'); + parser = new Parser(file); + }) + + console.log('inside Test 1') + }) + + // TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS // TEST 3: IDENTIFIES REDUX STORE CONNECTION // TEST 4: ALIASED IMPORTS diff --git a/src/test/test_cases/tc_1/component/App.jsx b/src/test/test_cases/tc_1/component/App.jsx new file mode 100644 index 0000000..d725e57 --- /dev/null +++ b/src/test/test_cases/tc_1/component/App.jsx @@ -0,0 +1,13 @@ +import React from 'react'; +import Main from './Main'; + +const App = () => { + return ( +
+
App
+
+
+ ) +} + +export default App; \ No newline at end of file diff --git a/src/test/test_cases/tc_1/component/Main.jsx b/src/test/test_cases/tc_1/component/Main.jsx new file mode 100644 index 0000000..9dcaab6 --- /dev/null +++ b/src/test/test_cases/tc_1/component/Main.jsx @@ -0,0 +1,9 @@ +import React from "react"; + +const Main = () => { + return ( +
Main App
+ ) +} + +export default Main; \ No newline at end of file diff --git a/src/test/test_cases/tc_1/index.js b/src/test/test_cases/tc_1/index.js new file mode 100644 index 0000000..2001356 --- /dev/null +++ b/src/test/test_cases/tc_1/index.js @@ -0,0 +1,12 @@ +import React from "react"; +import { render } from "react-dom"; +import App from "./component/App"; + +//TEST 1 - Simple App with 2 components, App and Main +//App renders Main + +render( +
+ +
, document.getElementById('root') +); \ No newline at end of file From 146e8967c2ed4559815c3f0f66ed77cc26e5c389 Mon Sep 17 00:00:00 2001 From: ChristinaRaether Date: Sun, 4 Feb 2024 16:42:28 -0800 Subject: [PATCH 2/5] first working test suite --- .DS_Store | Bin 0 -> 6148 bytes .eslintrc.json | 2 +- package.json | 2 +- src/test/suite/parser.test.ts | 21 +++++++++++---------- src/test/test_cases/tc_0/index.js | 2 +- src/test/test_cases/tc_2/index.js | 0 6 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 .DS_Store create mode 100644 src/test/test_cases/tc_2/index.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d086e81ccb757faa6422ee11cfbf8623da007842 GIT binary patch literal 6148 zcmeHKv2GJV5PgdsB{7k36D388tLPGuCZa&-u$(V&fDYpGMFGjqMG&Wi6MsO9g!q9J z5d}zymOgbVl!6NQ2HxzhlG(E_P@yQ=k#^tR&dkp9+q+vY0Mi-g>p&a89GhUX#cqm; zU)qG-@FOckBXbOQ*L#Cvv_BCU2ciN|fvc#1yt_@TVHeMFpx<9}`_%{S8x`GdHY_rZ z$;Y5``tjR?(4SxG-+y-TZ7`3wnTlD~J;X~4P$0*St`0PQOh!~Vyw8p-hsr#oB4APz zrTGANgwI0A2dg;14*3PTEGDh9%VIUhNB6!y?0vQzYvCzfSTBlTlpnB_Ul#~ubKWmUh{6@JE@?- zXX^z9nkDe=)`h3S>Fk$VFP|5#Rax=sdN8)0)YQg3TWs#8!`Md!q5@HYa|Pu4kgy4+ z9!rPz)4|Rj0f7iN&(aC_PQPZB)_*#{5aWb u6Si$OF^MZ3+7xzvJGK|H6)&?{qc4#QV(PJU$PrrnBVc8ST~y$|D)0w0uIQft literal 0 HcmV?d00001 diff --git a/.eslintrc.json b/.eslintrc.json index d25565b..a4f4c43 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,7 +18,7 @@ "no-this-before-super": "warn", "no-undef": "warn", "no-unreachable": "warn", - "no-unused-vars": "warn", + "no-unused-vars": "off", "constructor-super": "warn", "valid-typeof": "warn" } diff --git a/package.json b/package.json index d88ca4d..cb88741 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "scripts": { "lint": "eslint .", "pretest": "npm run lint", - "test": "node ./build/src/test/runTest.js", + "test": "npx tsc ; node ./build/src/test/runTest.js", "dev": "webpack --watch", "webpack": "webpack" }, diff --git a/src/test/suite/parser.test.ts b/src/test/suite/parser.test.ts index 5e6387d..418a974 100644 --- a/src/test/suite/parser.test.ts +++ b/src/test/suite/parser.test.ts @@ -1,7 +1,7 @@ // import * as assert from 'assert' -- this one is from node import { Parser } from '../../parser'; import * as path from 'path'; -import { beforeEach, expect, test } from '@jest/globals'; +import { beforeEach, beforeAll, expect, test } from '@jest/globals'; // You can import and use all API from the 'vscode' module // as well as import your extension to test it @@ -15,8 +15,7 @@ describe('Parser Test Suite', () => { describe('It initializes correctly', () => { beforeEach(() => { // declare var and assign it to a test file and make new instance of Parser - file = path.join(__dirname, '../test_cases/tc_0/index.js'); - // file = path.join(__dirname, '../../../src/test/test_apps/test_0/index.js'); + file = path.join(__dirname, '../../../../src/test/test_cases/tc_0/index.js'); parser = new Parser(file); }); @@ -31,22 +30,24 @@ describe('Parser Test Suite', () => { }); // TEST 0: ONE CHILD - it('It works for simple apps', () => { + describe('It works for simple apps', () => { beforeAll(() => { - console.log('-----test 0----------') - file = path.join(__dirname, '../test_cases/tc_0/index.js'); + // console.log('-----test 0----------') + file = path.join(__dirname, '../../../../src/test/test_cases/tc_0/index.js'); parser = new Parser(file); tree = parser.parse(); + console.log('tree', tree); }); test('It returns an defined object tree when parsed', () => { expect(tree).toBeDefined(); - //expect(tree).toMatchObject() + expect(typeof(tree)).toBe('object'); }); test('Parsed tree has a property called name with value index and one child with name App', () => { - expect(tree).toHaveProperty('index'); - console.log('--------------index---------'); + expect(tree).toHaveProperty('name', 'index'); + // console.log('--------------index---------'); + expect(tree.children[0]).toHaveProperty('name', 'App'); }); }); @@ -54,7 +55,7 @@ describe('Parser Test Suite', () => { describe('It checks for nested Children', () => { beforeEach(() => { - file = path.join(__dirname, '../test_cases/tc_1/index.js'); + file = path.join(__dirname, '../../../../test_cases/tc_1/index.js'); // file = path.join(__dirname, '../../../src/test/test_apps/test_0/index.js'); parser = new Parser(file); }) diff --git a/src/test/test_cases/tc_0/index.js b/src/test/test_cases/tc_0/index.js index 05603bc..9cee093 100644 --- a/src/test/test_cases/tc_0/index.js +++ b/src/test/test_cases/tc_0/index.js @@ -9,7 +9,7 @@ import React from 'react'; import { createRoot } from 'react-dom/client'; -import App from './components/App.jsx'; +import App from './component/App'; const root = createRoot(document.getElementById('root')); root.render(); \ No newline at end of file diff --git a/src/test/test_cases/tc_2/index.js b/src/test/test_cases/tc_2/index.js new file mode 100644 index 0000000..e69de29 From f77adbff81a66c4e8d9fbc46590468aef6b4c619 Mon Sep 17 00:00:00 2001 From: ChristinaRaether Date: Sun, 4 Feb 2024 17:02:31 -0800 Subject: [PATCH 3/5] added test suites 6-12 --- src/test/suite/parser.test.ts | 153 ++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/src/test/suite/parser.test.ts b/src/test/suite/parser.test.ts index 418a974..cafa5d3 100644 --- a/src/test/suite/parser.test.ts +++ b/src/test/suite/parser.test.ts @@ -8,6 +8,7 @@ import { beforeEach, beforeAll, expect, test } from '@jest/globals'; import * as vscode from 'vscode' // const myExtension = require('../extension'); + describe('Parser Test Suite', () => { let parser, tree, file; @@ -64,6 +65,158 @@ describe('Parser Test Suite', () => { }) + + // TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT + describe('Catches bad imports', () => { + beforeEach(() => { + file = path.join(__dirname, '../../../../src/test/test_cases/tc_6/component/App.jsx'); + parser = new Parser(file); + tree = parser.parse(); + }); + + test("Child component with bad file path does not show up on the node tree", () => { + expect(tree.children.length).toBe(0); + }); + }); + + // TEST 7: SYNTAX ERROR IN APP FILE CAUSES PARSER ERROR + describe('Parser should not work for components with syntax errors in the code', () => { + beforeEach(() => { + file = path.join(__dirname, '../../../../src/test/test_cases/tc_7/index.js'); + parser = new Parser(file); + tree = parser.parse(); + }); + + test("Parser stops parsing when there is a syntax error in a component", () => { + expect(tree.children.length).toBe(0); + }); + }); + + // TEST 11: PARSER DOESN'T BREAK UPON RECURSIVE COMPONENTS + describe('It should render the second call of mutually recursive components, but no further', () => { + beforeAll(() => { + file = path.join(__dirname, '../../../../src/test/test_cases/tc_11/index.js'); + parser = new Parser(file); + tree = parser.parse(); + }); + + test('Tree should not be undefined', () => { + expect(tree).toBeDefined(); + }); + + test('Tree should have an index component while child App1, grandchild App2, great-grandchild App1', () => { + expect(tree).toHaveProperty('name', 'index'); + expect(tree.children).toHaveLength(1); + expect(tree.children[0]).toHaveProperty('name', 'App1'); + expect(tree.children[0].children).toHaveLength(1); + expect(tree.children[0].children[0]).toHaveProperty('name', 'App2'); + expect(tree.children[0].children[0].children).toHaveLength(1); + expect(tree.children[0].children[0].children[0]).toHaveProperty('name', 'App1'); + expect(tree.children[0].children[0].children[0].children).toHaveLength(0); + }); + }); + + // TEST 12A: NEXT.JS APPS (PAGES ROUTER) + describe('It should parse Next.js applications using Pages Router', () => { + beforeAll(() => { + file = path.join(__dirname, '../../../../src/test/test_cases/tc_12a/pages/index.js'); + parser = new Parser(file); + tree = parser.parse(); + }); + + test('Root should be named index, children should be named Head and Navbar, children of Navbar should be named Link and Image', () => { + expect(tree).toHaveProperty('name', 'index'); + expect(tree.children).toHaveLength(2); + expect(tree.children[0]).toHaveProperty('name', 'Head'); + expect(tree.children[1]).toHaveProperty('name', 'Navbar'); + + expect(tree.children[1].children).toHaveLength(2); + expect(tree.children[1].children[0]).toHaveProperty('name', 'Link'); + expect(tree.children[1].children[1]).toHaveProperty('name', 'Image'); + }); + }); + + // TEST 12B: NEXT.JS APPS (APP ROUTER) + describe('It should parser Next.js applications using Apps Router', () => { + beforeAll(() => { + file = path.join(__dirname, '../../../../src/test/test_cases/tc_12b/app/page.jsx'); + parser = new Parser(file); + tree = parser.parse(); + }); + + test('Root should be named page, it should have one child named Homepage', () => { + expect(tree).toHaveProperty('name', 'page'); + expect(tree.children).toHaveLength(1); + expect(tree.children[0]).toHaveProperty('name', 'HomePage'); + }); + }); + + // TEST 13: VARIABLE DECLARATION IMPORTS AND REACT.LAZY IMPORTS + describe('It should parse VariableDeclaration imports including React.lazy imports', () => { + beforeAll(() => { + file = path.join(__dirname, '../../../../src/test/test_cases/tc_13/index.js'); + parser = new Parser(file); + tree = parser.parse(); + }); + + test('Root should be named index, it should have one child named App', () => { + expect(tree).toHaveProperty('name', 'index'); + expect(tree.children).toHaveLength(1); + expect(tree.children[0]).toHaveProperty('name', 'App'); + }); + + test('App should have three children, Component1, Component2 and Component3, all found successfully', () => { + expect(tree.children[0].children[0]).toHaveProperty('name', 'Component1'); + expect(tree.children[0].children[0]).toHaveProperty('thirdParty', false); + + expect(tree.children[0].children[1]).toHaveProperty('name', 'Component2'); + expect(tree.children[0].children[1]).toHaveProperty('thirdParty', false); + + expect(tree.children[0].children[2]).toHaveProperty('name', 'Component3'); + expect(tree.children[0].children[2]).toHaveProperty('thirdParty', false); + }); + }); + + // TEST 14: CHECK IF COMPONENT IS A CLIENT COMPONENT USING HOOKS AND DIRECTIVES + describe('It should parse components and determine if the component type', () => { + beforeAll(() => { + file = path.join(__dirname, '../../../../src/test/test_cases/tc_14/index.js'); + parser = new Parser(file); + tree = parser.parse(); + }); + + test('Root should be named index, it should have one children named App', () => { + expect(tree).toHaveProperty('name', 'index'); + expect(tree.children).toHaveLength(1); + expect(tree.children[0]).toHaveProperty('name', 'App'); + }); + + test('App should have three children, Component1, Component4, Component5 is a client component using hooks, Component2 is a client component using directives, and Component3, Component6, Component7 is not a client component', () => { + expect(tree.children[0].children[0]).toHaveProperty('name', 'Component1'); + expect(tree.children[0].children[0]).toHaveProperty('isClientComponent', true); + + expect(tree.children[0].children[1]).toHaveProperty('name', 'Component2'); + expect(tree.children[0].children[1]).toHaveProperty('isClientComponent', true); + + expect(tree.children[0].children[2]).toHaveProperty('name', 'Component3'); + expect(tree.children[0].children[2]).toHaveProperty('isClientComponent', false); + + expect(tree.children[0].children[3]).toHaveProperty('name', 'Component4'); + expect(tree.children[0].children[3]).toHaveProperty('isClientComponent', true); + + expect(tree.children[0].children[4]).toHaveProperty('name', 'Component5'); + expect(tree.children[0].children[4]).toHaveProperty('isClientComponent', true); + + expect(tree.children[0].children[5]).toHaveProperty('name', 'Component6'); + expect(tree.children[0].children[5]).toHaveProperty('isClientComponent', false); + + expect(tree.children[0].children[6]).toHaveProperty('name', 'Component7'); + expect(tree.children[0].children[6]).toHaveProperty('isClientComponent', false); + }); + }); + + + // TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS // TEST 3: IDENTIFIES REDUX STORE CONNECTION // TEST 4: ALIASED IMPORTS From b9d518b87487c6a322dfe0ef1236a696b53a27b0 Mon Sep 17 00:00:00 2001 From: ChristinaRaether Date: Sun, 11 Feb 2024 20:05:11 -0800 Subject: [PATCH 4/5] test 1 pass --- src/test/suite/parser.test.ts | 56 +++++++++++++------ src/test/test_cases/tc_0/component/App.jsx | 4 +- src/test/test_cases/tc_0/index.js | 2 +- .../tc_1/{component => components}/App.jsx | 2 +- .../tc_1/{component => components}/Main.jsx | 0 src/test/test_cases/tc_1/index.js | 2 +- src/test/test_cases/tc_2/index.js | 11 ++++ 7 files changed, 56 insertions(+), 21 deletions(-) rename src/test/test_cases/tc_1/{component => components}/App.jsx (84%) rename src/test/test_cases/tc_1/{component => components}/Main.jsx (100%) diff --git a/src/test/suite/parser.test.ts b/src/test/suite/parser.test.ts index d2282b9..cf8a1b7 100644 --- a/src/test/suite/parser.test.ts +++ b/src/test/suite/parser.test.ts @@ -10,10 +10,10 @@ describe('Parser Test Suite', () => { describe('It works for simple apps', () => { beforeAll(() => { // console.log('-----test 0----------') - file = path.join(__dirname, '../test_cases/tc_0/index.js'); + file = path.join(__dirname, '../../../../src/test/test_cases/tc_0/index.js'); parser = new Parser(file); tree = parser.parse(); - console.log('tree', tree); + // console.log('tree', tree); }); test('Tree should not be undefined', () => { @@ -21,9 +21,8 @@ describe('Parser Test Suite', () => { expect(typeof(tree)).toBe('object'); }); - test('Parsed tree has a property called name with value index and one child with name App', () => { + test('Parsed tree has a property called name with value index, and a child with the name App', () => { expect(tree).toHaveProperty('name', 'index'); - // console.log('--------------index---------'); expect(tree.children[0]).toHaveProperty('name', 'App'); }); }); @@ -34,16 +33,44 @@ describe('Parser Test Suite', () => { describe('It checks for nested Children', () => { beforeEach(() => { - file = path.join(__dirname, '../../../../test_cases/tc_1/index.js'); - // file = path.join(__dirname, '../../../src/test/test_apps/test_0/index.js'); + file = path.join(__dirname, '../../../../src/test/test_cases/tc_1/index.js'); parser = new Parser(file); + tree = parser.parse(); + console.log('tree 1', tree); + }) + + 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', () => { + expect(tree).toHaveProperty('name', 'index'); + expect(tree.children[0]).toHaveProperty('name', 'App'); + // console.log(tree.children[0].children); + expect(tree.children[0].children[0]).toHaveProperty('name', 'Main'); }) - console.log('inside Test 1') + test('Parsed tree has correct amount of child components', () => { + expect(tree.children).toHaveLength(1); + expect(tree.children[0].children).toHaveLength(1); + }) + + test('Parsed tree depth is accurate', () => { + expect(tree).toHaveProperty('depth', 0); + expect(tree.children[0]).toHaveProperty('depth', 1); + expect(tree.children[0].children[0]).toHaveProperty('depth', 2); + }) }) + // TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS + describe('It works for third party, React Router, and destructured imports', () => { + beforeAll(() => { + file = path.join(__dirname, '../../../../src/test/test_cases/tc_2/index.js'); + parser = new Parser(file); + tree = parser.parse(); + console.log(tree); + }) + + + }) + - // TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT describe('Catches bad imports', () => { beforeEach(() => { @@ -76,6 +103,7 @@ describe('Parser Test Suite', () => { file = path.join(__dirname, '../../../../src/test/test_cases/tc_11/index.js'); parser = new Parser(file); tree = parser.parse(); + // console.log('tree11', tree); }); test('Tree should not be undefined', () => { @@ -195,20 +223,14 @@ describe('Parser Test Suite', () => { - // TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS + // TEST 3: IDENTIFIES REDUX STORE CONNECTION // TEST 4: ALIASED IMPORTS // TEST 5: MISSING EXTENSIONS AND UNUSED IMPORTS - // TEST 6: BAD IMPORT OF APP2 FROM APP1 COMPONENT - // TEST 7: SYNTAX ERROR IN APP FILE CAUSES PARSER ERROR + // TEST 8: MULTIPLE PROPS ON ONE COMPONENT // TEST 9: FINDING DIFFERENT PROPS ACROSS TWO OR MORE IDENTICAL COMPONENTS - // TEST 10: CHECK CHILDREN WORKS AND COMPONENTS WORK - // TEST 11: PARSER DOESN'T BREAK UPON RECURSIVE COMPONENTS - // TEST 12: NEXT.JS APPS (pages version & app router version) - // TEST 13: Variable Declaration Imports and React.lazy Imports - // TEST 14: CHECK IF COMPONENT IS CLIENT OR SERVER (USING HOOKS & DIRECTIVES) => BOOLEAN (priority) - + // LOU is doing EXTENSION TEST in extension.test.ts }); diff --git a/src/test/test_cases/tc_0/component/App.jsx b/src/test/test_cases/tc_0/component/App.jsx index 3608737..4719305 100644 --- a/src/test/test_cases/tc_0/component/App.jsx +++ b/src/test/test_cases/tc_0/component/App.jsx @@ -1,5 +1,7 @@ export default function App() { return ( -
This is the App.
+
+
This is the App.
+
) }; \ No newline at end of file diff --git a/src/test/test_cases/tc_0/index.js b/src/test/test_cases/tc_0/index.js index ab2afa6..b2478ab 100644 --- a/src/test/test_cases/tc_0/index.js +++ b/src/test/test_cases/tc_0/index.js @@ -2,7 +2,7 @@ import React from 'react'; import { createRoot } from 'react-dom/client'; -import App from './component/App'; +import App from './component/App.jsx'; const root = createRoot(document.getElementById('root')); root.render(); \ No newline at end of file diff --git a/src/test/test_cases/tc_1/component/App.jsx b/src/test/test_cases/tc_1/components/App.jsx similarity index 84% rename from src/test/test_cases/tc_1/component/App.jsx rename to src/test/test_cases/tc_1/components/App.jsx index d725e57..5a594ed 100644 --- a/src/test/test_cases/tc_1/component/App.jsx +++ b/src/test/test_cases/tc_1/components/App.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import Main from './Main'; +import Main from './Main.jsx'; const App = () => { return ( diff --git a/src/test/test_cases/tc_1/component/Main.jsx b/src/test/test_cases/tc_1/components/Main.jsx similarity index 100% rename from src/test/test_cases/tc_1/component/Main.jsx rename to src/test/test_cases/tc_1/components/Main.jsx diff --git a/src/test/test_cases/tc_1/index.js b/src/test/test_cases/tc_1/index.js index 2001356..14704ce 100644 --- a/src/test/test_cases/tc_1/index.js +++ b/src/test/test_cases/tc_1/index.js @@ -1,6 +1,6 @@ import React from "react"; import { render } from "react-dom"; -import App from "./component/App"; +import App from "./components/App.jsx"; //TEST 1 - Simple App with 2 components, App and Main //App renders Main diff --git a/src/test/test_cases/tc_2/index.js b/src/test/test_cases/tc_2/index.js index e69de29..ee725ef 100644 --- a/src/test/test_cases/tc_2/index.js +++ b/src/test/test_cases/tc_2/index.js @@ -0,0 +1,11 @@ +import React from "react"; +import { render } from "react-dom"; + + + // TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS + +render( +
+ +
, document.getElementById('root') +); \ No newline at end of file From df191fa434d2a794ee88268d494935ae1fb36661 Mon Sep 17 00:00:00 2001 From: ChristinaRaether Date: Mon, 12 Feb 2024 14:22:30 -0800 Subject: [PATCH 5/5] finished tests 0-2 --- .DS_Store | Bin 6148 -> 6148 bytes src/test/suite/parser.test.ts | 26 +++++++++++++++++++++++--- src/test/test_cases/tc_2/index.js | 6 +++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.DS_Store b/.DS_Store index b2e918a6e29ec6ecf407a46fc8b8b2e60bf27e10..133b94ddb07f99e7b514454a9b8d4b178f7e0205 100644 GIT binary patch delta 328 zcmZoMXffEJ$`WVpw~2v)frUYjA)O(Up(Hoo#U&{xKM5$t!NAa9_hQdcM^yO~yz&JZ zhQZ1CxdlKy42<~+lbcy~F)N)?pX|V@!FJbAZcfJD$$6|=Fy=f~ZKkw_$){OmnLd?G ze#I)o(og_Y!Nn%W((p8K?_?b|ImQo@z1dbVm+DAPKEoy>g6uxUs0C|N_8xVFN+2AD zETM($A}$62ki(c6iW!O+l5^4#Ze?J&Z#a1#y95ivRGRp NiHRbc**X650|4dbU%vnV delta 328 zcmZoMXffEJ$`WVx-JOAffrUYjA)O(Up(Hoo#U&{xKM5$tVRyLcZ0OFTj;Qh}c;yQ+ z41<&Na|?ia7#MR3CO5O}VpfPTob14=!N$PQplP~eavrM|j5&{0n<*?|@@ZCCraSGE zU$M%tFsK7naIwij7&>fnj17~$*;X-^CB{uY!zLqw>^`7*yOK5>b%aVF9EL2Rh3q0O zh6f;rF*6i16fq>{q$AwQz;J!h { file = path.join(__dirname, '../../../../src/test/test_cases/tc_0/index.js'); parser = new Parser(file); tree = parser.parse(); - // console.log('tree', tree); }); test('Tree should not be undefined', () => { @@ -36,7 +35,6 @@ describe('Parser Test Suite', () => { file = path.join(__dirname, '../../../../src/test/test_cases/tc_1/index.js'); parser = new Parser(file); tree = parser.parse(); - console.log('tree 1', tree); }) 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', () => { @@ -64,9 +62,31 @@ describe('Parser Test Suite', () => { file = path.join(__dirname, '../../../../src/test/test_cases/tc_2/index.js'); parser = new Parser(file); tree = parser.parse(); - console.log(tree); }) + test('Should parse destructured and third party imports', () => { + expect(tree).toHaveProperty('thirdParty', false); + expect(tree.children[0]).toHaveProperty('thirdParty', true); + expect(tree.children[1]).toHaveProperty('thirdParty', true); + + try { + expect(tree.children[0].name).toContain('Switch') + } catch { + expect(tree.children[0].name).toContain('Route') + + } + try { + expect(tree.children[1].name).toContain('Switch') + } catch { + expect(tree.children[1].name).toContain('Route') + + } + }) + + test('third party should be reactRouter', () => { + expect(tree.children[0]).toHaveProperty('reactRouter', true); + expect(tree.children[1]).toHaveProperty('reactRouter', true); + }) }) diff --git a/src/test/test_cases/tc_2/index.js b/src/test/test_cases/tc_2/index.js index ee725ef..c819d01 100644 --- a/src/test/test_cases/tc_2/index.js +++ b/src/test/test_cases/tc_2/index.js @@ -1,11 +1,15 @@ import React from "react"; import { render } from "react-dom"; +import { Switch, Route} from 'react-router-dom'; // TEST 2: THIRD PARTY, REACT ROUTER, DESTRUCTURED IMPORTS render(
- + + + +
, document.getElementById('root') ); \ No newline at end of file