check if possible to use worker for unit tests

pull/5370/head
LianaHus 5 years ago committed by Liana Husikyan
parent 4c85873c09
commit 3525325c9a
  1. 43
      src/app/compiler/compiler-utils.js
  2. 39
      src/app/tabs/compileTab/compilerContainer.js
  3. 16
      src/app/tabs/test-tab.js

@ -0,0 +1,43 @@
const semver = require('semver')
/* global Worker */
/**
* Checks if the worker can be used to load a compiler.
* checks a compiler whitelist, browser support and OS.
*/
export function canUseWorker (selectedVersion) {
// Following restrictions should be deleted when Solidity will release fixed versions of compilers.
// See https://github.com/ethereum/remix-ide/issues/2461
const isChrome = !!window.chrome
const os = retrieveOS()
// define a whitelist for Linux
const linuxWL = ['0.4.26', '0.5.3', '0.5.4', '0.5.5']
const version = semver.coerce(selectedVersion)
// defining whitelist for chrome
let isFromWhiteList = false
switch (os) {
case 'Windows':
isFromWhiteList = semver.gt(version, '0.5.2') || version === '0.4.26'
break
case 'Linux':
isFromWhiteList = semver.gt(version, '0.5.13') || linuxWL.includes(version)
break
default :
isFromWhiteList = true
}
return browserSupportWorker() && (!isChrome || (isChrome && isFromWhiteList))
}
function browserSupportWorker () {
return document.location.protocol !== 'file:' && Worker !== undefined
}
function retrieveOS () {
let osName = 'Unknown OS'
if (navigator.platform.indexOf('Win') !== -1) {
osName = 'Windows'
} else if (navigator.platform.indexOf('Linux') !== -1) {
osName = 'Linux'
}
return osName
}

