|
|
@ -103,99 +103,105 @@ module.exports = class TestTab extends ApiFactory { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render () { |
|
|
|
checkAll (event) { |
|
|
|
const self = this |
|
|
|
const self = this |
|
|
|
self.testsOutput = yo`<div class="${css.container} border border-primary border-right-0 border-left-0 border-bottom-0" hidden='true' id="tests"></div>` |
|
|
|
let checkBoxes = self._view.el.querySelectorAll('.singleTest') |
|
|
|
self.testsSummary = yo`<div class="${css.container} border border-primary border-right-0 border-left-0 border-bottom-0" hidden='true' id="tests"></div>` |
|
|
|
const checkboxesLabels = self._view.el.querySelectorAll('.singleTestLabel') |
|
|
|
|
|
|
|
// checks/unchecks all
|
|
|
|
var testCallback = function (result) { |
|
|
|
for (let i = 0; i < checkBoxes.length; i++) { |
|
|
|
self.testsOutput.hidden = false |
|
|
|
checkBoxes[i].checked = event.target.checked |
|
|
|
if (result.type === 'contract') { |
|
|
|
self.toggleCheckbox(event.target.checked, checkboxesLabels[i].innerText) |
|
|
|
self.testsOutput.appendChild(yo`<div class="${css.outputTitle}">${result.filename} (${result.value})</div>`) |
|
|
|
|
|
|
|
} else if (result.type === 'testPass') { |
|
|
|
|
|
|
|
self.testsOutput.appendChild(yo`<div class="${css.testPass} ${css.testLog} bg-success">✓ (${result.value})</div>`) |
|
|
|
|
|
|
|
} else if (result.type === 'testFailure') { |
|
|
|
|
|
|
|
self.testsOutput.appendChild(yo`<div class="${css.testFailure} ${css.testLog} bg-danger">✘ (${result.value})</div>`) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var resultsCallback = function (_err, result, cb) { |
|
|
|
testCallback (result) { |
|
|
|
// total stats for the test
|
|
|
|
const self = this |
|
|
|
// result.passingNum
|
|
|
|
self.testsOutput.hidden = false |
|
|
|
// result.failureNum
|
|
|
|
if (result.type === 'contract') { |
|
|
|
// result.timePassed
|
|
|
|
self.testsOutput.appendChild(yo`<div class=${css.outputTitle}>${result.filename} (${result.value})</div>`) |
|
|
|
cb() |
|
|
|
} else if (result.type === 'testPass') { |
|
|
|
|
|
|
|
self.testsOutput.appendChild(yo`<div class='${css.testPass} ${css.testLog}'>✓ (${result.value})</div>`) |
|
|
|
|
|
|
|
} else if (result.type === 'testFailure') { |
|
|
|
|
|
|
|
self.testsOutput.appendChild(yo`<div class='${css.testFailure} ${css.testLog}'>✘ (${result.value})</div>`) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var updateFinalResult = function (_err, result, filename) { |
|
|
|
resultsCallback (_err, result, cb) { |
|
|
|
self.testsSummary.hidden = false |
|
|
|
// total stats for the test
|
|
|
|
if (_err) { |
|
|
|
// result.passingNum
|
|
|
|
self.testsSummary.appendChild(yo`<div class="${css.testFailureSummary} text-danger" >${_err.message}</div>`) |
|
|
|
// result.failureNum
|
|
|
|
return |
|
|
|
// result.timePassed
|
|
|
|
} |
|
|
|
cb() |
|
|
|
self.testsSummary.appendChild(yo`<div class=${css.summaryTitle}> ${filename} </div>`) |
|
|
|
} |
|
|
|
if (result.totalPassing > 0) { |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<div class="text-success">${result.totalPassing} passing (${result.totalTime}s)</div>`) |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<br>`) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (result.totalFailing > 0) { |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<div class="text-danger" >${result.totalFailing} failing</div>`) |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<br>`) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result.errors.forEach((error, index) => { |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<div class="text-danger" >${error.context} - ${error.value} </div>`) |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<div class="${css.testFailureSummary} text-danger" >${error.message}</div>`) |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<br>`) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function runTest (testFilePath, callback) { |
|
|
|
updateFinalResult (_err, result, filename) { |
|
|
|
self.fileManager.fileProviderOf(testFilePath).get(testFilePath, (error, content) => { |
|
|
|
const self = this |
|
|
|
if (!error) { |
|
|
|
self.testsSummary.hidden = false |
|
|
|
var runningTest = {} |
|
|
|
if (_err) { |
|
|
|
runningTest[testFilePath] = { content } |
|
|
|
self.testsSummary.appendChild(yo`<div class=${css.testFailureSummary} >${_err.message}</div>`) |
|
|
|
remixTests.runTestSources(runningTest, testCallback, resultsCallback, (error, result) => { |
|
|
|
return |
|
|
|
updateFinalResult(error, result, testFilePath) |
|
|
|
|
|
|
|
callback(error) |
|
|
|
|
|
|
|
}, (url, cb) => { |
|
|
|
|
|
|
|
return self.compileTab.compileTabLogic.importFileCb(url, cb) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<div class=${css.summaryTitle}> ${filename} </div>`) |
|
|
|
function checkAll (event) { |
|
|
|
if (result.totalPassing > 0) { |
|
|
|
let checkBoxes = self._view.el.querySelectorAll('.singleTest') |
|
|
|
self.testsSummary.appendChild(yo`<div>${result.totalPassing} passing (${result.totalTime}s)</div>`) |
|
|
|
const checkboxesLabels = self._view.el.querySelectorAll('.singleTestLabel') |
|
|
|
self.testsSummary.appendChild(yo`<br>`) |
|
|
|
// checks/unchecks all
|
|
|
|
|
|
|
|
for (let i = 0; i < checkBoxes.length; i++) { |
|
|
|
|
|
|
|
checkBoxes[i].checked = event.target.checked |
|
|
|
|
|
|
|
self.toggleCheckbox(event.target.checked, checkboxesLabels[i].innerText) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (result.totalFailing > 0) { |
|
|
|
var runTests = function () { |
|
|
|
self.testsSummary.appendChild(yo`<div>${result.totalFailing} failing</div>`) |
|
|
|
self.testsOutput.innerHTML = 'Running tests ...' |
|
|
|
self.testsSummary.appendChild(yo`<br>`) |
|
|
|
self.testsSummary.innerHTML = '' |
|
|
|
|
|
|
|
var tests = self.data.selectedTests |
|
|
|
|
|
|
|
async.eachOfSeries(tests, (value, key, callback) => { runTest(value, callback) }) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
result.errors.forEach((error, index) => { |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<div>${error.context} - ${error.value} </div>`) |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<div class=${css.testFailureSummary} >${error.message}</div>`) |
|
|
|
|
|
|
|
self.testsSummary.appendChild(yo`<br>`) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var generateTestFile = function () { |
|
|
|
runTest (testFilePath, callback) { |
|
|
|
var fileManager = self.fileManager |
|
|
|
const self = this |
|
|
|
var path = fileManager.currentPath() |
|
|
|
self.fileManager.fileProviderOf(testFilePath).get(testFilePath, (error, content) => { |
|
|
|
var fileProvider = fileManager.fileProviderOf(path) |
|
|
|
if (!error) { |
|
|
|
if (fileProvider) { |
|
|
|
var runningTest = {} |
|
|
|
helper.createNonClashingNameWithPrefix(path + '/test.sol', fileProvider, '_test', (error, newFile) => { |
|
|
|
runningTest[testFilePath] = { content } |
|
|
|
if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) |
|
|
|
remixTests.runTestSources(runningTest, self.testCallback, self.resultsCallback, (error, result) => { |
|
|
|
if (!fileProvider.set(newFile, testContractSample)) { |
|
|
|
self.updateFinalResult(error, result, testFilePath) |
|
|
|
modalDialogCustom.alert('Failed to create test file ' + newFile) |
|
|
|
callback(error) |
|
|
|
} else { |
|
|
|
}, (url, cb) => { |
|
|
|
fileManager.switchFile(newFile) |
|
|
|
return self.compileTab.compileTabLogic.importFileCb(url, cb) |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runTests () { |
|
|
|
|
|
|
|
const self = this |
|
|
|
|
|
|
|
self.testsOutput.innerHTML = '' |
|
|
|
|
|
|
|
self.testsSummary.innerHTML = '' |
|
|
|
|
|
|
|
var tests = self.data.selectedTests |
|
|
|
|
|
|
|
async.eachOfSeries(tests, (value, key, callback) => { self.runTest(value, callback) }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generateTestFile () { |
|
|
|
|
|
|
|
const self = this |
|
|
|
|
|
|
|
var fileManager = self.fileManager |
|
|
|
|
|
|
|
var path = fileManager.currentPath() |
|
|
|
|
|
|
|
var fileProvider = fileManager.fileProviderOf(path) |
|
|
|
|
|
|
|
if (fileProvider) { |
|
|
|
|
|
|
|
helper.createNonClashingNameWithPrefix(path + '/test.sol', fileProvider, '_test', (error, newFile) => { |
|
|
|
|
|
|
|
if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error) |
|
|
|
|
|
|
|
if (!fileProvider.set(newFile, testContractSample)) { |
|
|
|
|
|
|
|
modalDialogCustom.alert('Failed to create test file ' + newFile) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fileManager.switchFile(newFile) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render () { |
|
|
|
|
|
|
|
const self = this |
|
|
|
|
|
|
|
this.testsOutput = yo`<div class=${css.container} hidden='true' id="tests"></div>` |
|
|
|
|
|
|
|
this.testsSummary = yo`<div class=${css.container} hidden='true' id="tests"></div>` |
|
|
|
|
|
|
|
|
|
|
|
var el = yo` |
|
|
|
var el = yo` |
|
|
|
<div class="${css.testTabView} card" id="testView"> |
|
|
|
<div class="${css.testTabView} card" id="testView"> |
|
|
@ -208,17 +214,16 @@ module.exports = class TestTab extends ApiFactory { |
|
|
|
<br/> |
|
|
|
<br/> |
|
|
|
For more details, see |
|
|
|
For more details, see |
|
|
|
How to test smart contracts guide in our documentation. |
|
|
|
How to test smart contracts guide in our documentation. |
|
|
|
<br/> |
|
|
|
<div class="${css.generateTestFile}" onclick="${self.generateTestFile(self)}">Generate test file</div> |
|
|
|
<button class="${css.generateTestFile} btn btn-primary m-1" onclick="${generateTestFile}">Generate test file</button> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div class="${css.tests}"> |
|
|
|
<div class="${css.tests}"> |
|
|
|
${self.testList} |
|
|
|
${self.testList} |
|
|
|
<div class="${css.buttons} btn-group"> |
|
|
|
<div class="${css.buttons}"> |
|
|
|
<button class="${css.runButton} btn btn-primary m-1" onclick="${runTests}">Run Tests</button> |
|
|
|
<div class="${css.runButton}" onclick="${self.runTests.bind(self)}">Run Tests</div> |
|
|
|
<label class="${css.label}" for="checkAllTests"> |
|
|
|
<label class="${css.label}" for="checkAllTests"> |
|
|
|
<input id="checkAllTests" |
|
|
|
<input id="checkAllTests" |
|
|
|
type="checkbox" |
|
|
|
type="checkbox" |
|
|
|
onclick="${function (event) { checkAll(event) }}" |
|
|
|
onclick="${(event) => { this.checkAll(event) }}" |
|
|
|
checked="true" |
|
|
|
checked="true" |
|
|
|
> |
|
|
|
> |
|
|
|
Check/Uncheck all |
|
|
|
Check/Uncheck all |
|
|
|