From 7274222dbc205291c7ea7699eef5f7e5bbba3143 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 31 Dec 2021 13:54:42 +0530 Subject: [PATCH] load test files from root folder --- .../src/lib/logic/testTabLogic.ts | 20 ++++++---- .../src/lib/solidity-unit-testing.tsx | 40 +++++++++---------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts index 80a65d5f8f..6b42bc128a 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts +++ b/libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts @@ -12,6 +12,10 @@ export class TestTabLogic { } setCurrentPath (path: string) { + if (path === '/') { + this.currentPath = '/' + return + } if (path.indexOf('/') === 0) return this.currentPath = this.helper.removeMultipleSlashes(this.helper.removeTrailingSlashes(path)) } @@ -60,22 +64,22 @@ export class TestTabLogic { return this.fileManager.isRemixDActive() } - async getTests (cb: any) { - if (!this.currentPath) return cb(null, []) + async getTests () { + if (!this.currentPath) return [] const provider = this.fileManager.fileProviderOf(this.currentPath) - if (!provider) return cb(null, []) + if (!provider) return [] const tests = [] let files = [] try { - if (await this.fileManager.exists(this.currentPath)) files = await this.fileManager.readdir(this.currentPath) + if (await this.fileManager.exists(this.currentPath)) files = await this.fileManager.readdir(this.currentPath) } catch (e: any) { - cb(e.message) + throw e.message } for (const file in files) { - const filepath = provider && provider.type ? provider.type + '/' + file : file - if (/.(_test.sol)$/.exec(file)) tests.push(filepath) + const filepath = provider && provider.type ? provider.type + '/' + file : file + if (/.(_test.sol)$/.exec(file)) tests.push(filepath) } - cb(null, tests, this.currentPath) + return tests } // @todo(#2758): If currently selected file is compiled and compilation result is available, diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx index 97deaec103..64db219780 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx +++ b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx @@ -88,15 +88,14 @@ export const SolidityUnitTesting = (props: Record) => { updateTestFileList() clearResults() try { - testTabLogic.getTests(async (error: any, tests: any) => { - if (error) return setToasterMsg(error) - allTests.current = tests - selectedTests.current = [...allTests.current] - updateTestFileList() - if (!areTestsRunning) await updateRunAction(file) - }) - } catch (e) { + const tests = await testTabLogic.getTests() + allTests.current = tests + selectedTests.current = [...allTests.current] + updateTestFileList() + if (!areTestsRunning) await updateRunAction(file) + } catch (e: any) { console.log(e) + setToasterMsg(e) } } @@ -135,11 +134,11 @@ export const SolidityUnitTesting = (props: Record) => { }) testTab.on('filePanel', 'setWorkspace', async () => { - setCurrentPath(defaultPath) + await setCurrentPath(defaultPath) }) testTab.fileManager.events.on('noFileSelected', () => { }) // eslint-disable-line - testTab.fileManager.events.on('currentFileChanged', (file: any, provider: any) => updateForNewCurrent(file)) + testTab.fileManager.events.on('currentFileChanged', async(file: any, provider: any) => await updateForNewCurrent(file)) }, []) // eslint-disable-line @@ -157,7 +156,7 @@ export const SolidityUnitTesting = (props: Record) => { if (e.key === 'Enter') { if (await testTabLogic.pathExists(testDirInput)) { testTabLogic.setCurrentPath(testDirInput) - updateForNewCurrent() + await updateForNewCurrent() return } } @@ -174,17 +173,19 @@ export const SolidityUnitTesting = (props: Record) => { if (await testTabLogic.pathExists(testDirInput)) { setDisableCreateButton(true) setDisableGenerateButton(false) - testTabLogic.setCurrentPath(testDirInput) - updateForNewCurrent() + await setCurrentPath(testDirInput) } else { // Enable Create button setDisableCreateButton(false) // Disable Generate button because dir does not exist setDisableGenerateButton(true) + await setCurrentPath(testDirInput) } } } else { - updateDirList('/') + await setCurrentPath('/') + setDisableCreateButton(true) + setDisableGenerateButton(false) } } @@ -194,8 +195,7 @@ export const SolidityUnitTesting = (props: Record) => { setInputPathValue(inputPath) if (disableCreateButton) { if (await testTabLogic.pathExists(inputPath)) { - testTabLogic.setCurrentPath(inputPath) - updateForNewCurrent() + await setCurrentPath(inputPath) } } } @@ -211,7 +211,7 @@ export const SolidityUnitTesting = (props: Record) => { setDisableGenerateButton(false) testTabLogic.setCurrentPath(inputPath) await updateRunAction() - updateForNewCurrent() + await updateForNewCurrent() pathOptions.push(inputPath) setPathOptions(pathOptions) } @@ -648,7 +648,6 @@ export const SolidityUnitTesting = (props: Record) => { } ) => { style={{ backgroundImage: "var(--primary)" }} onKeyUp={handleTestDirInput} onChange={handleEnter} + onClick = {() => { if (inputPathValue === '/') setInputPathValue('')} } />