stop button

pull/5370/head
aniket-engg 3 years ago committed by Aniket
parent 5402ea94e7
commit e97d01522b
  1. 56
      libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx

@ -1,5 +1,4 @@
import React, { useState, useRef, useEffect, CSSProperties } from 'react' // eslint-disable-line import React, { useState, useEffect } from 'react' // eslint-disable-line
// import { TestTabLogic } from './logic/testTabLogic'
var async = require('async') var async = require('async')
import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity'
import { Renderer } from '@remix-ui/renderer' // eslint-disable-line import { Renderer } from '@remix-ui/renderer' // eslint-disable-line
@ -44,10 +43,10 @@ export const SolidityUnitTesting = (props: any) => {
let [readyTestsNumber, setReadyTestsNumber] = useState(0) let [readyTestsNumber, setReadyTestsNumber] = useState(0)
let [runningTestsNumber, setRunningTestsNumber] = useState(0) let [runningTestsNumber, setRunningTestsNumber] = useState(0)
let [hasBeenStopped, setHasBeenStopped] = useState(false)
let [areTestsRunning, setAreTestsRunning] = useState(false) let areTestsRunning = false
let [isDebugging, setIsDebugging] = useState(false) let isDebugging = false
let hasBeenStopped = false
let allTests: any = [] let allTests: any = []
let currentErrors: any let currentErrors: any
@ -81,21 +80,20 @@ export const SolidityUnitTesting = (props: any) => {
// } // }
// // if current file is changed while debugging and one of the files imported in test file are opened // // if current file is changed while debugging and one of the files imported in test file are opened
// // do not clear the test results in SUT plugin // // do not clear the test results in SUT plugin
// if (this.isDebugging && this.allFilesInvolved.includes(file)) return // if (isDebugging && this.allFilesInvolved.includes(file)) return
console.log('Inside updateForNewCurrent --allTests-->', allTests) console.log('Inside updateForNewCurrent --allTests-->', allTests)
allTests = [] allTests = []
updateTestFileList() updateTestFileList()
clearResults() clearResults()
// if (!areTestsRunning) updateRunAction(file)
try { try {
testTabLogic.getTests((error: any, tests: any) => { testTabLogic.getTests(async (error: any, tests: any) => {
// if (error) return tooltip(error) // if (error) return tooltip(error)
console.log('tests in updateForNewCurrent testTabLogic.getTests', tests) console.log('tests in updateForNewCurrent testTabLogic.getTests', tests)
allTests = tests allTests = tests
selectedTests = [...allTests] selectedTests = [...allTests]
setSelectedTests(tests) setSelectedTests(tests)
updateTestFileList() updateTestFileList()
// if (!this.testsOutput) return // eslint-disable-line if (!areTestsRunning) await updateRunAction(file)
}) })
} catch (e) { } catch (e) {
console.log('error in updateForNewCurrent', e) console.log('error in updateForNewCurrent', e)
@ -164,7 +162,7 @@ export const SolidityUnitTesting = (props: any) => {
} }
} }
const handleCreateFolder = () => { const handleCreateFolder = async() => {
let inputPath = trimTestDirInput(inputPathValue) let inputPath = trimTestDirInput(inputPathValue)
let path = helper.removeMultipleSlashes(inputPath) let path = helper.removeMultipleSlashes(inputPath)
if (path !== '/') path = helper.removeTrailingSlashes(path) if (path !== '/') path = helper.removeTrailingSlashes(path)
@ -174,7 +172,7 @@ export const SolidityUnitTesting = (props: any) => {
setDisableCreateButton(true) setDisableCreateButton(true)
setDisableGenerateButton(false) setDisableGenerateButton(false)
testTabLogic.setCurrentPath(inputPath) testTabLogic.setCurrentPath(inputPath)
updateRunAction() await updateRunAction()
updateForNewCurrent() updateForNewCurrent()
pathOptions.push(inputPath) pathOptions.push(inputPath)
setPathOptions(pathOptions) setPathOptions(pathOptions)
@ -185,7 +183,7 @@ export const SolidityUnitTesting = (props: any) => {
} }
const startDebug = async (txHash: any, web3: any) => { const startDebug = async (txHash: any, web3: any) => {
// this.isDebugging = true isDebugging = true
if (!await testTab.appManager.isActive('debugger')) await testTab.appManager.activatePlugin('debugger') if (!await testTab.appManager.isActive('debugger')) await testTab.appManager.activatePlugin('debugger')
testTab.call('menuicons', 'select', 'debugger') testTab.call('menuicons', 'select', 'debugger')
testTab.call('debugger', 'debug', txHash, web3) testTab.call('debugger', 'debug', txHash, web3)
@ -354,7 +352,7 @@ export const SolidityUnitTesting = (props: any) => {
} }
const showTestsResult = () => { const showTestsResult = () => {
console.log('filesContent---->', filesContent) console.log('inside showTestsResult filesContent---->', filesContent)
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]
@ -441,7 +439,6 @@ export const SolidityUnitTesting = (props: any) => {
// show only file name // show only file name
renderContract(filename, null, -1, true) renderContract(filename, null, -1, true)
currentErrors = _errors.errors currentErrors = _errors.errors
// this.setHeader(false)
} }
if (result) { if (result) {
const totalTime = parseFloat(result.totalTime).toFixed(2) const totalTime = parseFloat(result.totalTime).toFixed(2)
@ -461,18 +458,15 @@ export const SolidityUnitTesting = (props: any) => {
// if all tests has been through before stopping no need to print this. // if all tests has been through before stopping no need to print this.
setTestsExecutionStoppedHidden(false) setTestsExecutionStoppedHidden(false)
} }
// if (_errors || this.hasBeenStopped || this.readyTestsNumber === this.runningTestsNumber) { if (_errors || hasBeenStopped || readyTestsNumber === runningTestsNumber) {
// // All tests are ready or the operation has been canceled or there was a compilation error in one of the test files. // All tests are ready or the operation has been canceled or there was a compilation error in one of the test files.
// const stopBtn = document.getElementById('runTestsTabStopAction') setDisableStopButton(true)
// stopBtn.setAttribute('disabled', 'disabled') setStopButtonLabel('Stop')
// const stopBtnLabel = document.getElementById('runTestsTabStopActionLabel') if (selectedTests.length !== 0) {
// stopBtnLabel.innerText = 'Stop' setDisableRunButton(false)
// if (this.data.selectedTests.length !== 0) { }
// const runBtn = document.getElementById('runTestsTabRunAction') areTestsRunning = false
// runBtn.removeAttribute('disabled') }
// }
// this.areTestsRunning = false
// }
} }
const runTest = (testFilePath: any, callback: any) => { const runTest = (testFilePath: any, callback: any) => {
@ -540,8 +534,10 @@ export const SolidityUnitTesting = (props: any) => {
}) })
} }
const updateRunAction = (currentFile : any = null) => { const updateRunAction = async (currentFile : any = null) => {
const isSolidityActive = testTab.appManager.isActive('solidity') const isSolidityActive = await testTab.appManager.isActive('solidity')
console.log('isSolidityActive-in updateRunAction--->', isSolidityActive)
console.log('selectedTests-in updateRunAction--->', selectedTests)
if (!isSolidityActive || !selectedTests?.length) { if (!isSolidityActive || !selectedTests?.length) {
setDisableRunButton(true) setDisableRunButton(true)
if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) {
@ -553,7 +549,7 @@ export const SolidityUnitTesting = (props: any) => {
} }
const stopTests = () => { const stopTests = () => {
setHasBeenStopped(true) hasBeenStopped = true
setStopButtonLabel('Stopping') setStopButtonLabel('Stopping')
setDisableStopButton(true) setDisableStopButton(true)
setDisableRunButton(true) setDisableRunButton(true)

Loading…
Cancel
Save