loop over _test.sol to run test

move test injection in importFileCb
pull/3094/head
yann300 7 years ago
parent 94633a6adb
commit ddbf9b76bc
  1. 8
      src/app.js
  2. 4
      src/app/compiler/compiler-imports.js
  3. 8
      src/app/files/fileManager.js
  4. 21
      src/app/tabs/test-tab.js

@ -6,6 +6,7 @@ var yo = require('yo-yo')
var async = require('async') var async = require('async')
var request = require('request') var request = require('request')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var remixTests = require('remix-tests')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
var UniversalDApp = require('./universal-dapp.js') 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) { function importFileCb (url, filecb) {
if (url.indexOf('/remix_tests.sol') !== -1) {
return filecb(null, remixTests.assertLibCode)
}
var provider = fileManager.fileProviderOf(url) var provider = fileManager.fileProviderOf(url)
if (provider) { if (provider) {
provider.exists(url, (error, exist) => { 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 -------------------- // ---------------- Righthand-panel --------------------
var rhpAPI = { var rhpAPI = {
importFileCb: importFileCb,
filesFromPath: (path, cb) => {
fileManager.filesFromPath(path, cb)
},
newAccount: (pass, cb) => { newAccount: (pass, cb) => {
udapp.newAccount(pass, cb) udapp.newAccount(pass, cb)
}, },

@ -2,7 +2,6 @@
var base64 = require('js-base64').Base64 var base64 = require('js-base64').Base64
var swarmgw = require('swarmgw') var swarmgw = require('swarmgw')
var request = require('request') var request = require('request')
var assertLibCode = require('remix-tests').assertLibCode
module.exports = class CompilerImports { module.exports = class CompilerImports {
constructor () { constructor () {
@ -71,9 +70,6 @@ module.exports = class CompilerImports {
import (url, loadingCb, cb) { import (url, loadingCb, cb) {
var self = this 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] var imported = this.previouslyHandled[url]
if (imported) { if (imported) {
return cb(null, imported.content, imported.cleanUrl, imported.type, url) 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) { fileProviderOf (file) {
var provider = file.match(/[^/]*/) var provider = file.match(/[^/]*/)
if (provider !== null && this.opt.filesProviders[provider[0]]) { if (provider !== null && this.opt.filesProviders[provider[0]]) {

@ -43,10 +43,27 @@ function testTabView (api) {
}) })
} }
function runTest (testFilePath) {
var provider = api.fileProviderOf(testFilePath)
provider.get(testFilePath, (error, content) => {
if (!error) {
var runningTest = {}
runningTest[testFilePath] = { content }
remixTests.runTestSources(runningTest, testCallback, resultsCallback, finalCallback, api.importFileCb)
}
})
}
let runTests = function () { let runTests = function () {
let contractSources = api.getAllSources()
container.innerHTML = '' container.innerHTML = ''
remixTests.runTestSources(contractSources, testCallback, resultsCallback, finalCallback) var path = api.currentPath()
api.filesFromPath(path, (error, files) => {
if (!error) {
for (var file in files) {
if (/.(_test.sol)$/.exec(file)) runTest(path + file)
}
}
})
} }
return yo` return yo`

Loading…
Cancel
Save