|
|
|
@ -8,7 +8,7 @@ import './css/style.css' |
|
|
|
|
const _paq = (window as any)._paq = (window as any)._paq || [] // eslint-disable-line
|
|
|
|
|
|
|
|
|
|
/* eslint-disable-next-line */ |
|
|
|
|
export interface SolidityUnitTestingProps {} |
|
|
|
|
export interface SolidityUnitTestingProps { } |
|
|
|
|
|
|
|
|
|
interface TestObject { |
|
|
|
|
fileName: string |
|
|
|
@ -17,7 +17,7 @@ interface TestObject { |
|
|
|
|
|
|
|
|
|
export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
|
|
|
|
|
const {helper, testTab} = props |
|
|
|
|
const { helper, testTab, initialPath } = props |
|
|
|
|
const { testTabLogic } = testTab |
|
|
|
|
|
|
|
|
|
const [defaultPath, setDefaultPath] = useState('tests') |
|
|
|
@ -55,9 +55,9 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
let runningTestFileName: any |
|
|
|
|
const filesContent: any = {} |
|
|
|
|
|
|
|
|
|
const testsResultByFilename:Record<string, any> = {} |
|
|
|
|
const testsResultByFilename: Record<string, any> = {} |
|
|
|
|
|
|
|
|
|
const trimTestDirInput = (input:string) => { |
|
|
|
|
const trimTestDirInput = (input: string) => { |
|
|
|
|
if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/') |
|
|
|
|
else return input.trim() |
|
|
|
|
} |
|
|
|
@ -109,6 +109,10 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
await updateForNewCurrent() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (initialPath) setCurrentPath(initialPath) |
|
|
|
|
}, [initialPath]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
updateDirList('/') |
|
|
|
|
updateForNewCurrent() |
|
|
|
@ -132,7 +136,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
setCurrentPath(defaultPath) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
testTab.fileManager.events.on('noFileSelected', () => {}) // eslint-disable-line
|
|
|
|
|
testTab.fileManager.events.on('noFileSelected', () => { }) // eslint-disable-line
|
|
|
|
|
testTab.fileManager.events.on('currentFileChanged', (file: any, provider: any) => updateForNewCurrent(file)) |
|
|
|
|
|
|
|
|
|
}, []) // eslint-disable-line
|
|
|
|
@ -182,7 +186,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleEnter = async(e:any) => { |
|
|
|
|
const handleEnter = async (e: any) => { |
|
|
|
|
let inputPath = e.target.value |
|
|
|
|
inputPath = helper.removeMultipleSlashes(trimTestDirInput(inputPath)) |
|
|
|
|
setInputPathValue(inputPath) |
|
|
|
@ -194,7 +198,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleCreateFolder = async() => { |
|
|
|
|
const handleCreateFolder = async () => { |
|
|
|
|
let inputPath = trimTestDirInput(inputPathValue) |
|
|
|
|
let path = helper.removeMultipleSlashes(inputPath) |
|
|
|
|
if (path !== '/') path = helper.removeTrailingSlashes(path) |
|
|
|
@ -266,7 +270,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
if (withoutLabel) { |
|
|
|
|
const contractCard: any = ( |
|
|
|
|
<div id={runningTestFileName} data-id="testTabSolidityUnitTestsOutputheader" className="pt-1"> |
|
|
|
|
<span className="font-weight-bold">{contract ? contract: ''} ({filename})</span> |
|
|
|
|
<span className="font-weight-bold">{contract ? contract : ''} ({filename})</span> |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|
setTestsOutput(prevCards => ([...prevCards, contractCard])) |
|
|
|
@ -303,8 +307,8 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
// show filename and contract
|
|
|
|
|
renderContract(filename, contract, index) |
|
|
|
|
// show tests
|
|
|
|
|
for(const test of tests) { |
|
|
|
|
if(!test.rendered) { |
|
|
|
|
for (const test of tests) { |
|
|
|
|
if (!test.rendered) { |
|
|
|
|
let debugBtn |
|
|
|
|
if (test.debugTxHash) { |
|
|
|
|
const { web3, debugTxHash } = test |
|
|
|
@ -385,11 +389,11 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
|
|
|
|
|
const showTestsResult = () => { |
|
|
|
|
const filenames = Object.keys(testsResultByFilename) |
|
|
|
|
for(const filename of filenames) { |
|
|
|
|
for (const filename of filenames) { |
|
|
|
|
const fileTestsResult = testsResultByFilename[filename] |
|
|
|
|
const contracts = Object.keys(fileTestsResult) |
|
|
|
|
for(const contract of contracts) { |
|
|
|
|
if(contract && contract !== 'summary' && contract !== 'errors') { |
|
|
|
|
for (const contract of contracts) { |
|
|
|
|
if (contract && contract !== 'summary' && contract !== 'errors') { |
|
|
|
|
runningTestFileName = cleanFileName(filename, contract) |
|
|
|
|
const tests = fileTestsResult[contract] |
|
|
|
|
if (tests?.length) { |
|
|
|
@ -433,13 +437,13 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const testCallback = (result: any) => { |
|
|
|
|
if(result.filename) { |
|
|
|
|
if(!testsResultByFilename[result.filename]) { |
|
|
|
|
if (result.filename) { |
|
|
|
|
if (!testsResultByFilename[result.filename]) { |
|
|
|
|
testsResultByFilename[result.filename] = {} |
|
|
|
|
testsResultByFilename[result.filename]['summary'] = {} |
|
|
|
|
} |
|
|
|
|
if(result.type === 'contract') { |
|
|
|
|
testsResultByFilename[result.filename][result.value]= {} |
|
|
|
|
if (result.type === 'contract') { |
|
|
|
|
testsResultByFilename[result.filename][result.value] = {} |
|
|
|
|
testsResultByFilename[result.filename][result.value] = [] |
|
|
|
|
} else { |
|
|
|
|
// Set that this test is not rendered on UI
|
|
|
|
@ -469,10 +473,10 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
if (result) { |
|
|
|
|
const totalTime = parseFloat(result.totalTime).toFixed(2) |
|
|
|
|
const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } |
|
|
|
|
testsResultByFilename[filename]['summary']= testsSummary |
|
|
|
|
testsResultByFilename[filename]['summary'] = testsSummary |
|
|
|
|
showTestsResult() |
|
|
|
|
} else if (_errors) { |
|
|
|
|
if(!testsResultByFilename[filename]) { |
|
|
|
|
if (!testsResultByFilename[filename]) { |
|
|
|
|
testsResultByFilename[filename] = {} |
|
|
|
|
} |
|
|
|
|
testsResultByFilename[filename]['errors'] = _errors |
|
|
|
@ -557,7 +561,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const updateRunAction = async (currentFile : any = null) => { |
|
|
|
|
const updateRunAction = async (currentFile: any = null) => { |
|
|
|
|
const isSolidityActive = await testTab.appManager.isActive('solidity') |
|
|
|
|
if (!isSolidityActive || !selectedTests.current?.length) { |
|
|
|
|
setDisableRunButton(true) |
|
|
|
@ -581,7 +585,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
return selectedTestsList.map(testFileObj => testFileObj.fileName) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const toggleCheckbox = (eChecked: any, index:any) => { |
|
|
|
|
const toggleCheckbox = (eChecked: any, index: any) => { |
|
|
|
|
testFiles[index].checked = eChecked |
|
|
|
|
setTestFiles(testFiles) |
|
|
|
|
selectedTests.current = getCurrentSelectedTests() |
|
|
|
@ -602,7 +606,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
testFiles.forEach((testFileObj) => testFileObj.checked = event.target.checked) |
|
|
|
|
setTestFiles(testFiles) |
|
|
|
|
setCheckSelectAll(event.target.checked) |
|
|
|
|
if(event.target.checked) { |
|
|
|
|
if (event.target.checked) { |
|
|
|
|
selectedTests.current = getCurrentSelectedTests() |
|
|
|
|
setDisableRunButton(false) |
|
|
|
|
} else { |
|
|
|
@ -612,8 +616,8 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const updateTestFileList = () => { |
|
|
|
|
if(allTests.current?.length) { |
|
|
|
|
testFiles = allTests.current.map((testFile: any) => { return {'fileName': testFile, 'checked': true }}) |
|
|
|
|
if (allTests.current?.length) { |
|
|
|
|
testFiles = allTests.current.map((testFile: any) => { return { 'fileName': testFile, 'checked': true } }) |
|
|
|
|
setCheckSelectAll(true) |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
@ -644,8 +648,8 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
name="utPath" |
|
|
|
|
value={inputPathValue} |
|
|
|
|
title="Press 'Enter' to change the path for test files." |
|
|
|
|
style= {{ backgroundImage: "var(--primary)"}} |
|
|
|
|
onKeyUp= {handleTestDirInput} |
|
|
|
|
style={{ backgroundImage: "var(--primary)" }} |
|
|
|
|
onKeyUp={handleTestDirInput} |
|
|
|
|
onChange={handleEnter} |
|
|
|
|
/> |
|
|
|
|
<button |
|
|
|
@ -694,7 +698,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
data-id="testTabCheckAllTests" |
|
|
|
|
onClick={checkAll} |
|
|
|
|
checked={checkSelectAll} |
|
|
|
|
onChange={() => {}} // eslint-disable-line
|
|
|
|
|
onChange={() => { }} // eslint-disable-line
|
|
|
|
|
/> |
|
|
|
|
<label className="text-nowrap pl-2 mb-0" htmlFor="checkAllTests"> Select all </label> |
|
|
|
|
</div> |
|
|
|
@ -702,12 +706,12 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { |
|
|
|
|
const elemId = `singleTest${testFileObj.fileName}` |
|
|
|
|
return ( |
|
|
|
|
<div className="d-flex align-items-center py-1" key={index}> |
|
|
|
|
<input className="singleTest" id={elemId} onChange={(e) => toggleCheckbox(e.target.checked, index)} type="checkbox" checked={testFileObj.checked}/> |
|
|
|
|
<input className="singleTest" id={elemId} onChange={(e) => toggleCheckbox(e.target.checked, index)} type="checkbox" checked={testFileObj.checked} /> |
|
|
|
|
<label className="singleTestLabel text-nowrap pl-2 mb-0" htmlFor={elemId}>{testFileObj.fileName}</label> |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
: "No test file available" } </div> |
|
|
|
|
: "No test file available"} </div> |
|
|
|
|
<div className="align-items-start flex-column mt-2 mx-3 mb-0"> |
|
|
|
|
<span className='text-info h6' hidden={progressBarHidden}>Progress: {readyTestsNumber} finished (of {runningTestsNumber})</span> |
|
|
|
|
<label className="text-warning h6" data-id="testTabTestsExecutionStopped" hidden={testsExecutionStoppedHidden}>The test execution has been stopped</label> |
|
|
|
|