Skip to content

Commit db93a9c

Browse files
committed
move compiler events in one file
1 parent d8655f3 commit db93a9c

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

libs/remix-tests/src/compiler.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from './fileSystem'
22
import async from 'async'
33
import path from 'path'
4+
import deepequal from 'deep-equal'
45
import Log from './logger'
56
import { Compiler as RemixCompiler } from '@remix-project/remix-solidity'
67
import { SrcIfc, CompilerConfiguration, CompilationErrors } from './types'
@@ -170,7 +171,8 @@ export function compileFileOrFiles (filename: string, isDirectory: boolean, opts
170171
* @param opts Options
171172
* @param cb Callback
172173
*/
173-
export function compileContractSources (sources: SrcIfc, compiler: any, opts: any, cb): void {
174+
export function compileContractSources (sources: SrcIfc, newCompConfig: any, importFileCb, UTRunner, opts: any, cb): void {
175+
let compiler
174176
const filepath = opts.testFilePath || ''
175177
const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm
176178

@@ -183,8 +185,29 @@ export function compileContractSources (sources: SrcIfc, compiler: any, opts: an
183185
}
184186

185187
async.waterfall([
186-
function doCompilation (next) {
188+
(next) => {
189+
if (!deepequal(UTRunner.compilerConfig, newCompConfig)) {
190+
UTRunner.compilerConfig = newCompConfig
191+
const { currentCompilerUrl, evmVersion, optimize, runs, usingWorker } = newCompConfig
192+
compiler = new RemixCompiler(importFileCb)
193+
compiler.set('evmVersion', evmVersion)
194+
compiler.set('optimize', optimize)
195+
compiler.set('runs', runs)
196+
compiler.loadVersion(usingWorker, currentCompilerUrl)
197+
// @ts-ignore
198+
compiler.event.register('compilerLoaded', this, (version) => {
199+
console.log('Inside compiler loaded')
200+
next()
201+
})
202+
} else {
203+
compiler = UTRunner.compiler
204+
next()
205+
}
206+
},
207+
(next) => {
208+
console.log('compiler before compilation', compiler)
187209
const compilationFinishedCb = (success, data, source) => {
210+
UTRunner.compiler = compiler
188211
if (opts && opts.event) opts.event.emit('compilationFinished', success, data, source)
189212
next(null, data)
190213
}

libs/remix-tests/src/runTestSources.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import async, { ErrorCallback } from 'async'
2-
import deepequal from 'deep-equal'
3-
import { Compiler as RemixCompiler } from '@remix-project/remix-solidity'
42
import { compileContractSources, writeTestAccountsContract } from './compiler'
53
import { deployAll } from './deployer'
64
import { runTest } from './testRunner'
@@ -50,29 +48,13 @@ export class UnitTestRunner {
5048
* @param importFileCb Import file callback
5149
* @param opts Options
5250
*/
53-
async runTestSources (contractSources: SrcIfc, compilerConfig: CompilerConfiguration, testCallback, resultCallback, deployCb:any, finalCallback: any, importFileCb, opts: Options) {
51+
async runTestSources (contractSources: SrcIfc, newCompilerConfig: CompilerConfiguration, testCallback, resultCallback, deployCb:any, finalCallback: any, importFileCb, opts: Options) {
5452
opts = opts || {}
5553
const sourceASTs: any = {}
5654
if (opts.web3 || opts.accounts) this.init(opts.web3, opts.accounts)
57-
5855
async.waterfall([
5956
(next) => {
60-
if (!deepequal(this.compilerConfig, compilerConfig)) {
61-
this.compilerConfig = compilerConfig
62-
const { currentCompilerUrl, evmVersion, optimize, runs, usingWorker } = compilerConfig
63-
this.compiler = new RemixCompiler(importFileCb)
64-
this.compiler.set('evmVersion', evmVersion)
65-
this.compiler.set('optimize', optimize)
66-
this.compiler.set('runs', runs)
67-
this.compiler.loadVersion(usingWorker, currentCompilerUrl)
68-
// @ts-ignore
69-
this.compiler.event.register('compilerLoaded', this, (version) => {
70-
next()
71-
})
72-
} else next()
73-
},
74-
(next) => {
75-
compileContractSources(contractSources, this.compiler, { accounts: this.testsAccounts, testFilePath: opts.testFilePath, event: this.event }, next)
57+
compileContractSources(contractSources, newCompilerConfig, importFileCb, this, { accounts: this.testsAccounts, testFilePath: opts.testFilePath, event: this.event }, next)
7658
},
7759
(compilationResult: compilationInterface, asts: ASTInterface, next) => {
7860
for (const filename in asts) {

0 commit comments

Comments
 (0)