@ -1,4 +1,4 @@
/* global Worker */
const yo = require('yo-yo') const yo = require('yo-yo')
const minixhr = require('minixhr') const minixhr = require('minixhr')
const helper = require('../../../lib/helper') const helper = require('../../../lib/helper')
@ -6,6 +6,7 @@ const addTooltip = require('../../ui/tooltip')
const semver = require('semver') const semver = require('semver')
const modalDialogCustom = require('../../ui/modal-dialog-custom') const modalDialogCustom = require('../../ui/modal-dialog-custom')
const css = require('../styles/compile-tab-styles') const css = require('../styles/compile-tab-styles')
import { canUseWorker } from '../../compiler/compiler-utils'
class CompilerContainer { class CompilerContainer {
@ -397,30 +398,10 @@ class CompilerContainer {
url = `${this.data.baseurl}/${this.data.selectedVersion}` url = `${this.data.baseurl}/${this.data.selectedVersion}`
} }
// Following restrictions should be deleted when Solidity will release fixed versions of compilers.
// See https://github.com/ethereum/remix-ide/issues/2461
const isChrome = !!window.chrome
const os = this._retrieveOS()
// define a whitelist for Linux
const linuxWL = ['0.4.26', '0.5.3', '0.5.4', '0.5.5']
const version = semver.coerce(this.data.selectedVersion)
// defining whitelist for chrome
let isFromWhiteList = false
switch (os) {
case 'Windows':
isFromWhiteList = semver.gt(version, '0.5.2') || version === '0.4.26'
break
case 'Linux':
isFromWhiteList = semver.gt(version, '0.5.13') || linuxWL.includes(version)
break
default :
isFromWhiteList = true
}
// Workers cannot load js on "file:"-URLs and we get a // Workers cannot load js on "file:"-URLs and we get a
// "Uncaught RangeError: Maximum call stack size exceeded" error on Chromium, // "Uncaught RangeError: Maximum call stack size exceeded" error on Chromium,
// resort to non-worker version in that case. // resort to non-worker version in that case.
if (this.browserSupportWorker() && (!isChrome || (isChrome && isFromWhiteList))) { if (canUseWorker(this.data.selectedVersion)) {
this.compileTabLogic.compiler.loadVersion(true, url) this.compileTabLogic.compiler.loadVersion(true, url)
this.setVersionText('(loading using worker)') this.setVersionText('(loading using worker)')
} else { } else {
@ -429,16 +410,6 @@ class CompilerContainer {
} }
} }
_retrieveOS () {
let osName = 'Unknown OS'
if (navigator.platform.indexOf('Win') !== -1) {
osName = 'Windows'
} else if (navigator.platform.indexOf('Linux') !== -1) {
osName = 'Linux'
}
return osName
}
_updateLanguageSelector () { _updateLanguageSelector () {
// This is the first version when Yul is available // This is the first version when Yul is available
if (!semver.valid(this._retrieveVersion()) || semver.lt(this._retrieveVersion(), 'v0.5.7+commit.6da8b019.js')) { if (!semver.valid(this._retrieveVersion()) || semver.lt(this._retrieveVersion(), 'v0.5.7+commit.6da8b019.js')) {
@ -481,10 +452,6 @@ class CompilerContainer {
this.data.compileTimeout = window.setTimeout(() => this.compileIfAutoCompileOn(), this.data.timeout) this.data.compileTimeout = window.setTimeout(() => this.compileIfAutoCompileOn(), this.data.timeout)
} }
browserSupportWorker () {
return document.location.protocol !== 'file:' && Worker !== undefined
}
} }
module.exports = CompilerContainer module.exports = CompilerContainer

@ -4,6 +4,7 @@ var tooltip = require('../ui/tooltip')
var css = require('./styles/test-tab-styles') var css = require('./styles/test-tab-styles')
var remixTests = require('remix-tests') var remixTests = require('remix-tests')
import { ViewPlugin } from '@remixproject/engine' import { ViewPlugin } from '@remixproject/engine'
import { canUseWorker } from '../compiler/compiler-utils'
const TestTabLogic = require('./testTab/testTab') const TestTabLogic = require('./testTab/testTab')
@ -153,8 +154,7 @@ module.exports = class TestTab extends ViewPlugin {
let runningTest = {} let runningTest = {}
runningTest[path] = { content } runningTest[path] = { content }
let currentCompilerUrl = this.baseurl + '/' + this.compileTab.getCurrentVersion() let currentCompilerUrl = this.baseurl + '/' + this.compileTab.getCurrentVersion()
let usingWorker = this.compileTab.compilerContainer.browserSupportWorker() remixTests.runTestSources(runningTest, currentCompilerUrl, canUseWorker(this.compileTab.getCurrentVersion()), () => {}, () => {}, (error, result) => {
remixTests.runTestSources(runningTest, currentCompilerUrl, usingWorker, () => {}, () => {}, (error, result) => {
if (error) return reject(error) if (error) return reject(error)
resolve(result) resolve(result)
}, (url, cb) => { }, (url, cb) => {
@ -169,14 +169,20 @@ module.exports = class TestTab extends ViewPlugin {
var runningTest = {} var runningTest = {}
runningTest[testFilePath] = { content } runningTest[testFilePath] = { content }
let currentCompilerUrl = this.baseurl + '/' + this.compileTab.getCurrentVersion() let currentCompilerUrl = this.baseurl + '/' + this.compileTab.getCurrentVersion()
let usingWorker = this.compileTab.compilerContainer.browserSupportWorker() remixTests.runTestSources(
remixTests.runTestSources(runningTest, currentCompilerUrl, usingWorker, (result) => { this.testCallback(result) }, (_err, result, cb) => { this.resultsCallback(_err, result, cb) }, (error, result) => { runningTest,
currentCompilerUrl,
canUseWorker(this.compileTab.getCurrentVersion()),
(result) => { this.testCallback(result) },
(_err, result, cb) => { this.resultsCallback(_err, result, cb) },
(error, result) => {
this.updateFinalResult(error, result, testFilePath) this.updateFinalResult(error, result, testFilePath)
this.loading.hidden = true this.loading.hidden = true
callback(error) callback(error)
}, (url, cb) => { }, (url, cb) => {
return this.compileTab.compileTabLogic.importFileCb(url, cb) return this.compileTab.compileTabLogic.importFileCb(url, cb)
}) }
)
}).catch((error) => { }).catch((error) => {
if (error) return if (error) return
}) })

Loading…
Cancel
Save