Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
9eb17cd4
Commit
9eb17cd4
authored
Nov 21, 2018
by
0mkar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests for remix-resolve
parent
ed515dda
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
100 deletions
+44
-100
package.json
remix-resolve/package.json
+5
-4
combineSource.js
remix-resolve/src/combineSource.js
+1
-1
resolve.js
remix-resolve/src/resolve.js
+1
-1
resolveImports.js
remix-resolve/src/resolveImports.js
+0
-94
test.js
remix-resolve/tests/test.js
+37
-0
No files found.
remix-resolve/package.json
View file @
9eb17cd4
...
...
@@ -27,12 +27,13 @@
"tests/"
]
},
"dependencies"
:
{
"axios"
:
"^0.18.0"
,
"url"
:
"^0.11.0"
,
"valid-url"
:
"^1.0.9"
},
"devDependencies"
:
{
"mocha"
:
"^5.1.0"
,
"standard"
:
"^12.0.1"
},
"dependencies"
:
{
"url"
:
"^0.11.0"
,
"valid-url"
:
"^1.0.9"
}
}
remix-resolve/src/combineSource.js
View file @
9eb17cd4
...
...
@@ -39,4 +39,4 @@ const combineSource = async function (rootpath, sources) {
return
sources
}
module
.
exports
=
{
combineSource
}
module
.
exports
=
combineSource
remix-resolve/src/resolve.js
View file @
9eb17cd4
...
...
@@ -91,4 +91,4 @@ const resolve = async function (fileRoot, sourcePath) {
return
response
}
module
.
exports
=
{
resolve
}
module
.
exports
=
resolve
remix-resolve/src/resolveImports.js
deleted
100644 → 0
View file @
ed515dda
const
axios
=
require
(
'axios'
)
const
path
=
require
(
'path'
)
const
fs
=
require
(
'fs'
)
const
handleGithubCall
=
async
function
(
fullpath
,
repoPath
,
path
,
filename
,
fileRoot
)
{
const
data
=
await
axios
({
method
:
'get'
,
url
:
'https://api.github.com/repos/'
+
repoPath
+
'/contents/'
+
path
,
responseType
:
'json'
}).
then
(
function
(
response
)
{
if
(
'content'
in
response
.
data
)
{
const
buf
=
Buffer
.
from
(
response
.
data
.
content
,
'base64'
)
fileRoot
=
fullpath
.
substring
(
0
,
fullpath
.
lastIndexOf
(
'/'
))
fileRoot
=
fileRoot
+
'/'
const
resp
=
{
filename
,
content
:
buf
.
toString
(
'UTF-8'
),
fileRoot
}
return
resp
}
else
{
throw
Error
(
'Content not received!'
)
}
})
return
data
}
const
handleNodeModulesImport
=
async
function
(
pathString
,
filename
,
fileRoot
)
{
const
o
=
{
encoding
:
'UTF-8'
}
var
modulesDir
=
fileRoot
while
(
true
)
{
var
p
=
path
.
join
(
modulesDir
,
'node_modules'
,
pathString
,
filename
)
try
{
const
content
=
fs
.
readFileSync
(
p
,
o
)
fileRoot
=
path
.
join
(
modulesDir
,
'node_modules'
,
pathString
)
const
response
=
{
filename
,
content
,
fileRoot
}
return
response
}
catch
(
err
)
{
console
.
log
(
err
)
}
// Recurse outwards until impossible
var
oldModulesDir
=
modulesDir
modulesDir
=
path
.
join
(
modulesDir
,
'..'
)
if
(
modulesDir
===
oldModulesDir
)
{
break
}
}
}
const
handleLocalImport
=
async
function
(
pathString
,
filename
,
fileRoot
)
{
// if no relative/absolute path given then search in node_modules folder
if
(
pathString
&&
pathString
.
indexOf
(
'.'
)
!==
0
&&
pathString
.
indexOf
(
'/'
)
!==
0
)
{
return
handleNodeModulesImport
(
pathString
,
filename
,
fileRoot
)
}
else
{
const
o
=
{
encoding
:
'UTF-8'
}
const
p
=
pathString
?
path
.
resolve
(
fileRoot
,
pathString
,
filename
)
:
path
.
resolve
(
fileRoot
,
filename
)
const
content
=
fs
.
readFileSync
(
p
,
o
)
fileRoot
=
pathString
?
path
.
resolve
(
fileRoot
,
pathString
)
:
fileRoot
const
response
=
{
filename
,
content
,
fileRoot
}
return
response
}
}
const
getHandlers
=
async
function
()
{
return
[
{
type
:
'local'
,
match
:
/
(
^
(?!(?:
http:
\/\/)
|
(?:
https:
\/\/)?(?:
www.
)?(?:
github.com
)))(
^
\/
*
[\w
+-_
/]
*
\/)
*
?(\w
+
\.
sol
)
/g
,
handle
:
async
(
match
,
fileRoot
)
=>
{
const
data
=
await
handleLocalImport
(
match
[
2
],
match
[
3
],
fileRoot
);
return
data
}
},
{
type
:
'github'
,
match
:
/^
(
https
?
:
\/\/)?(
www.
)?
github.com
\/([^/]
*
\/[^/]
*
)(
.*
\/(\w
+
\.
sol
))
/g
,
handle
:
async
(
match
,
fileRoot
)
=>
{
const
data
=
await
handleGithubCall
(
match
[
0
],
match
[
3
],
match
[
4
],
match
[
5
],
fileRoot
)
return
data
}
}
]
}
const
resolveImports
=
async
function
(
fileRoot
,
sourcePath
)
{
const
handlers
=
await
getHandlers
()
let
response
=
{}
for
(
const
handler
of
handlers
)
{
try
{
// here we are trying to find type of import path github/swarm/ipfs/local
const
match
=
handler
.
match
.
exec
(
sourcePath
)
if
(
match
)
{
response
=
await
handler
.
handle
(
match
,
fileRoot
)
break
}
}
catch
(
e
)
{
throw
e
}
}
return
response
}
module
.
exports
=
{
resolveImports
}
remix-resolve/tests/test.js
View file @
9eb17cd4
const
rr
=
require
(
'../src/index.js'
)
const
assert
=
require
(
'assert'
)
const
fs
=
require
(
'fs'
)
describe
(
'testRunner'
,
function
()
{
describe
(
'#combineSource'
,
function
()
{
describe
(
'test with beforeAll'
,
function
()
{
let
filename
=
'tests/examples_1/greeter.sol'
let
tests
=
[],
results
=
{}
before
(
function
(
done
)
{
const
content
=
fs
.
readFileSync
(
'../remix-resolve/tests/example_1/greeter.sol'
)
var
sources
=
[]
sources
[
'greeter.sol'
]
=
content
rr
.
combineSource
(
'/home/0mkar/Karma/remix/remix-resolve/tests/example_1/greeter.sol'
,
sources
)
})
it
(
'should 1 passing test'
,
function
()
{
assert
.
equal
(
results
.
passingNum
,
2
)
})
it
(
'should 1 failing test'
,
function
()
{
assert
.
equal
(
results
.
failureNum
,
2
)
})
it
(
'should returns 5 messages'
,
function
()
{
assert
.
deepEqual
(
tests
,
[
{
type
:
'contract'
,
value
:
'MyTest'
,
filename
:
'simple_storage_test.sol'
},
{
type
:
'testFailure'
,
value
:
'Should trigger one fail'
,
time
:
1
,
context
:
'MyTest'
,
errMsg
:
'the test 1 fails'
},
{
type
:
'testPass'
,
value
:
'Should trigger one pass'
,
time
:
1
,
context
:
'MyTest'
},
{
type
:
'testPass'
,
value
:
'Initial value should be100'
,
time
:
1
,
context
:
'MyTest'
},
{
type
:
'testFailure'
,
value
:
'Initial value should be200'
,
time
:
1
,
context
:
'MyTest'
,
errMsg
:
'function returned false'
}
])
})
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment