Commit d68a7c25 authored by Omkara's avatar Omkara

Add tests with & without AppManager

parent 75ec6ae7
...@@ -17,10 +17,10 @@ interface IAppManager { ...@@ -17,10 +17,10 @@ interface IAppManager {
} }
describe('testRunner', () => { describe('testRunner', () => {
describe('#resolve', () => { describe('# RemixResolveApi.resolve()', () => {
describe('test example_1 [local imports]]', () => {
// AppManager tests // AppManager tests
describe('test with AppManager', () => { describe('* test with AppManager', () => {
describe('test example_1 [local imports]', () => {
let app: AppManager<IAppManager> let app: AppManager<IAppManager>
let api: RemixResolveApi let api: RemixResolveApi
...@@ -53,11 +53,11 @@ describe('testRunner', () => { ...@@ -53,11 +53,11 @@ describe('testRunner', () => {
} }
] ]
app['modules'][api.type].api.resolve(fileName, localFSHandler) app['modules'][api.type].api.resolve(fileName, localFSHandler)
.then(sources => { .then((sources: object) => {
results = sources results = sources
done() done()
}) })
.catch(e => { .catch((e: Error) => {
throw e throw e
}) })
}) })
...@@ -74,7 +74,6 @@ describe('testRunner', () => { ...@@ -74,7 +74,6 @@ describe('testRunner', () => {
assert.deepEqual(results, expt) assert.deepEqual(results, expt)
}) })
}) })
// test IPFShandle // test IPFShandle
describe('test getting IPFS files', function() { describe('test getting IPFS files', function() {
let app: AppManager<IAppManager> let app: AppManager<IAppManager>
...@@ -116,5 +115,49 @@ describe('testRunner', () => { ...@@ -116,5 +115,49 @@ describe('testRunner', () => {
}) })
}) })
}) })
describe('* test without AppManager', () => {
const remixResolve = new RemixResolveApi()
const fileName: string = '../remix-resolve/tests/example_1/greeter.sol'
let results: object = {}
before(done => {
function handleLocal(pathString: string, filePath: string) {
// if no relative/absolute path given then search in node_modules folder
if (pathString && pathString.indexOf('.') !== 0 && pathString.indexOf('/') !== 0) {
// return handleNodeModulesImport(pathString, filePath, pathString)
return
} else {
const o = { encoding: 'UTF-8' }
const p = pathString ? path.resolve(pathString, filePath) : path.resolve(pathString, filePath)
const content = fs.readFileSync(p, o)
return content
}
}
const localFSHandler = [
{
type: 'local',
match: (url: string) => { return /(^(?!(?:http:\/\/)|(?:https:\/\/)?(?:www.)?(?:github.com)))(^\/*[\w+-_/]*\/)*?(\w+\.sol)/g.exec(url) },
handle: (match: Array<string>) => { return handleLocal(match[2], match[3]) }
}
]
remixResolve.resolve(fileName, localFSHandler)
.then((sources: object) => {
results = sources
done()
})
.catch((e: Error) => {
throw e
})
})
it('should returns contract content of given local path', () => {
const expt = {
content: 'pragma solidity ^0.5.0;\nimport "./mortal.sol";\n\ncontract Greeter is Mortal {\n /* Define variable greeting of the type string */\n string greeting;\n\n /* This runs when the contract is executed */\n constructor(string memory _greeting) public {\n greeting = _greeting;\n }\n\n /* Main function */\n function greet() public view returns (string memory) {\n return greeting;\n }\n}\n',
cleanURL: '../remix-resolve/tests/example_1/greeter.sol',
type: 'local'
}
assert.deepEqual(results, expt)
})
})
}) })
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment