save compiler artifacts to show data on debugging

pull/5370/head
aniket-engg 3 years ago committed by Aniket
parent 8d77b4c2fa
commit d4ee9ea76b
  1. 15
      apps/remix-ide/src/app/tabs/test-tab.js
  2. 5
      libs/remix-core-plugin/src/lib/compiler-artefacts.ts
  3. 1
      libs/remix-tests/src/compiler.ts
  4. 2
      libs/remix-tests/src/index.ts
  5. 68
      libs/remix-tests/src/lib/eventManager.ts
  6. 23
      libs/remix-tests/src/runTestSources.ts

@ -7,7 +7,7 @@ var async = require('async')
var tooltip = require('../ui/tooltip')
var Renderer = require('../ui/renderer')
var css = require('./styles/test-tab-styles')
var remixTests = require('@remix-project/remix-tests')
var { UnitTestRunner } = require('@remix-project/remix-tests')
const TestTabLogic = require('./testTab/testTab')
@ -33,6 +33,7 @@ module.exports = class TestTab extends ViewPlugin {
this.data = {}
this.appManager = appManager
this.renderer = new Renderer(this)
this.testRunner = new UnitTestRunner()
this.hasBeenStopped = false
this.runningTestsNumber = 0
this.readyTestsNumber = 0
@ -95,6 +96,14 @@ module.exports = class TestTab extends ViewPlugin {
this.setCurrentPath(this.defaultPath)
})
this.testRunner.event.register('compilationFinished', (success, data, source) => {
if (success) {
// forwarding the event to the appManager infra
// This is listened by compilerArtefacts to show data while debugging
this.emit('compilationFinished', source.target, source, 'soljson', data)
}
})
this.fileManager.events.on('noFileSelected', () => {
})
@ -462,7 +471,7 @@ module.exports = class TestTab extends ViewPlugin {
usingWorker: canUseWorker(currentVersion),
runs
}
remixTests.runTestSources(runningTest, compilerConfig, () => {}, () => {}, (error, result) => {
this.testRunner.runTestSources(runningTest, compilerConfig, () => {}, () => {}, (error, result) => {
if (error) return reject(error)
resolve(result)
}, (url, cb) => {
@ -489,7 +498,7 @@ module.exports = class TestTab extends ViewPlugin {
usingWorker: canUseWorker(currentVersion),
runs
}
remixTests.runTestSources(
this.testRunner.runTestSources(
runningTests,
compilerConfig,
(result) => this.testCallback(result, runningTests),

@ -52,6 +52,11 @@ export class CompilerArtefacts extends Plugin {
this.compilersArtefacts.__last = new CompilerAbstract(languageVersion, data, source)
saveCompilationPerFileResult(file, source, languageVersion, data)
})
this.on('solidityUnitTesting', 'compilationFinished', (file, source, languageVersion, data) => {
this.compilersArtefacts.__last = new CompilerAbstract(languageVersion, data, source)
saveCompilationPerFileResult(file, source, languageVersion, data)
})
}
getAllContractDatas () {

@ -205,6 +205,7 @@ export function compileContractSources (sources: SrcIfc, compilerConfig: Compile
function doCompilation (next) {
// @ts-ignore
compiler.event.register('compilationFinished', this, (success, data, source) => {
if (opts && opts.event) opts.event.trigger('compilationFinished', [success, data, source])
next(null, data)
})
compiler.compile(sources, filepath)

@ -1,5 +1,5 @@
export { runTestFiles } from './runTestFiles'
export { runTestSources } from './runTestSources'
export { UnitTestRunner } from './runTestSources'
export { runTest } from './testRunner'
export * from './types'
export const assertLibCode = require('../sol/tests.sol')

@ -0,0 +1,68 @@
'use strict'
export default class EventManager {
registered: any = {} // eslint-disable-line
anonymous: any = {} // eslint-disable-line
/*
* Unregister a listener.
* Note that if obj is a function. the unregistration will be applied to the dummy obj {}.
*
* @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event
* @param {Func} func - function of the listeners that will be executed
*/
unregister (eventName: any, obj: any, func: any): void { // eslint-disable-line
if (!this.registered[eventName]) {
return
}
if (obj instanceof Function) {
func = obj
obj = this.anonymous
}
for (const reg in this.registered[eventName]) {
if (this.registered[eventName][reg].obj === obj && this.registered[eventName][reg].func === func) {
this.registered[eventName].splice(reg, 1)
}
}
}
/*
* Register a new listener.
* Note that if obj is a function, the function registration will be associated with the dummy object {}
*
* @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event
* @param {Func} func - function of the listeners that will be executed
*/
register (eventName: any, obj: any, func: any): void { // eslint-disable-line
if (!this.registered[eventName]) {
this.registered[eventName] = []
}
if (obj instanceof Function) {
func = obj
obj = this.anonymous
}
this.registered[eventName].push({
obj: obj,
func: func
})
}
/*
* trigger event.
* Every listener have their associated function executed
*
* @param {String} eventName - the event name
* @param {Array}j - argument that will be passed to the executed function.
*/
trigger (eventName: any, args: any): void { // eslint-disable-line
if (!this.registered[eventName]) {
return
}
for (const listener in this.registered[eventName]) {
const l = this.registered[eventName][listener]
if (l.func) l.func.apply(l.obj === this.anonymous ? {} : l.obj, args)
}
}
}

@ -5,6 +5,7 @@ import { deployAll } from './deployer'
import { runTest } from './testRunner'
import Web3 from 'web3'
import EventManager from './lib/eventManager'
import { Provider, extend } from '@remix-project/remix-simulator'
import {
FinalResult, SrcIfc, compilationInterface, ASTInterface, Options,
@ -12,16 +13,23 @@ import {
} from './types'
require('colors')
const createWeb3Provider = async function () {
export class UnitTestRunner {
event
constructor() {
this.event = new EventManager()
}
async createWeb3Provider () {
const web3 = new Web3()
const provider: any = new Provider()
await provider.init()
web3.setProvider(provider)
extend(web3)
return web3
}
}
/**
/**
* @dev Run tests from source of a test contract file (used for IDE)
* @param contractSources Sources of contract
* @param compilerConfig current compiler configuration
@ -31,10 +39,10 @@ const createWeb3Provider = async function () {
* @param importFileCb Import file callback
* @param opts Options
*/
export async function runTestSources (contractSources: SrcIfc, compilerConfig: CompilerConfiguration, testCallback, resultCallback, finalCallback: any, importFileCb, opts: Options) {
async runTestSources (contractSources: SrcIfc, compilerConfig: CompilerConfiguration, testCallback, resultCallback, finalCallback: any, importFileCb, opts: Options) {
opts = opts || {}
const sourceASTs: any = {}
const web3 = opts.web3 || await createWeb3Provider()
const web3 = opts.web3 || await this.createWeb3Provider()
let accounts: string[] | null = opts.accounts || null
async.waterfall([
function getAccountList (next) {
@ -44,8 +52,8 @@ export async function runTestSources (contractSources: SrcIfc, compilerConfig: C
next()
})
},
function compile (next) {
compileContractSources(contractSources, compilerConfig, importFileCb, { accounts }, next)
(next) => {
compileContractSources(contractSources, compilerConfig, importFileCb, { accounts, event: this.event}, next)
},
function deployAllContracts (compilationResult: compilationInterface, asts: ASTInterface, next) {
for (const filename in asts) {
@ -134,4 +142,5 @@ export async function runTestSources (contractSources: SrcIfc, compilerConfig: C
})
}
], finalCallback)
}
}

Loading…
Cancel
Save