smartystreets / goconvey

Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.
http://smartystreets.github.io/goconvey/
Other
8.25k stars 555 forks source link

Unable to View Test Coverage #253

Closed ghost closed 10 years ago

ghost commented 10 years ago

In the Web UI, the test coverage link is broken and points to: http://localhost:8080/reports/_-Users-ever-Dev-go-src-forecast.html

/Users/ever/Dev/go is my $GOPATH and /src/forecast is where the project files are being stored, so somehow the link is grabbing my $GOPATH. If I edit the link to read: http://localhost:8080/forecast.html a good looking coverage report comes up, however it's outdated and looks like it was created on my very first project save, but not since then.

If I go to $GOPATH/src/github.com/smartysteets/goconvey/web/client/reports I can see two files related to my project:

  1. forecast.html (the outdated coverage report)
  2. forecast.txt which contains:
mode: set
_/Users/ever/Dev/go/src/forecast/app.go:16.45,18.2 1 1
_/Users/ever/Dev/go/src/forecast/app.go:20.13,39.2 5 0

This .txt file updates on every project file save and appears to be working correctly. In the WEB UI, when I hover over coverage, it says 16.7% test coverage which appears correct and in line with what the .txt file is reporting.

So, it looks like the UI link and .html report are broken, but the UI coverage % and .txt file are working.

A couple questions:

  1. How do I fix the link on the Web UI to pull up the HTML report?
  2. How do I get the HTML report to update when I save a project file?

Version / Settings:

go version go1.3.3 darwin/amd64
2014/10/24 10:18:05 goconvey.go:52: Initial configuration: [host: 127.0.0.1] [port: 8080] [poll: 250ms] [cover: true]

Mac / OS X Yosemite

Great tool by the way! Everything else has been super easy to use.

mdwhatcott commented 10 years ago

@everdev - The href of that coverage link does look strange. When I run goconvey at $GOPATH/src/github.com/smartystreets/goconvey/examples here is what the coverage url for that package is:

http://localhost:8080/reports/github.com-smartystreets-goconvey-examples.html

So, the pattern for the url path should be /reports/import-path-with-hyphens-not-slashes.html. It should not include any path elements above your project's import path (so in your case it should NOT include /Users/ever/Dev/go).

Just to confirm, your GOPATH is:

/Users/ever/Dev/go

And your project is found at:

/src/forecast

I would actually expect your code to be here:

 Users/ever/Dev/go/src/forecast
  1. Is that what you meant to write?
  2. Do you have anything unconventional with symbolic links going on?
  3. Do you get a working coverage link when you run goconvey from the examples package ($GOPATH/src/github.com/smartystreets/goconvey/examples)?
ghost commented 10 years ago
  1. Yes, the $GOPATH is correct and the code is as you corrected at $GOPATH/src/forecast
  2. no symbolic links
  3. No, the URL from that reports goes to: http://localhost:8080/reports/_-Users-ever-Dev-go-src-github.com-smartystreets-goconvey-examples.html

It looks like the URL is being generated here: https://github.com/smartystreets/goconvey/blob/4c4f4172c0ec2894b0b5c850212ef370333bb8b0/web/client/index.html#L161

with the variable: {{PackageName|boldPkgName}}

mdwhatcott commented 10 years ago

@everdev - Ok, here's something I'd like to have you try:

  1. Start the goconvey server
  2. In another terminal run curl http://localhost:8080/latest
  3. Paste the resulting JSON here in a comment here (or let me know if you'd like to share it more privately). I'm most interested to see the value of the PackageName field for the package in question.
mdwhatcott commented 10 years ago

For my own reference, I think the actual line that generates the coverage link is here:

https://github.com/smartystreets/goconvey/blob/4c4f4172c0ec2894b0b5c850212ef370333bb8b0/web/client/index.html#L143

There are two kinds of links being generated in the left side bar, coverage report links and little tiny scroll arrows. I'm still baffled to see an underscore in the path of the report link.

ghost commented 10 years ago

Here's the JSON output:

{"Packages":[{"PackageName":"forecast","Elapsed":0.011,"Coverage":3.7,"Outcome":"passed","BuildOutput":"","TestResults":[{"TestName":"TestUserName","Elapsed":0,"Passed":true,"Skipped":false,"File":"","Line":0,"Message":"","Error":"","Stories":[{"Title":"Given a name","File":"/Users/ever/dev/go/src/forecast/forecast_test.go","Line":18,"Depth":0,"Assertions":[],"Output":""},{"Title":"It should create an appropriate filename","File":"/Users/ever/dev/go/src/forecast/forecast_test.go","Line":16,"Depth":1,"Assertions":[{"File":"","Line":0,"Expected":"","Actual":"","Failure":"","Error":null,"StackTrace":"","Skipped":false}],"Output":""}]}]},{"PackageName":"forecast/csvs","Elapsed":0,"Coverage":-1,"Outcome":"no go code","BuildOutput":"can't load package: package forecast/csvs: no buildable Go source files in /Users/ever/dev/go/src/forecast/csvs","TestResults":[]}],"Revision":"2014-10-26 12:22:27.772210686 -0700 PDT","Paused":false}
mdwhatcott commented 10 years ago

@everdev - Hmm. The PackageName is correct which surprises me--I thought for sure it would have that weird leading underscore in it. I'm stumped. If you run the commands manually which generate the coverage profile do you still see the leading underscore in the output file?

go test -cover -coverprofile out.txt
ghost commented 10 years ago

That worked! The URL is now: http://localhost:8080/reports/forecast.html

And it remains correct even after restarting goconvey, so it looks to be fixed.

I've never run tests manually before on this project. I wonder if it needs to be executed once to establish the configuration or set the right permissions with goconvey.

In any event, thanks for helping. It's a great tool and quite impressive for a relatively new language. It's made learning Go a lot of fun.

mdwhatcott commented 10 years ago

@everdev - Phew! Glad it's working for you.

sandy-adi commented 4 years ago

image It appears like my agent is running without coverage, how can I enable this?