From 8e12bf51cd924669945f76e16145edbdbc464e87 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 7 Apr 2022 18:50:43 +0530 Subject: [PATCH] create test libs on the fly --- apps/remix-ide/src/app/tabs/test-tab.js | 6 +++--- libs/remix-core-plugin/src/lib/compiler-content-imports.ts | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index 606bc2821b..960e2a93ce 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -13,7 +13,7 @@ var { UnitTestRunner, assertLibCode } = require('@remix-project/remix-tests') const profile = { name: 'solidityUnitTesting', displayName: 'Solidity unit testing', - methods: ['testFromPath', 'testFromSource', 'setTestFolderPath', 'getTestlibs'], + methods: ['testFromPath', 'testFromSource', 'setTestFolderPath', 'getTestlibs', 'createTestLibs'], events: [], icon: 'assets/img/unitTesting.webp', description: 'Fast tool to generate unit tests for your contracts', @@ -63,8 +63,8 @@ module.exports = class TestTab extends ViewPlugin { async createTestLibs () { const provider = await this.fileManager.currentFileProvider() if (provider) { - provider.addExternal('.deps/remix-tests/remix_tests.sol', assertLibCode, 'remix_tests.sol') - provider.addExternal('.deps/remix-tests/remix_accounts.sol', this.testRunner.accountsLibCode, 'remix_accounts.sol') + await provider.addExternal('.deps/remix-tests/remix_tests.sol', assertLibCode, 'remix_tests.sol') + await provider.addExternal('.deps/remix-tests/remix_accounts.sol', this.testRunner.accountsLibCode, 'remix_accounts.sol') } } diff --git a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts index 2b88d26064..4bc9297ea2 100644 --- a/libs/remix-core-plugin/src/lib/compiler-content-imports.ts +++ b/libs/remix-core-plugin/src/lib/compiler-content-imports.ts @@ -129,14 +129,17 @@ export class CompilerImports extends Plugin { if (provider.type === 'localhost' && !provider.isConnected()) { throw new Error(`file provider ${provider.type} not available while trying to resolve ${url}`) } - const exist = await provider.exists(url) + let exist = await provider.exists(url) /* if the path is absolute and the file does not exist, we can stop here Doesn't make sense to try to resolve "localhost/node_modules/localhost/node_modules/" and we'll end in an infinite loop. */ + if (!exist && (url === 'remix_tests.sol' || url === 'remix_accounts.sol')) { + await this.call('solidityUnitTesting', 'createTestLibs') + exist = await provider.exists(url) + } if (!exist && url.startsWith('browser/')) throw new Error(`not found ${url}`) if (!exist && url.startsWith('localhost/')) throw new Error(`not found ${url}`) - if (exist) { const content = await (() => { return new Promise((resolve, reject) => {