Commit 52b2e468 authored by aniket-engg's avatar aniket-engg Committed by Aniket

save compiler artifacts to show data on debugging

parent 6edbb46b
...@@ -7,7 +7,7 @@ var async = require('async') ...@@ -7,7 +7,7 @@ var async = require('async')
var tooltip = require('../ui/tooltip') var tooltip = require('../ui/tooltip')
var Renderer = require('../ui/renderer') var Renderer = require('../ui/renderer')
var css = require('./styles/test-tab-styles') 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') const TestTabLogic = require('./testTab/testTab')
...@@ -33,6 +33,7 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -33,6 +33,7 @@ module.exports = class TestTab extends ViewPlugin {
this.data = {} this.data = {}
this.appManager = appManager this.appManager = appManager
this.renderer = new Renderer(this) this.renderer = new Renderer(this)
this.testRunner = new UnitTestRunner()
this.hasBeenStopped = false this.hasBeenStopped = false
this.runningTestsNumber = 0 this.runningTestsNumber = 0
this.readyTestsNumber = 0 this.readyTestsNumber = 0
...@@ -95,6 +96,14 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -95,6 +96,14 @@ module.exports = class TestTab extends ViewPlugin {
this.setCurrentPath(this.defaultPath) 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', () => { this.fileManager.events.on('noFileSelected', () => {
}) })
...@@ -462,7 +471,7 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -462,7 +471,7 @@ module.exports = class TestTab extends ViewPlugin {
usingWorker: canUseWorker(currentVersion), usingWorker: canUseWorker(currentVersion),
runs runs
} }
remixTests.runTestSources(runningTest, compilerConfig, () => {}, () => {}, (error, result) => { this.testRunner.runTestSources(runningTest, compilerConfig, () => {}, () => {}, (error, result) => {
if (error) return reject(error) if (error) return reject(error)
resolve(result) resolve(result)
}, (url, cb) => { }, (url, cb) => {
...@@ -489,7 +498,7 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -489,7 +498,7 @@ module.exports = class TestTab extends ViewPlugin {
usingWorker: canUseWorker(currentVersion), usingWorker: canUseWorker(currentVersion),
runs runs
} }
remixTests.runTestSources( this.testRunner.runTestSources(
runningTests, runningTests,
compilerConfig, compilerConfig,
(result) => this.testCallback(result, runningTests), (result) => this.testCallback(result, runningTests),
......
...@@ -52,6 +52,11 @@ export class CompilerArtefacts extends Plugin { ...@@ -52,6 +52,11 @@ export class CompilerArtefacts extends Plugin {
this.compilersArtefacts.__last = new CompilerAbstract(languageVersion, data, source) this.compilersArtefacts.__last = new CompilerAbstract(languageVersion, data, source)
saveCompilationPerFileResult(file, source, languageVersion, data) 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 () { getAllContractDatas () {
......
...@@ -205,6 +205,7 @@ export function compileContractSources (sources: SrcIfc, compilerConfig: Compile ...@@ -205,6 +205,7 @@ export function compileContractSources (sources: SrcIfc, compilerConfig: Compile
function doCompilation (next) { function doCompilation (next) {
// @ts-ignore // @ts-ignore
compiler.event.register('compilationFinished', this, (success, data, source) => { compiler.event.register('compilationFinished', this, (success, data, source) => {
if (opts && opts.event) opts.event.trigger('compilationFinished', [success, data, source])
next(null, data) next(null, data)
}) })
compiler.compile(sources, filepath) compiler.compile(sources, filepath)
......
export { runTestFiles } from './runTestFiles' export { runTestFiles } from './runTestFiles'
export { runTestSources } from './runTestSources' export { UnitTestRunner } from './runTestSources'
export { runTest } from './testRunner' export { runTest } from './testRunner'
export * from './types' export * from './types'
export const assertLibCode = require('../sol/tests.sol') export const assertLibCode = require('../sol/tests.sol')
'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)
}
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment