handle test files

pull/1738/head
Aniket-Engg 3 years ago committed by yann300
parent 3f1205aee1
commit 0600ece5ef
  1. 11
      libs/remix-core-plugin/src/lib/compiler-content-imports.ts
  2. 2
      libs/remix-tests/src/compiler.ts

@ -106,6 +106,13 @@ export class CompilerImports extends Plugin {
})
}
async importTestFiles () {
const provider = await this.call('fileManager', 'getProviderOf', null)
const content = remixTests.assertLibCode
if (provider) provider.addExternal('.deps/remix-tests/remix-tests.sol', content, 'remix_tests.sol')
return content
}
/**
* import the content of @arg url.
* first look in the browser localstorage (browser explorer) or locahost explorer. if the url start with `browser/*` or `localhost/*`
@ -117,7 +124,9 @@ export class CompilerImports extends Plugin {
* @returns {Promise} - string content
*/
async resolveAndSave (url, targetPath) {
if (url.indexOf('remix_tests.sol') !== -1) return remixTests.assertLibCode
if (url.indexOf('remix_tests.sol') !== -1) {
return await this.importTestFiles()
}
try {
const provider = await this.call('fileManager', 'getProviderOf', url)
if (provider) {

@ -177,7 +177,7 @@ export function compileContractSources (sources: SrcIfc, compilerConfig: Compile
// Iterate over sources keys. Inject test libraries. Inject test library import statements.
if (!('remix_tests.sol' in sources) && !('tests.sol' in sources)) {
sources['tests.sol'] = { content: require('../sol/tests.sol.js') }
sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') }
// sources['remix_tests.sol'] = { content: require('../sol/tests.sol.js') }
sources['remix_accounts.sol'] = { content: writeTestAccountsContract(accounts) }
}
const testFileImportRegEx = /^(import)\s['"](remix_tests.sol|tests.sol)['"];/gm

Loading…
Cancel
Save