|
|
@ -14,13 +14,6 @@ interface TestObject { |
|
|
|
checked: boolean |
|
|
|
checked: boolean |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface TestSummary { |
|
|
|
|
|
|
|
filename: string |
|
|
|
|
|
|
|
passed: number |
|
|
|
|
|
|
|
failed: number |
|
|
|
|
|
|
|
timeTaken: any |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const SolidityUnitTesting = (props: any) => { |
|
|
|
export const SolidityUnitTesting = (props: any) => { |
|
|
|
|
|
|
|
|
|
|
|
const {helper, testTab} = props |
|
|
|
const {helper, testTab} = props |
|
|
@ -37,16 +30,12 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
|
|
|
|
|
|
|
|
const [checkSelectAll, setCheckSelectAll] = useState(true) |
|
|
|
const [checkSelectAll, setCheckSelectAll] = useState(true) |
|
|
|
const [testsOutput, setTestsOutput] = useState<Element[]>([]) |
|
|
|
const [testsOutput, setTestsOutput] = useState<Element[]>([]) |
|
|
|
// let [testsSummary, setTestsSummary] = useState<TestSummary>()
|
|
|
|
|
|
|
|
const [testsSummaryHidden, setTestsSummaryHidden] = useState('hidden') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) |
|
|
|
const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) |
|
|
|
const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) |
|
|
|
const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let [testFiles, setTestFiles] = useState<TestObject[]>([]) |
|
|
|
let [testFiles, setTestFiles] = useState<TestObject[]>([]) |
|
|
|
const [pathOptions, setPathOptions] = useState(['']) |
|
|
|
const [pathOptions, setPathOptions] = useState(['']) |
|
|
|
// let [allTests, setAllTests] = useState([])
|
|
|
|
|
|
|
|
let [selectedTests, setSelectedTests] = useState<string[]>([]) |
|
|
|
let [selectedTests, setSelectedTests] = useState<string[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
const [inputPathValue, setInputPathValue] = useState('tests') |
|
|
|
const [inputPathValue, setInputPathValue] = useState('tests') |
|
|
@ -59,15 +48,10 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
|
|
|
|
|
|
|
|
let allTests: any = [] |
|
|
|
let allTests: any = [] |
|
|
|
|
|
|
|
|
|
|
|
let testSuite: any |
|
|
|
|
|
|
|
let testSuites: any |
|
|
|
|
|
|
|
let runningTestFileName: any |
|
|
|
let runningTestFileName: any |
|
|
|
let runningTests: any |
|
|
|
let runningTests: any = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let testsResultByFilename:Record<string, any> = {} |
|
|
|
let [testsResultByFilename, setTestsResultByFilename] = useState<Record<string, any>>({}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const trimTestDirInput = (input:string) => { |
|
|
|
const trimTestDirInput = (input:string) => { |
|
|
|
if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/') |
|
|
|
if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/') |
|
|
@ -127,10 +111,7 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const handleTestDirInput = async (e: any) => { |
|
|
|
const handleTestDirInput = async (e: any) => { |
|
|
|
console.log('handleTestDirInput--e-->', e.target) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let testDirInput = trimTestDirInput(e.target.value) |
|
|
|
let testDirInput = trimTestDirInput(e.target.value) |
|
|
|
console.log('handleTestDirInput--e-->', testDirInput) |
|
|
|
|
|
|
|
testDirInput = helper.removeMultipleSlashes(testDirInput) |
|
|
|
testDirInput = helper.removeMultipleSlashes(testDirInput) |
|
|
|
if (testDirInput !== '/') testDirInput = helper.removeTrailingSlashes(testDirInput) |
|
|
|
if (testDirInput !== '/') testDirInput = helper.removeTrailingSlashes(testDirInput) |
|
|
|
setInputPathValue(testDirInput) |
|
|
|
setInputPathValue(testDirInput) |
|
|
@ -169,7 +150,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const handleEnter = async(e:any) => { |
|
|
|
const handleEnter = async(e:any) => { |
|
|
|
console.log('handleEnter --e-->', e) |
|
|
|
|
|
|
|
let inputPath = e.target.value |
|
|
|
let inputPath = e.target.value |
|
|
|
inputPath = helper.removeMultipleSlashes(trimTestDirInput(inputPath)) |
|
|
|
inputPath = helper.removeMultipleSlashes(trimTestDirInput(inputPath)) |
|
|
|
setInputPathValue(inputPath) |
|
|
|
setInputPathValue(inputPath) |
|
|
@ -191,8 +171,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
setDisableCreateButton(true) |
|
|
|
setDisableCreateButton(true) |
|
|
|
setDisableGenerateButton(false) |
|
|
|
setDisableGenerateButton(false) |
|
|
|
testTabLogic.setCurrentPath(inputPath) |
|
|
|
testTabLogic.setCurrentPath(inputPath) |
|
|
|
console.log('path-->', path) |
|
|
|
|
|
|
|
console.log('inputPath-->', inputPath) |
|
|
|
|
|
|
|
updateRunAction() |
|
|
|
updateRunAction() |
|
|
|
updateForNewCurrent() |
|
|
|
updateForNewCurrent() |
|
|
|
pathOptions.push(inputPath) |
|
|
|
pathOptions.push(inputPath) |
|
|
@ -233,9 +211,10 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
await testTab.call('editor', 'discardHighlight') |
|
|
|
await testTab.call('editor', 'discardHighlight') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const highlightLocation = async (location: any, runningTests: any, fileName: any) => { |
|
|
|
const highlightLocation = async (location: any, fileName: any) => { |
|
|
|
console.log('Inside highlightLocation---runningTests-->', runningTests) |
|
|
|
console.log('Inside highlightLocation---runningTests-->', runningTests) |
|
|
|
console.log('Inside highlightLocation---fileName-->', fileName) |
|
|
|
console.log('Inside highlightLocation---fileName-->', fileName) |
|
|
|
|
|
|
|
console.log('Inside highlightLocation---location-->', location) |
|
|
|
if (location) { |
|
|
|
if (location) { |
|
|
|
var split = location.split(':') |
|
|
|
var split = location.split(':') |
|
|
|
var file = split[2] |
|
|
|
var file = split[2] |
|
|
@ -255,7 +234,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
|
|
|
|
|
|
|
|
const showTestsResult = () => { |
|
|
|
const showTestsResult = () => { |
|
|
|
console.log('runningTests---->', runningTests) |
|
|
|
console.log('runningTests---->', runningTests) |
|
|
|
// setTestsOutput([])
|
|
|
|
|
|
|
|
let filenames = Object.keys(testsResultByFilename) |
|
|
|
let filenames = Object.keys(testsResultByFilename) |
|
|
|
for(const filename of filenames) { |
|
|
|
for(const filename of filenames) { |
|
|
|
const fileTestsResult = testsResultByFilename[filename] |
|
|
|
const fileTestsResult = testsResultByFilename[filename] |
|
|
@ -292,7 +270,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
// show tests
|
|
|
|
// show tests
|
|
|
|
for(const test of tests) { |
|
|
|
for(const test of tests) { |
|
|
|
console.log('test---->', test) |
|
|
|
|
|
|
|
if(!test.rendered) { |
|
|
|
if(!test.rendered) { |
|
|
|
let debugBtn |
|
|
|
let debugBtn |
|
|
|
if (test.debugTxHash) { |
|
|
|
if (test.debugTxHash) { |
|
|
@ -326,7 +303,7 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
const testFailCard1: any = (<div |
|
|
|
const testFailCard1: any = (<div |
|
|
|
className="bg-light mb-2 px-2 testLog d-flex flex-column text-danger border-0" |
|
|
|
className="bg-light mb-2 px-2 testLog d-flex flex-column text-danger border-0" |
|
|
|
id={"UTContext" + test.context} |
|
|
|
id={"UTContext" + test.context} |
|
|
|
onClick={() => highlightLocation(test.location, runningTests, test.filename)} |
|
|
|
onClick={() => highlightLocation(test.location, test.filename)} |
|
|
|
> |
|
|
|
> |
|
|
|
<div className="d-flex my-1 align-items-start justify-content-between"> |
|
|
|
<div className="d-flex my-1 align-items-start justify-content-between"> |
|
|
|
<span> ✘ {test.value}</span> |
|
|
|
<span> ✘ {test.value}</span> |
|
|
@ -343,7 +320,7 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
const testFailCard2: any = (<div |
|
|
|
const testFailCard2: any = (<div |
|
|
|
className="bg-light mb-2 px-2 testLog d-flex flex-column text-danger border-0" |
|
|
|
className="bg-light mb-2 px-2 testLog d-flex flex-column text-danger border-0" |
|
|
|
id={"UTContext" + test.context} |
|
|
|
id={"UTContext" + test.context} |
|
|
|
onClick={() => highlightLocation(test.location, runningTests, test.filename)} |
|
|
|
onClick={() => highlightLocation(test.location, test.filename)} |
|
|
|
> |
|
|
|
> |
|
|
|
<div className="d-flex my-1 align-items-start justify-content-between">
|
|
|
|
<div className="d-flex my-1 align-items-start justify-content-between">
|
|
|
|
<span> ✘ {test.value}</span> |
|
|
|
<span> ✘ {test.value}</span> |
|
|
@ -396,10 +373,9 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const testCallback = (result: any, runningTests: any) => { |
|
|
|
const testCallback = (result: any) => { |
|
|
|
console.log('result--------------in testCallback->', result) |
|
|
|
console.log('result--------------in testCallback->', result) |
|
|
|
console.log('testsResultByFilename--------============------in testCallback->', testsResultByFilename) |
|
|
|
console.log('testsResultByFilename--------============------in testCallback->', testsResultByFilename) |
|
|
|
runningTests = runningTests |
|
|
|
|
|
|
|
if(result.filename) { |
|
|
|
if(result.filename) { |
|
|
|
if(!testsResultByFilename[result.filename]) { |
|
|
|
if(!testsResultByFilename[result.filename]) { |
|
|
|
testsResultByFilename[result.filename] = {} |
|
|
|
testsResultByFilename[result.filename] = {} |
|
|
@ -428,7 +404,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
console.log('result---------------------------in updateFinalResult->', result, filename) |
|
|
|
console.log('result---------------------------in updateFinalResult->', result, filename) |
|
|
|
console.log('testsResultByFilename---------------------------in updateFinalResult->', testsResultByFilename) |
|
|
|
console.log('testsResultByFilename---------------------------in updateFinalResult->', testsResultByFilename) |
|
|
|
++readyTestsNumber |
|
|
|
++readyTestsNumber |
|
|
|
setTestsSummaryHidden('visible') |
|
|
|
|
|
|
|
// if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) {
|
|
|
|
// if (!result && (_errors && (_errors.errors || (Array.isArray(_errors) && (_errors[0].message || _errors[0].formattedMessage))))) {
|
|
|
|
// this.testCallback({ type: 'contract', filename })
|
|
|
|
// this.testCallback({ type: 'contract', filename })
|
|
|
|
// this.currentErrors = _errors.errors
|
|
|
|
// this.currentErrors = _errors.errors
|
|
|
@ -448,15 +423,7 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } |
|
|
|
const testsSummary = { filename, passed: result.totalPassing, failed: result.totalFailing, timeTaken: totalTime, rendered: false } |
|
|
|
testsResultByFilename[filename]['summary']= testsSummary |
|
|
|
testsResultByFilename[filename]['summary']= testsSummary |
|
|
|
showTestsResult() |
|
|
|
showTestsResult() |
|
|
|
// setTestsSummary(testsSummary)
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// fix for displaying right label for multiple tests (testsuites) in a single file
|
|
|
|
|
|
|
|
// this.testSuites.forEach(testSuite => {
|
|
|
|
|
|
|
|
// this.testSuite = testSuite
|
|
|
|
|
|
|
|
// this.runningTestFileName = this.cleanFileName(filename, this.testSuite)
|
|
|
|
|
|
|
|
// this.outputHeader = document.querySelector(`#${this.runningTestFileName}`)
|
|
|
|
|
|
|
|
// this.setHeader(true)
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// result.errors.forEach((error, index) => {
|
|
|
|
// result.errors.forEach((error, index) => {
|
|
|
|
// this.testSuite = error.context
|
|
|
|
// this.testSuite = error.context
|
|
|
@ -499,7 +466,7 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
} |
|
|
|
} |
|
|
|
// this.resultStatistics.hidden = false
|
|
|
|
// this.resultStatistics.hidden = false
|
|
|
|
testTab.fileManager.readFile(testFilePath).then((content: any) => { |
|
|
|
testTab.fileManager.readFile(testFilePath).then((content: any) => { |
|
|
|
const runningTests: any = {} |
|
|
|
runningTests = {} |
|
|
|
runningTests[testFilePath] = { content } |
|
|
|
runningTests[testFilePath] = { content } |
|
|
|
const { currentVersion, evmVersion, optimize, runs, isUrl } = testTab.compileTab.getCurrentCompilerConfig() |
|
|
|
const { currentVersion, evmVersion, optimize, runs, isUrl } = testTab.compileTab.getCurrentCompilerConfig() |
|
|
|
const currentCompilerUrl = isUrl ? currentVersion : urlFromVersion(currentVersion) |
|
|
|
const currentCompilerUrl = isUrl ? currentVersion : urlFromVersion(currentVersion) |
|
|
@ -517,7 +484,7 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
testTab.testRunner.runTestSources( |
|
|
|
testTab.testRunner.runTestSources( |
|
|
|
runningTests, |
|
|
|
runningTests, |
|
|
|
compilerConfig, |
|
|
|
compilerConfig, |
|
|
|
(result: any) => testCallback(result, runningTests), |
|
|
|
(result: any) => testCallback(result), |
|
|
|
(_err: any, result: any, cb: any) => resultsCallback(_err, result, cb), |
|
|
|
(_err: any, result: any, cb: any) => resultsCallback(_err, result, cb), |
|
|
|
deployCb, |
|
|
|
deployCb, |
|
|
|
(error: any, result: any) => { |
|
|
|
(error: any, result: any) => { |
|
|
@ -528,7 +495,7 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
}, { testFilePath } |
|
|
|
}, { testFilePath } |
|
|
|
) |
|
|
|
) |
|
|
|
}).catch((error: any) => { |
|
|
|
}).catch((error: any) => { |
|
|
|
console.log('Error in runTest---->', error) |
|
|
|
console.log(error) |
|
|
|
if (error) return // eslint-disable-line
|
|
|
|
if (error) return // eslint-disable-line
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -555,7 +522,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const updateRunAction = (currentFile : any = null) => { |
|
|
|
const updateRunAction = (currentFile : any = null) => { |
|
|
|
console.log('updateRunAction --currentFile-->', currentFile) |
|
|
|
|
|
|
|
const isSolidityActive = testTab.appManager.isActive('solidity') |
|
|
|
const isSolidityActive = testTab.appManager.isActive('solidity') |
|
|
|
if (!isSolidityActive || !selectedTests?.length) { |
|
|
|
if (!isSolidityActive || !selectedTests?.length) { |
|
|
|
setDisableRunButton(true) |
|
|
|
setDisableRunButton(true) |
|
|
@ -568,7 +534,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const stopTests = () => { |
|
|
|
const stopTests = () => { |
|
|
|
console.log('stopTests') |
|
|
|
|
|
|
|
setHasBeenStopped(true) |
|
|
|
setHasBeenStopped(true) |
|
|
|
setStopButtonLabel('Stopping') |
|
|
|
setStopButtonLabel('Stopping') |
|
|
|
setDisableStopButton(true) |
|
|
|
setDisableStopButton(true) |
|
|
@ -584,7 +549,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
testFiles[index].checked = eChecked |
|
|
|
testFiles[index].checked = eChecked |
|
|
|
setTestFiles(testFiles) |
|
|
|
setTestFiles(testFiles) |
|
|
|
selectedTests = getCurrentSelectedTests() |
|
|
|
selectedTests = getCurrentSelectedTests() |
|
|
|
console.log('selectedTests----->', selectedTests) |
|
|
|
|
|
|
|
setSelectedTests(selectedTests) |
|
|
|
setSelectedTests(selectedTests) |
|
|
|
if (eChecked) { |
|
|
|
if (eChecked) { |
|
|
|
setCheckSelectAll(true) |
|
|
|
setCheckSelectAll(true) |
|
|
@ -614,7 +578,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const updateTestFileList = () => { |
|
|
|
const updateTestFileList = () => { |
|
|
|
console.log('updateTestFileList--tests->', allTests) |
|
|
|
|
|
|
|
if(allTests?.length) { |
|
|
|
if(allTests?.length) { |
|
|
|
testFiles = allTests.map((testFile: any) => { return {'fileName': testFile, 'checked': true }}) |
|
|
|
testFiles = allTests.map((testFile: any) => { return {'fileName': testFile, 'checked': true }}) |
|
|
|
setCheckSelectAll(true) |
|
|
|
setCheckSelectAll(true) |
|
|
@ -727,12 +690,6 @@ export const SolidityUnitTesting = (props: any) => { |
|
|
|
<label className="text-danger h6" data-id="testTabTestsExecutionStoppedError" hidden={testsExecutionStoppedErrorHidden}>The test execution has been stopped because of error(s) in your test file</label> |
|
|
|
<label className="text-danger h6" data-id="testTabTestsExecutionStoppedError" hidden={testsExecutionStoppedErrorHidden}>The test execution has been stopped because of error(s) in your test file</label> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div>{testsOutput}</div> |
|
|
|
<div>{testsOutput}</div> |
|
|
|
{/* <div className="d-flex alert-secondary mb-3 p-3 flex-column" style= {{visibility: testsSummaryHidden} as CSSProperties }> |
|
|
|
|
|
|
|
<span className="font-weight-bold">{testsSummary && testsSummary.filename ? `Result for ${testsSummary.filename}` : ''}</span> |
|
|
|
|
|
|
|
<span className="text-success">{testsSummary && testsSummary.passed >= 0 ? `Passed: ${testsSummary.passed}` : ''}</span> |
|
|
|
|
|
|
|
<span className="text-danger">{testsSummary && testsSummary.failed >= 0 ? `Failed: ${testsSummary.failed}` : ''}</span> |
|
|
|
|
|
|
|
<span>{testsSummary && testsSummary.timeTaken ? `Time Taken: ${testsSummary.timeTaken}` : ''}</span> |
|
|
|
|
|
|
|
</div> */} |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) |
|
|
|
) |
|
|
|