-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow importing helper/utility files in test files #1030
Allow importing helper/utility files in test files #1030
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1030 +/- ##
==========================================
+ Coverage 39.65% 39.74% +0.08%
==========================================
Files 37 37
Lines 1841 1847 +6
==========================================
+ Hits 730 734 +4
- Misses 1028 1029 +1
- Partials 83 84 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
internal/test/test_test.go
Outdated
testFiles := make(map[string][]byte, 0) | ||
testFiles[script.Filename] = script.Source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testFiles := make(map[string][]byte, 0) | |
testFiles[script.Filename] = script.Source | |
testFiles := map[string][]byte{ | |
script.Filename: script.Source, | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 6c6d174
internal/test/test.go
Outdated
relativePath := stringLocation.String() | ||
|
||
if strings.Contains(relativePath, "_helper") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe strip the file extension (path/filepath
Ext()
) and check the plain filename contains this as a suffix. Or is the idea that this allows both _helper
and e.g. _helpers
like in the two test files?
Also, maybe refactor this magic string into a constant and add a comment explaining it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is the idea that this allows both _helper and e.g. _helpers like in the two test files?
Yes, exactly 👍 It might be the case that developers will put everything in a single helper file, or split them in several files. So I wanted to allow some flexibility in both plural & singular names.
Also, maybe refactor this magic string into a constant and add a comment explaining it.
Fixed in e920d18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good after Bastian comments.
@m-Peter can I merge and release? |
Work towards: onflow/developer-grants#148
Description
(taken from onflow/developer-grants#148 (comment))
Note: By convention, we consider files that contain the
_helper
substring, to be helper/utility files. Of course, this is just an initial implementation detail, feel free to suggest an alternative. The main difficulty here is that we can't distinguish from acommon.StringLocation
, if we are dealing with a contract, or with a simple script containing Cadence code. TheimportResolver
function, has business logic which rejects any imports that are not declared in theflow.json
config file.For contributor use:
master
branchFiles changed
in the Github PR explorer