Skip to content

Ava reports incorrect lines and source files with precompiled typescript #2146

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

Closed
rianadon opened this issue May 30, 2019 · 3 comments
Closed

Comments

@rianadon
Copy link

I'm currently using Ava and Instanbul's nyc to run tests compiled to typescript. The tests are compiled with tsc and sourcemaps enabled, then I run Ava with the compiled JavaScript.

If I run without nyc (ava build/tests), Ava behaves perfectly. The output of a failing test looks like this:

file  test

  /path/to/file.ts:38

   37:     const r = await t.context.axios.get('/url')
   38:     t.is(r.status, 201)                           
   39:     t.is(r.data, 'hi')

The sourcemap converts the filename to typescript and the line numbers and source files match the Typescript source code.

However, if I run with nyc (nyc ava build/tests), Ava prints JavaScript filenames, the JS source code, and incorrect line numbers:

 file  test

  /path/to/file.js:4

   3:     return (mod && mod.__esModule) ? mod : { "default": mod };
   4: };                                                            
   5: Object.defineProperty(exports, "__esModule", { value: true });

In both cases, nyc uses the correct line numbers from the source map, so it seems the issue is in the handoff between nyc and Ava.

I have no configuration for Ava as I'm not using it to compile the TS files and the guide doesn't have any other instructions, but I've installed source-map-support. I've tried setting "compileEnhancements": false and require: ["source-map-support/register"], but they make no difference.

My nyc config is:

"nyc": {                                                                                                                                                                                     
  "extension": [                                                                                                                                                                             
    ".ts",                                                                                                                                                                                   
    ".tsx"                                                                                                                                                                                   
  ],                                                                                                                                                                                         
  "exclude": [                                                                                                                                                                               
    "**/*.d.ts",                                                                                                                                                                             
    "test"                                                                                                                                                                                   
  ],                                                                                                                                                                                         
  "reporter": [                                                                                                                                                                              
    "text",                                                                                                                                                                                  
    "html"                                                                                                                                                                                   
  ]                                                                                                                                                                                          
}

If it would help I can create a minimal reproduction, but I'd first like to check that I'm not missing any configuration options.

Thanks!

@sindresorhus
Copy link
Member

Can you try without nyc? We've had reports in the past which turned out to be nyc problems, not AVA.

@rianadon
Copy link
Author

It works without nyc (see the second and third paragraphs of my first comment). So the problem could definitely be entirely with nyc. However, since nyc read the source map correctly and then Ava running within nyc didn't, I figured the issue was with both of them.

If you think it would be more suitable, I could also create an issue on the nyc repo. Or do that and close the one here.

@rianadon
Copy link
Author

Whoops I did more digging and realized this is a duplicate of #1604 (which is without using typescript but the same concept), which is related to istanbuljs/nyc#619. Sorry for wasting your time 😞.

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

No branches or pull requests

2 participants