From 8ebb852df3a7771202f850bfae105765289fea52 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 15 Dec 2021 17:48:29 +0530 Subject: [PATCH] render a test only once --- .../src/lib/solidity-unit-testing.tsx | 159 ++++++++++-------- 1 file changed, 86 insertions(+), 73 deletions(-) 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 4e6ce3f920..9095fe1c36 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 @@ -37,7 +37,7 @@ export const SolidityUnitTesting = (props: any) => { const [checkSelectAll, setCheckSelectAll] = useState(true) const [testsOutput, setTestsOutput] = useState([]) - let [testsSummary, setTestsSummary] = useState() + // let [testsSummary, setTestsSummary] = useState() const [testsSummaryHidden, setTestsSummaryHidden] = useState('hidden') const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) @@ -255,7 +255,7 @@ export const SolidityUnitTesting = (props: any) => { const showTestsResult = () => { console.log('runningTests---->', runningTests) - setTestsOutput([]) + // setTestsOutput([]) let filenames = Object.keys(testsResultByFilename) for(const filename of filenames) { const fileTestsResult = testsResultByFilename[filename] @@ -285,81 +285,90 @@ export const SolidityUnitTesting = (props: any) => { {label}{contract} ({filename}) ) - setTestsOutput(prevCards => ([...prevCards, ContractCard])) + setTestsOutput(prevCards => { + const index = prevCards.findIndex((card: any) => card.props.id === runningTestFileName) + prevCards[index] = ContractCard + return prevCards + }) // show tests for(const test of tests) { console.log('test---->', test) - let debugBtn - if (test.debugTxHash) { - const { web3, debugTxHash } = test - debugBtn = ( -
startDebug(debugTxHash, web3)}> - -
- ) - } - if (test.type === 'testPass') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - const testPassCard: any = ( -
discardHighlight()} - > -
- ✓ {test.value} - {debugBtn} -
+ if(!test.rendered) { + let debugBtn + if (test.debugTxHash) { + const { web3, debugTxHash } = test + debugBtn = ( +
startDebug(debugTxHash, web3)}> +
- ) - setTestsOutput(prevCards => ([...prevCards, testPassCard])) - } else if (test.type === 'testFailure') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - if (!test.assertMethod) { - const testFailCard1: any = (
highlightLocation(test.location, runningTests, test.filename)} - > -
- ✘ {test.value} - {debugBtn} -
- Error Message: - "{test.errMsg}" -
) - setTestsOutput(prevCards => ([...prevCards, testFailCard1])) - } else { - const preposition = test.assertMethod === 'equal' || test.assertMethod === 'notEqual' ? 'to' : '' - const method = test.assertMethod === 'ok' ? '' : test.assertMethod - const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected - const testFailCard2: any = (
highlightLocation(test.location, runningTests, test.filename)} - > -
- ✘ {test.value} + ) + } + if (test.type === 'testPass') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + const testPassCard: any = ( +
discardHighlight()} + > +
+ ✓ {test.value} {debugBtn} -
- Error Message: - "{test.errMsg}" - Assertion: -
- Expected value should be -
{method}
-
{preposition} {expected}
- Received value: - {test.returned} - Skipping the remaining tests of the function. -
) - setTestsOutput(prevCards => ([...prevCards, testFailCard2])) +
+ ) + setTestsOutput(prevCards => ([...prevCards, testPassCard])) + test.rendered = true + } else if (test.type === 'testFailure') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + if (!test.assertMethod) { + const testFailCard1: any = (
highlightLocation(test.location, runningTests, test.filename)} + > +
+ ✘ {test.value} + {debugBtn} +
+ Error Message: + "{test.errMsg}" +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard1])) + } else { + const preposition = test.assertMethod === 'equal' || test.assertMethod === 'notEqual' ? 'to' : '' + const method = test.assertMethod === 'ok' ? '' : test.assertMethod + const expected = test.assertMethod === 'ok' ? '\'true\'' : test.expected + const testFailCard2: any = (
highlightLocation(test.location, runningTests, test.filename)} + > +
+ ✘ {test.value} + {debugBtn} +
+ Error Message: + "{test.errMsg}" + Assertion: +
+ Expected value should be +
{method}
+
{preposition} {expected}
+
+ Received value: + {test.returned} + Skipping the remaining tests of the function. +
) + setTestsOutput(prevCards => ([...prevCards, testFailCard2])) + } + test.rendered = true + } else if (test.type === 'logOnly') { + if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + test.rendered = true } - } else if (test.type === 'logOnly') { - if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) - } + } } } else { // show only contract and file name @@ -374,7 +383,7 @@ export const SolidityUnitTesting = (props: any) => { } // show summary const testSummary = fileTestsResult['summary'] - if (testSummary && testSummary.filename) { + if (testSummary && testSummary.filename && !testSummary.rendered) { const summaryCard: any = (
Result for {testSummary.filename} Passed: {testSummary.passed} @@ -382,6 +391,7 @@ export const SolidityUnitTesting = (props: any) => { Time Taken: {testSummary.timeTaken}s
) setTestsOutput(prevCards => ([...prevCards, summaryCard])) + fileTestsResult['summary']['rendered'] = true } } } @@ -397,8 +407,11 @@ export const SolidityUnitTesting = (props: any) => { } if(result.type === 'contract') { testsResultByFilename[result.filename][result.value] = [] - } else + } else { + // Set that this test is not rendered on UI + result.rendered = false testsResultByFilename[result.filename][result.context].push(result) + } showTestsResult() } } @@ -432,7 +445,7 @@ export const SolidityUnitTesting = (props: any) => { // yo.update(this.resultStatistics, this.createResultLabel()) if (result) { const totalTime = parseFloat(result.totalTime).toFixed(2) - testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime } + const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } testsResultByFilename[filename]['summary']= testsSummary showTestsResult() // setTestsSummary(testsSummary)