Merge pull request #1334 from ethereum/test-tab4

test-tab importFileCb injection
pull/3094/head
Iuri Matias 7 years ago committed by GitHub
commit 2e393cafcf
  1. 8
      src/app.js
  2. 4
      src/app/compiler/compiler-imports.js
  3. 8
      src/app/files/fileManager.js
  4. 29
      src/app/tabs/test-tab.js

@ -6,6 +6,7 @@ var yo = require('yo-yo')
var async = require('async')
var request = require('request')
var remixLib = require('remix-lib')
var remixTests = require('remix-tests')
var EventManager = remixLib.EventManager
var UniversalDApp = require('./universal-dapp.js')
@ -253,6 +254,9 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
}
function importFileCb (url, filecb) {
if (url.indexOf('/remix_tests.sol') !== -1) {
return filecb(null, remixTests.assertLibCode)
}
var provider = fileManager.fileProviderOf(url)
if (provider) {
provider.exists(url, (error, exist) => {
@ -714,6 +718,10 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// ---------------- Righthand-panel --------------------
var rhpAPI = {
importFileCb: importFileCb,
filesFromPath: (path, cb) => {
fileManager.filesFromPath(path, cb)
},
newAccount: (pass, cb) => {
udapp.newAccount(pass, cb)
},

@ -2,7 +2,6 @@
var base64 = require('js-base64').Base64
var swarmgw = require('swarmgw')
var request = require('request')
var assertLibCode = require('remix-tests').assertLibCode
module.exports = class CompilerImports {
constructor () {
@ -71,9 +70,6 @@ module.exports = class CompilerImports {
import (url, loadingCb, cb) {
var self = this
if (url === 'remix_tests.sol') {
return cb(null, assertLibCode, 'remix_tests.sol', 'remix_tests', 'remix_tests.sol')
}
var imported = this.previouslyHandled[url]
if (imported) {
return cb(null, imported.content, imported.cleanUrl, imported.type, url)

@ -155,6 +155,14 @@ class FileManager {
}
}
filesFromPath (path, cb) {
var provider = this.fileProviderOf(path)
if (provider) {
return provider.resolveDirectory(path, (error, filesTree) => { cb(error, filesTree) })
}
cb(`provider for path ${path} not found`)
}
fileProviderOf (file) {
var provider = file.match(/[^/]*/)
if (provider !== null && this.opt.filesProviders[provider[0]]) {

@ -1,4 +1,5 @@
var yo = require('yo-yo')
var async = require('async')
var css = require('./styles/test-tab-styles')
var remixTests = require('remix-tests')
@ -28,7 +29,7 @@ function testTabView (api) {
cb()
}
let finalCallback = function (_err, result) {
let updateFinalResult = function (_err, result) {
if (result.totalPassing > 0) {
append(container, (' ' + result.totalPassing + ' passing ') + ('(' + result.totalTime + 's)'))
}
@ -43,10 +44,32 @@ function testTabView (api) {
})
}
function runTest (testFilePath, callback) {
var provider = api.fileProviderOf(testFilePath)
provider.get(testFilePath, (error, content) => {
if (!error) {
var runningTest = {}
runningTest[testFilePath] = { content }
remixTests.runTestSources(runningTest, testCallback, resultsCallback, (error, result) => {
updateFinalResult(error, result)
callback(error)
}, api.importFileCb)
}
})
}
let runTests = function () {
let contractSources = api.getAllSources()
container.innerHTML = ''
remixTests.runTestSources(contractSources, testCallback, resultsCallback, finalCallback)
var path = api.currentPath()
var tests = []
api.filesFromPath(path, (error, files) => {
if (!error) {
for (var file in files) {
if (/.(_test.sol)$/.exec(file)) tests.push(path + file)
}
async.eachOfSeries(tests, (value, key, callback) => { runTest(value, callback) })
}
})
}
return yo`

Loading…
Cancel
Save