diff --git a/src/app.js b/src/app.js index 8cb910ebe9..1afff93e76 100644 --- a/src/app.js +++ b/src/app.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) }, diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index a832f843d8..e306ac9fee 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.js @@ -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) diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 0d974200fb..9af4d38420 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -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]]) { diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index 2a06779310..c5dffd88c0 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -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 contractSources = api.getAllSources() 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`