cucumber / godog

Cucumber for golang
MIT License
2.21k stars 249 forks source link

Calculated step duration is wrong #615

Closed iaroslav-ciupin closed 1 month ago

iaroslav-ciupin commented 1 month ago

👓 What did you see?

Produced following report.json

[
    {
        "uri": "test/test.feature",
        "id": "test",
        "keyword": "Feature",
        "name": "Test",
        "description": "",
        "line": 1,
        "elements": [
            {
                "id": "test;test",
                "keyword": "Scenario",
                "name": "Test",
                "description": "",
                "line": 2,
                "type": "scenario",
                "steps": [
                    {
                        "keyword": "When ",
                        "name": "test",
                        "line": 3,
                        "match": {
                            "location": "api_test.go:95"
                        },
                        "result": {
                            "status": "passed",
                            "duration": 27750
                        }
                    },
                    {
                        "keyword": "Then ",
                        "name": "test2",
                        "line": 4,
                        "match": {
                            "location": "api_test.go:98"
                        },
                        "result": {
                            "status": "passed",
                            "duration": 1000527500
                        }
                    }
                ]
            }
        ]
    }
]

✅ What did you expect to see?

1st step should have duration of 1 second. 2nd step should have duration of 2 seconds.

📦 Which tool/library version are you using?

github.com/cucumber/godog v0.14.0

🔬 How could we reproduce it?

Feature file:

Feature: Test
  Scenario: Test
    When test
    Then test2

Go test file:

func Test_WrongDuration(t *testing.T) {
    tSuite := godog.TestSuite{
        ScenarioInitializer: func(ctx *godog.ScenarioContext) {
            ctx.Step("^test$", func() {
                time.Sleep(time.Second)
            })
            ctx.Step("^test2$", func() {
                time.Sleep(2 * time.Second)
            })
        },
        Options: &godog.Options{
            Format:   "cucumber",
            Paths:    []string{"test"},
            TestingT: t,
        },
    }

    code := tSuite.Run()
    if code != 0 {
        t.Fatalf("status returned %d, failed to run feature tests", code)
    }
}

📚 Any additional context?

Also not clear if duration should be rendered in nanoseconds or milliseconds. When I generate HTML report using https://github.com/myie/cucumber-html-reporter as Readme suggests, I get wrong values in HTML, because cucumber-html-reporter assumes duration is in milliseconds. Who is wrong here? is there a well-documented standard for Cucumber json format?

iaroslav-ciupin commented 1 month ago

@l3pp4rd @lonnblad can somebody of you take a look and confirm if bug is valid? also please note 2nd question about time duration units

iaroslav-ciupin commented 1 month ago

https://github.com/cucumber/godog/pull/616 opened a PR for 1st part

iaroslav-ciupin commented 1 month ago

Looks like both godog and latest version of cucumber-html-reporter are using nanoseconds and report shows duration as expected. I was initially using cucumber-html-reporter 3.0.4 as was mentioned here, which apparently doesn't expect nanoseconds. Closing issue as done.