-
Notifications
You must be signed in to change notification settings - Fork 41
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
Use bisect PPX instead of Jest coverage #261
Conversation
First successful coverage report by bisect ppx: https://coveralls.io/builds/30172931 |
__tests__/Relude_IO_test.re
Outdated
@@ -2,6 +2,9 @@ open Jest; | |||
open Expect; | |||
open Relude.Globals; | |||
|
|||
[@coverage exclude_file]; | |||
afterAll(Bisect.Runtime.write_coverage_data); |
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.
Argh :/ I think we need some better way of doing this globally in a Jest project. The problem I ran into is that when Jest exits, it somehow doesn't trigger process.on('exit')
hooks.
Also, a near-future version of Bisect will support excluding files by pattern in the ppx-flags
. In the meantime, you could use an exclusions file: https://github.com/aantron/bisect_ppx/blob/master/doc/advanced.md#Excluding
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.
In the meantime, you could use an exclusions file: https://github.com/aantron/bisect_ppx/blob/master/doc/advanced.md#Excluding
I've tried without success, could you please advise?
I added a dune
file in the root of project:
(preprocess (pps bisect_ppx --exclusions bisect.exclude))
(preprocessor_deps (file bisect.exclude))
And added a bisect.exclude
file next to dune
:
file regexp "*_test.bs.js"
file regexp "node_modules/*"
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.
I understood that you are building with BuckleScript, so this should go into bsconfig.json
, not a dune
file. I think (haven't tried) you can pass the option like this:
"ppx-flags": [["bisect_ppx/ppx", "--exclusions", "bisect.exclude"]]
Then, the file patterns are regexps, not globs, so
file regexp ".*_test.bs.js"
and you won't be able to exclude node_modules
from your project, because instrumentation of bs-bastet is controlled from the upstream node_modules/bs-bastet/bsconfig.json
, and is best disabled by rescript-lang/rescript#3761.
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.
it seems like bisect has not supported relative path of exclusion file:
"ppx-flags": [["bisect_ppx/ppx", "--exclusions", "bisect.exclude"]]
where got errors:
> relude@0.61.0 build /Users/jihchi/Repos/relude
> bsb -make-world
[11/11] Building src/runtime/bucklescript/runtime-Bisect.cmj
[81/81] Building bastet/src/Test-BsBastet.cmj
[5/5] Building src/jest.cmj
[1/456] Building __tests__/Relude_Eq_test.reast
FAILED: __tests__/Relude_Eq_test.reast
/Users/jihchi/Repos/relude/node_modules/bs-platform/darwin/bsc.exe -w +A-4-40-42 -warn-error +A -color always -ppx '/Users/jihchi/Repos/relude/node_modules/bisect_ppx/ppx --exclusions bisect.exclude' -bs-no-version-header -bs-super-errors -o __tests__/Relude_Eq_test.reast -bs-syntax-only -bs-binary-ast /Users/jihchi/Repos/relude/__tests__/Relude_Eq_test.re
File "_none_", line 1:
Error: I/O error: bisect.exclude: No such file or directory
We've found a bug for you!
/Users/jihchi/Repos/relude/__tests__/Relude_Eq_test.re
Error while running external preprocessor
Command line: /Users/jihchi/Repos/relude/node_modules/bisect_ppx/ppx --exclusions bisect.exclude '/var/folders/wm/lp071lgd09nb3_mv_9pthcs00000gn/T/camlppx7aa76b' '/var/folders/wm/lp071lgd09nb3_mv_9pthcs00000gn/T/camlppx94f0b2'
( ...omitted repeated error with different re file... )
And then, I changed to absolute path:
"ppx-flags": [
["bisect_ppx/ppx", "--exclusions", "/Users/jihchi/Repos/relude/bisect.exclude"]
]
where got another errors:
> relude@0.61.0 build /Users/jihchi/Repos/relude
> bsb -make-world
[11/11] Building src/runtime/bucklescript/runtime-Bisect.cmj
[81/81] Building bastet/src/Test-BsBastet.cmj
[5/5] Building src/jest.cmj
[1/456] Building __tests__/Relude_Eq_test.reast
FAILED: __tests__/Relude_Eq_test.reast
/Users/jihchi/Repos/relude/node_modules/bs-platform/darwin/bsc.exe -w +A-4-40-42 -warn-error +A -color always -ppx '/Users/jihchi/Repos/relude/node_modules/bisect_ppx/ppx --exclusions /Users/jihchi/Repos/relude/bisect.exclude' -bs-no-version-header -bs-super-errors -o __tests__/Relude_Eq_test.reast -bs-syntax-only -bs-binary-ast /Users/jihchi/Repos/relude/__tests__/Relude_Eq_test.re
open Jest
open Expect
open Relude.Globals
[@@@coverage exclude_file]
;;afterAll Bisect.Runtime.write_coverage_data
( ... omitted re content ...)
File "/var/folders/wm/lp071lgd09nb3_mv_9pthcs00000gn/T/camlppx931ed4", line 1:
Error: I can't decide whether /var/folders/wm/lp071lgd09nb3_mv_9pthcs00000gn/T/camlppx931ed4 is an implement
ation or interface file
We've found a bug for you!
/Users/jihchi/Repos/relude/__tests__/Relude_Eq_test.re
Error while running external preprocessor
Command line: /Users/jihchi/Repos/relude/node_modules/bisect_ppx/ppx --exclusions /Users/jihchi/Repos/relude/bisect.exclude '/var/folders/wm/lp071lgd09nb3_mv_9pthcs00000gn/T/camlppx08d86e' '/var/folders/wm/lp071lgd09nb3_mv_9pthcs00000gn/T/camlppx931ed4'
( ...omitted repeated error with different re file... )
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.
These are probably two issues:
- BuckleScript is running Bisect from some unexpected directory (Bisect does support relative paths).
- There is something wrong with assumptions Bisect makes about the order of arguments coming from BuckleScript.
Could you push your latest code, that triggers these errors, into this branch, and I'll fix as much of this as I can in Bisect?
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.
Ok aantron/bisect_ppx#310 and aantron/bisect_ppx#311 fixed it at least in my testing. I'm waiting for CI to build binaries, and then I'll push release 2.3.2 to npm. I looked at the report, and it looks like test cases were excluded successfully. bs-bastet is still included, but that's waiting on BuckleScript.
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.
2.3.2 is in npm with the fixes.
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.
I looked at the report, and it looks like test cases were excluded successfully.
I guess that's not what I checked, since the exclude attributes were still inside each test file :/
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.
I looked at the report, and it looks like test cases were excluded successfully.
I guess that's not what I checked, since the exclude attributes were still inside each test file :/
--exclusions
works with version >=2.3.2
. thanks for speedy fixing on bisect ppx!
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.
BTW, I was wrong about bisect.exclude
, it should be .re
extension:
Lines 1 to 2
in
777d04d
file regexp ".*_test\.re$"
file regexp ".*\/testUtils\/.*\.re$"
Lines 1 to 2 in 777d04d
file regexp ".*_test\.re$" | |
file regexp ".*\/testUtils\/.*\.re$" |
Latest code coverage report: https://coveralls.io/builds/30182377
package.json
Outdated
@@ -32,6 +33,7 @@ | |||
"license": "MIT", | |||
"devDependencies": { | |||
"@glennsl/bs-jest": "^0.5.1", | |||
"bisect_ppx": "^2.3.1", |
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.
bisect_ppx has to be a regular dep; see aantron/bisect_ppx#309 (comment). This is because the ppx-flags in bsconfig.json
cause Bisect to always be called. It's just when BISECT_ENABLE=yes
is missing, Bisect leaves the code clean and uninstrumented. But the code still gets passed through Bisect.
Once BuckleScript releases dev ppx-flags
(rescript-lang/rescript#3761) in the next release, it will be correct to move bisect_ppx
to devDependencies
, which is where it properly belongs :)
If you can find a way to add an exit hook to Jest in one place, please let me know. Having to add Bisect will need a command-line flag for excluding files soon, as part of the improved future BuckleScript integration I've linked too many times :) I might as well add that now, so you can avoid a separate exclusions file, which is also awkward. It's going to allow passing regexps on the command line (i.e. through |
Bisect_ppx "ppx-flags": [
["bisect_ppx/ppx",
"--exclude-files", ".*_test\\.re",
"--exclude-files", ".*\/testUtils\/.*\\.re"]
] but I want to hold off on a release until the Jest exit hook issue. |
Just wanted to thank you both for the work you're doing on this! I'm excited to see where it ends up. |
Yeah, thank you for taking a stab at this! |
Ok, "setupFilesAfterEnv": ["bisect_ppx/src/runtime/bucklescript/jest.js"] should be enough. Thanks for pushing this so we can smooth out the rough corners of the integration. There is still some work left on the BuckleScript side to exclude bs-bastet and make Bisect into a true dev-only dependency. |
This PR is better and cleaner now! Thanks @aantron for the help on bisect ppx and make this happen! |
Great :) Is that a comparison of Bisect (new) and Jest (old)? I got confused because of the big screenshot :) |
BTW, it's best to use the local HTML report ( |
I basically use Coveralls only for the GitHub status and/or nag comment, or if anyone wants to examine the coverage without generating a report locally. As a developer, I use the HTML report during development (or the |
I notice the title is no longer "WIP" and the PR is no longer marked as a draft! :) How are we feeling about this? I glanced through the PR, and I trust the two of you to self-review more than I trust myself on this one, but it looks good to me. |
It looks right to me. |
Oh wow, I just noticed that this gives Coveralls everything it needs to show the real report:
This is super exciting, and I'm ready to merge if you feel good about it @jihchi |
I think my only reservation is that bisect-ppx has to be listed as a dependency at this time, rather than a devDependency. How close are they to supporting ppxs as devDependencies? If it's a long way off, we can probably just merge this, but I'd rather it be a devDependency. |
@bobzhang has suggested that the feature needed for Bisect_ppx to become a devDependency may be included in the next BuckleScript release. |
Since |
Ok, we might as well just merge it then. I'll open an issue to make it a devDependency when that is possible to do. |
Thanks again @aantron for the help. Thanks @mlms13 , @andywhite37 |
Relevant issue: #156
This is an attempt to try bisect ppx for code coverage and see how it goes.