do not reload compiler for same config

pull/1864/merge
aniket-engg 3 years ago committed by Aniket
parent 1d3dab492c
commit f53a4ef609
  1. 1
      libs/remix-tests/package.json
  2. 15
      libs/remix-tests/src/compiler.ts
  3. 21
      libs/remix-tests/src/runTestSources.ts

@ -49,6 +49,7 @@
"color-support": "^1.1.3",
"colors": "^1.1.2",
"commander": "^2.13.0",
"deep-equal": "^1.0.1",
"ethereumjs-util": "^7.0.10",
"ethers": "^5.4.2",
"ethjs-util": "^0.1.6",

@ -170,8 +170,7 @@ export function compileFileOrFiles (filename: string, isDirectory: boolean, opts
* @param opts Options
* @param cb Callback
*/
export function compileContractSources (sources: SrcIfc, compilerConfig: CompilerConfiguration, importFileCb: any, opts: any, cb): void {
let compiler
export function compileContractSources (sources: SrcIfc, compiler: any, opts: any, cb): void {
const filepath = opts.testFilePath || ''
const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm
@ -184,18 +183,6 @@ export function compileContractSources (sources: SrcIfc, compilerConfig: Compile
}
async.waterfall([
function loadCompiler (next) {
const { currentCompilerUrl, evmVersion, optimize, runs, usingWorker } = compilerConfig
compiler = new RemixCompiler(importFileCb)
compiler.set('evmVersion', evmVersion)
compiler.set('optimize', optimize)
compiler.set('runs', runs)
compiler.loadVersion(usingWorker, currentCompilerUrl)
// @ts-ignore
compiler.event.register('compilerLoaded', this, (version) => {
next()
})
},
function doCompilation (next) {
// @ts-ignore
compiler.event.register('compilationFinished', this, (success, data, source) => {

@ -1,4 +1,6 @@
import async, { ErrorCallback } from 'async'
import deepequal from 'deep-equal'
import { Compiler as RemixCompiler } from '@remix-project/remix-solidity'
import { compileContractSources, writeTestAccountsContract } from './compiler'
import { deployAll } from './deployer'
import { runTest } from './testRunner'
@ -16,6 +18,8 @@ export class UnitTestRunner {
accountsLibCode
testsAccounts: string[] | null
web3
compiler
compilerConfig
constructor () {
this.event = new EventEmitter()
@ -53,7 +57,22 @@ export class UnitTestRunner {
async.waterfall([
(next) => {
compileContractSources(contractSources, compilerConfig, importFileCb, { accounts: this.testsAccounts, testFilePath: opts.testFilePath, event: this.event }, next)
if (!deepequal(this.compilerConfig, compilerConfig)) {
this.compilerConfig = compilerConfig
const { currentCompilerUrl, evmVersion, optimize, runs, usingWorker } = compilerConfig
this.compiler = new RemixCompiler(importFileCb)
this.compiler.set('evmVersion', evmVersion)
this.compiler.set('optimize', optimize)
this.compiler.set('runs', runs)
this.compiler.loadVersion(usingWorker, currentCompilerUrl)
// @ts-ignore
this.compiler.event.register('compilerLoaded', this, (version) => {
next()
})
} else next()
},
(next) => {
compileContractSources(contractSources, this.compiler, { accounts: this.testsAccounts, testFilePath: opts.testFilePath, event: this.event }, next)
},
(compilationResult: compilationInterface, asts: ASTInterface, next) => {
for (const filename in asts) {

Loading…
Cancel
Save