diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index daeea0562c..a58a1d4f11 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -33,69 +33,62 @@ module.exports = class TestTab extends ApiFactory { } listenToEvents () { - const self = this - - self.filePanel.event.register('newTestFileCreated', file => { - var testList = self.view.querySelector("[class^='testList']") + this.filePanel.event.register('newTestFileCreated', file => { + var testList = this.view.querySelector("[class^='testList']") var test = yo`` testList.appendChild(test) - self.data.allTests.push(file) - self.data.selectedTests.push(file) + this.data.allTests.push(file) + this.data.selectedTests.push(file) }) - self.fileManager.event.register('currentFileChanged', (file, provider) => { - self.getTests(self, (error, tests) => { + this.fileManager.event.register('currentFileChanged', (file, provider) => { + this.getTests((error, tests) => { if (error) return tooltip(error) - self.data.allTests = tests - self.data.selectedTests = [...self.data.allTests] + this.data.allTests = tests + this.data.selectedTests = [...this.data.allTests] if (!tests.length) { - yo.update(self.testList, yo`
No test file available
`) + yo.update(this.testList, yo`
No test file available
`) } else { - yo.update(self.testList, yo`
${self.listTests()}
`) + yo.update(this.testList, yo`
${this.listTests()}
`) } - if (!self.testsOutput || !self.testsSummary) return + if (!this.testsOutput || !this.testsSummary) return - self.testsOutput.hidden = true - self.testsSummary.hidden = true - self.testsOutput.innerHTML = '' - self.testsSummary.innerHTML = '' + this.testsOutput.hidden = true + this.testsSummary.hidden = true + this.testsOutput.innerHTML = '' + this.testsSummary.innerHTML = '' }) }) } - getTests (self, cb) { - var path = self.fileManager.currentPath() + getTests (cb) { + var path = this.fileManager.currentPath() if (!path) return cb(null, []) - var provider = self.fileManager.fileProviderOf(path) + var provider = this.fileManager.fileProviderOf(path) if (!provider) return cb(null, []) var tests = [] - self.fileManager.filesFromPath(path, (error, files) => { + this.fileManager.filesFromPath(path, (error, files) => { if (error) return cb(error) - if (!error) { - for (var file in files) { - if (/.(_test.sol)$/.exec(file)) tests.push(provider.type + '/' + file) - } - cb(null, tests) + for (var file in files) { + if (/.(_test.sol)$/.exec(file)) tests.push(provider.type + '/' + file) } + cb(null, tests) }) } listTests () { - const self = this - var tests = self.data.allTests - return tests.map(test => yo``) + return this.data.allTests.map(test => yo``) } toggleCheckbox (eChecked, test) { - const self = this - if (!self.data.selectedTests) { - self.data.selectedTests = self._view.el.querySelectorAll('.singleTest:checked') + if (!this.data.selectedTests) { + this.data.selectedTests = this._view.el.querySelectorAll('.singleTest:checked') } - let selectedTests = self.data.selectedTests + let selectedTests = this.data.selectedTests selectedTests = eChecked ? [...selectedTests, test] : selectedTests.filter(el => el !== test) - self.data.selectedTests = selectedTests - let checkAll = self._view.el.querySelector('[id="checkAllTests"]') + this.data.selectedTests = selectedTests + let checkAll = this._view.el.querySelector('[id="checkAllTests"]') if (eChecked) { checkAll.checked = true } else if (!selectedTests.length) { @@ -104,25 +97,23 @@ module.exports = class TestTab extends ApiFactory { } checkAll (event) { - const self = this - let checkBoxes = self._view.el.querySelectorAll('.singleTest') - const checkboxesLabels = self._view.el.querySelectorAll('.singleTestLabel') + let checkBoxes = this._view.el.querySelectorAll('.singleTest') + const checkboxesLabels = this._view.el.querySelectorAll('.singleTestLabel') // 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) + this.toggleCheckbox(event.target.checked, checkboxesLabels[i].innerText) } } testCallback (result) { - const self = this - self.testsOutput.hidden = false + this.testsOutput.hidden = false if (result.type === 'contract') { - self.testsOutput.appendChild(yo`
${result.filename} (${result.value})
`) + this.testsOutput.appendChild(yo`
${result.filename} (${result.value})
`) } else if (result.type === 'testPass') { - self.testsOutput.appendChild(yo`
✓ (${result.value})
`) + this.testsOutput.appendChild(yo`
✓ (${result.value})
`) } else if (result.type === 'testFailure') { - self.testsOutput.appendChild(yo`
✘ (${result.value})
`) + this.testsOutput.appendChild(yo`
✘ (${result.value})
`) } } @@ -135,71 +126,63 @@ module.exports = class TestTab extends ApiFactory { } updateFinalResult (_err, result, filename) { - const self = this - self.testsSummary.hidden = false + this.testsSummary.hidden = false if (_err) { - self.testsSummary.appendChild(yo`
${_err.message}
`) + this.testsSummary.appendChild(yo`
${_err.message}
`) return } - self.testsSummary.appendChild(yo`
${filename}
`) + this.testsSummary.appendChild(yo`
${filename}
`) if (result.totalPassing > 0) { - self.testsSummary.appendChild(yo`
${result.totalPassing} passing (${result.totalTime}s)
`) - self.testsSummary.appendChild(yo`
`) + this.testsSummary.appendChild(yo`
${result.totalPassing} passing (${result.totalTime}s)
`) + this.testsSummary.appendChild(yo`
`) } if (result.totalFailing > 0) { - self.testsSummary.appendChild(yo`
${result.totalFailing} failing
`) - self.testsSummary.appendChild(yo`
`) + this.testsSummary.appendChild(yo`
${result.totalFailing} failing
`) + this.testsSummary.appendChild(yo`
`) } result.errors.forEach((error, index) => { - self.testsSummary.appendChild(yo`
${error.context} - ${error.value}
`) - self.testsSummary.appendChild(yo`
${error.message}
`) - self.testsSummary.appendChild(yo`
`) + this.testsSummary.appendChild(yo`
${error.context} - ${error.value}
`) + this.testsSummary.appendChild(yo`
${error.message}
`) + this.testsSummary.appendChild(yo`
`) }) } runTest (testFilePath, callback) { - const self = this - self.fileManager.fileProviderOf(testFilePath).get(testFilePath, (error, content) => { - if (!error) { - var runningTest = {} - runningTest[testFilePath] = { content } - remixTests.runTestSources(runningTest, self.testCallback, self.resultsCallback, (error, result) => { - self.updateFinalResult(error, result, testFilePath) - callback(error) - }, (url, cb) => { - return self.compileTab.compileTabLogic.importFileCb(url, cb) - }) - } + this.fileManager.fileProviderOf(testFilePath).get(testFilePath, (error, content) => { + if (error) return + var runningTest = {} + runningTest[testFilePath] = { content } + remixTests.runTestSources(runningTest, this.testCallback, this.resultsCallback, (error, result) => { + this.updateFinalResult(error, result, testFilePath) + callback(error) + }, (url, cb) => { + return this.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) }) + this.testsOutput.innerHTML = '' + this.testsSummary.innerHTML = '' + var tests = this.data.selectedTests + async.eachOfSeries(tests, (value, key, callback) => { this.runTest(value, callback) }) } generateTestFile () { - const self = this - var fileManager = self.fileManager + var fileManager = this.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) - } - }) - } + if (!fileProvider) return + 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)) { + return modalDialogCustom.alert('Failed to create test file ' + newFile) + } + fileManager.switchFile(newFile) + }) } render () { - const self = this this.testsOutput = yo`` this.testsSummary = yo`` @@ -214,12 +197,12 @@ module.exports = class TestTab extends ApiFactory {
For more details, see How to test smart contracts guide in our documentation. -
Generate test file
+
Generate test file
- ${self.testList} + ${this.testList}
-
Run Tests
+
Run Tests
- ${self.testsOutput} - ${self.testsSummary} + ${this.testsOutput} + ${this.testsSummary}
` - if (!self._view.el) self._view.el = el + if (!this._view.el) this._view.el = el return el }