use workspace event to create files

pull/5370/head
Aniket-Engg 3 years ago committed by yann300
parent 4d95e3a6c6
commit 682fcdde6f
  1. 18
      apps/remix-ide/src/app/tabs/test-tab.js
  2. 8
      libs/remix-core-plugin/src/lib/compiler-content-imports.ts

@ -78,17 +78,21 @@ module.exports = class TestTab extends ViewPlugin {
return { assertLibCode, accountsLibCode: this.testRunner.accountsLibCode }
}
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')
}
}
async onActivation () {
const isSolidityActive = await this.call('manager', 'isActive', 'solidity')
if (!isSolidityActive) {
await this.call('manager', 'activatePlugin', 'solidity')
}
await this.testRunner.init()
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 this.createTestLibs()
this.updateRunAction()
}
@ -120,6 +124,10 @@ module.exports = class TestTab extends ViewPlugin {
this.setCurrentPath(this.defaultPath)
})
this.on('filePanel', 'workspaceCreated', async () => {
this.createTestLibs()
})
this.testRunner.event.on('compilationFinished', (success, data, source) => {
if (success) {
this.allFilesInvolved.push(...Object.keys(data.sources))

@ -118,14 +118,6 @@ export class CompilerImports extends Plugin {
* @returns {Promise} - string content
*/
async resolveAndSave (url, targetPath, testRunner = null) {
if (url.indexOf('remix_tests.sol') !== -1 || url.indexOf('remix_accounts.sol') !== -1) {
let content
if (url === 'remix_tests.sol') content = assertLibCode
else if (url === 'remix_accounts.sol' && testRunner) content = testRunner.accountsLibCode
const provider = await this.call('fileManager', 'getProviderOf', null)
if (provider) provider.addExternal('.deps/remix-tests/' + url, content, url)
return content
}
try {
const provider = await this.call('fileManager', 'getProviderOf', url)
if (provider) {

Loading…
Cancel
Save