Skip to content
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

Report does not contain a reference to the location of the test when using macros or helpers from another file #2722

Open
MatthiasKunnen opened this issue Mar 20, 2021 · 5 comments

Comments

@MatthiasKunnen
Copy link

When using a macro, the failure report does not include a line number that could be used to navigate to the test.

Example of the report:

  Number must be 5

  Difference:

  - 4
  + 5

  › macro (typescript/helper/macro.ts:4:7)

Reproduction: https://github.com/MatthiasKunnen/ava-line-number-reproduction.
AVA version: 3.15.0.
AVA configuration: See repo.

Proposal
Capture the line number when test is invoked and either add it to the stack trace or add it above the diff, e.g. typescript/spec/something.spec.ts:7

Notes
Interestingly, the report is a bit different when the macro is inside vs outside the spec file. This can be seen on the root commit in the reproduction repository. Example diff with the + side representing a macro outside the spec file:

Number must be 5

-typescript/spec/something.spec.ts:4

-3: const macro: Macro<[number]> = (t, number) => {
-4:     t.is(number, 5);                           
-5: }

Difference:

﹣ 4
﹢ 5

-› macro (typescript/spec/something.spec.ts:4:7)
+› macro (typescript/helper/macro.ts:4:7)
@novemberborn novemberborn changed the title Report does not contain a reference to the location of the test when using macros Report does not contain a reference to the location of the test when using macros or helpers from another file Mar 21, 2021
@novemberborn
Copy link
Member

I believe this is a known issue, or at least I'm not surprised by it, but I can't immediately find an existing issue for this either.

I believe we try to find the line where the assertion was called. But that must be within the test file. It would be interesting to find the first line from the test file and provide context for that.

@MatthiasKunnen
Copy link
Author

MatthiasKunnen commented Mar 21, 2021

I'll have a look and see if I can add the filename and line number of the test to the stack trace. In which file would you like me to add tests regarding this?

@novemberborn
Copy link
Member

In which file would you like me to add tests regarding this?

The laziest answer would be the reporter tests, but they're not easy to maintain.

The harder answer is a new self-hosted test in test/, using internal access to the raw result data. But you'll have to do some digging around for that (or leave it to me).

@MatthiasKunnen
Copy link
Author

I'll take a stab at it ;)

@novemberborn
Copy link
Member

As mentioned in #2723, #2785 adds a test.macro() to declare macros, maybe we can special case the behavior for those objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants