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 9c5d64d658..8c1dc8e2c6 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 @@ -259,16 +259,30 @@ export const SolidityUnitTesting = (props: any) => { for(const contract of contracts) { if(contract && contract !== 'summary') { runningTestFileName = cleanFileName(filename, contract) - // show contract and file name - const ContractCard: any = ( -
- {contract} ({filename}) -
- ) - setTestsOutput(prevCards => ([...prevCards, ContractCard])) - // show tests 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 => ([...prevCards, ContractCard])) + // show tests for(const test of tests) { if (test.type === 'testPass') { if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) @@ -286,8 +300,61 @@ export const SolidityUnitTesting = (props: any) => { ) setTestsOutput(prevCards => ([...prevCards, testPassCard])) - } + } else if (test.type === 'testFailure') { + // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.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(result.location, runningTests, result.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])) + } + } else if (test.type === 'logOnly') { + // if (test.hhLogs && test.hhLogs.length) printHHLogs(test.hhLogs, test.value) + } } + } else { + // show only contract and file name + const ContractCard: any = ( +
+ {contract} ({filename}) +
+ ) + setTestsOutput(prevCards => ([...prevCards, ContractCard])) } } } @@ -301,98 +368,9 @@ export const SolidityUnitTesting = (props: any) => { // // // ) - // } - // if (result.type === 'contract') { - // var testSuite = result.value - // if (testSuites) { - // testSuites.push(testSuite) - // } else { - // testSuites = [testSuite] - // } - // runningTestFileName = cleanFileName(result.filename, testSuite) - // const ContractCard: any = ( - //
- // {testSuite} ({result.filename}) - //
- // ) - // setTestsOutput(prevCards => ([...prevCards, ContractCard])) - // } else if (result.type === 'testPass') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // const testPassCard: any = ( - //
discardHighlight()} - // > - //
- // ✓ {result.value} - // {debugBtn} - //
- //
- // ) - // setTestsOutput(prevCards => ([...prevCards, testPassCard])) - // } else if (result.type === 'testFailure') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // if (!result.assertMethod) { - // const testFailCard1: any = (
highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ {result.value} - // {debugBtn} - //
- // Error Message: - // "{result.errMsg}" - //
) - // setTestsOutput(prevCards => ([...prevCards, testFailCard1])) - // } else { - // const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' - // const method = result.assertMethod === 'ok' ? '' : result.assertMethod - // const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected - // const testFailCard2: any = (
highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ {result.value} - // {debugBtn} - //
- // Error Message: - // "{result.errMsg}" - // Assertion: - //
- // Expected value should be - //
{method}
- //
{preposition} {expected}
- //
- // Received value: - // {result.returned} - // Skipping the remaining tests of the function. - //
) - // setTestsOutput(prevCards => ([...prevCards, testFailCard2])) - // } - // } else if (result.type === 'logOnly') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // } + // } } - // const testCallback = (result: any, runningTests: any) => { - // console.log('result--------------in testCallback->', result) - // console.log('testsResultByFilename--------============------in testCallback->', testsResultByFilename) - // if(result.filename) { - // if(!testsResultByFilename[result.filename]) { - // testsResultByFilename[result.filename] = {} - // testsResultByFilename[result.filename][contract]['tests'] = [] - // testsResultByFilename[result.filename]['summary'] = {} - // } - // testsResultByFilename[result.filename]['tests'].push(result) - // } - // } - const testCallback = (result: any, runningTests: any) => { console.log('result--------------in testCallback->', result) console.log('testsResultByFilename--------============------in testCallback->', testsResultByFilename) @@ -407,91 +385,6 @@ export const SolidityUnitTesting = (props: any) => { testsResultByFilename[result.filename][result.context].push(result) showTestsResult() } - // let debugBtn - // if ((result.type === 'testPass' || result.type === 'testFailure') && result.debugTxHash) { - // const { web3, debugTxHash } = result - // debugBtn = ( - //
startDebug(debugTxHash, web3)}> - // - //
- // ) - // } - // if (result.type === 'contract') { - // var testSuite = result.value - // if (testSuites) { - // testSuites.push(testSuite) - // } else { - // testSuites = [testSuite] - // } - // runningTestFileName = cleanFileName(result.filename, testSuite) - // const ContractCard: any = ( - //
- // {testSuite} ({result.filename}) - //
- // ) - // setTestsOutput(prevCards => ([...prevCards, ContractCard])) - // } else if (result.type === 'testPass') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // const testPassCard: any = ( - //
discardHighlight()} - // > - //
- // ✓ {result.value} - // {debugBtn} - //
- //
- // ) - // setTestsOutput(prevCards => ([...prevCards, testPassCard])) - // } else if (result.type === 'testFailure') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // if (!result.assertMethod) { - // const testFailCard1: any = (
highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ {result.value} - // {debugBtn} - //
- // Error Message: - // "{result.errMsg}" - //
) - // setTestsOutput(prevCards => ([...prevCards, testFailCard1])) - // } else { - // const preposition = result.assertMethod === 'equal' || result.assertMethod === 'notEqual' ? 'to' : '' - // const method = result.assertMethod === 'ok' ? '' : result.assertMethod - // const expected = result.assertMethod === 'ok' ? '\'true\'' : result.expected - // const testFailCard2: any = (
highlightLocation(result.location, runningTests, result.filename)} - // > - //
- // ✘ {result.value} - // {debugBtn} - //
- // Error Message: - // "{result.errMsg}" - // Assertion: - //
- // Expected value should be - //
{method}
- //
{preposition} {expected}
- //
- // Received value: - // {result.returned} - // Skipping the remaining tests of the function. - //
) - // setTestsOutput(prevCards => ([...prevCards, testFailCard2])) - // } - // } else if (result.type === 'logOnly') { - // if (result.hhLogs && result.hhLogs.length) printHHLogs(result.hhLogs, result.value) - // } } const resultsCallback = (_err: any, result: any, cb: any) => {