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 5f1bf15bf1..cb32b2fa4c 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 @@ -230,6 +230,113 @@ export const SolidityUnitTesting = (props: any) => { } } + const renderTests = (tests: any, contract: any, filename: any) => { + const index = tests.findIndex((test: any) => test.type === 'testFailure') + let label + if (index > -1) label = (
+ FAIL +
) + else label = (
+ PASS +
) + // show contract and file name with label + const ContractCard: any = ( +
+ {label}{contract} ({filename}) +
+ ) + setTestsOutput(prevCards => { + const index = prevCards.findIndex((card: any) => card.props.id === runningTestFileName) + prevCards[index] = ContractCard + return prevCards + }) + // show tests + for(const test of tests) { + if(!test.rendered) { + 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} +
+
+ ) + 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, 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, 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 + } + } + } + } + const showTestsResult = () => { console.log('filesContent---->', filesContent) let filenames = Object.keys(testsResultByFilename) @@ -241,110 +348,7 @@ export const SolidityUnitTesting = (props: any) => { runningTestFileName = cleanFileName(filename, contract) const tests = fileTestsResult[contract] if (tests?.length) { - const index = tests.findIndex((test: any) => test.type === 'testFailure') - let label - if (index > -1) label = (
- FAIL -
) - else label = (
- PASS -
) - // show contract and file name with label - const ContractCard: any = ( -
- {label}{contract} ({filename}) -
- ) - setTestsOutput(prevCards => { - const index = prevCards.findIndex((card: any) => card.props.id === runningTestFileName) - prevCards[index] = ContractCard - return prevCards - }) - // show tests - for(const test of tests) { - if(!test.rendered) { - 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} -
-
- ) - 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, 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, 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 - } - } - } + renderTests(tests, contract, filename) } else { // show only contract and file name const contractCard: any = (