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

line number is mismatch when use console.log #283

Closed
m0a opened this issue Jul 29, 2017 · 12 comments
Closed

line number is mismatch when use console.log #283

m0a opened this issue Jul 29, 2017 · 12 comments

Comments

@m0a
Copy link

m0a commented Jul 29, 2017

thank you for great tool!
i use console.log in test code.
but line number mismatch.
i created test project. here https://github.com/m0a-mystudy/typescript/blob/master/jest-line-number/line-number.test.ts

out put is here

FAIL  ./line-number.test.ts
  ● line number test

    SyntaxError: test error line:3

      at Suite.<anonymous> (line-number.test.ts:3:14)
      at Object.<anonymous> (line-number.test.ts:2:5)
          at Promise (<anonymous>)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:169:7)

  ● line number test2

    SyntaxError: test error line:10

      at Suite.<anonymous> (line-number.test.ts:10:14)
      at Object.<anonymous> (line-number.test.ts:9:5)
          at Promise (<anonymous>)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:169:7)

  ✕ line number test (115ms)
  ✕ line number test2 (17ms)
  ✓ line number test4 (1ms)

Test Suites: 1 failed, 1 total
Tests:       2 failed, 1 passed, 3 total
Snapshots:   0 total
Time:        1.462s, estimated 2s
Ran all test suites.
  console.log line-number.test.ts:14
    hello line:17

output console.log line-number.test.ts:14
line number mismatch. why?

@kulshekhar
Copy link
Owner

@m0a would it be possible for you to create a minimal repo with only the test project?

@m0a
Copy link
Author

m0a commented Jul 29, 2017

@kulshekhar
Copy link
Owner

@m0a thanks

On testing, I got the same output as you did. The line number for console.log does look wrong.

What's confusing is that the other line numbers are correctly shown. I'll try to take a closer look at this

@kulshekhar
Copy link
Owner

ts-jest uses source-map-support to ensure that the line numbers are correct. source-map-support only takes care of the stack traces related to errors. That's why error related stack traces have the correct line numbers while console.log doesn't. I don't think there's much we can do in ts-jest to fix this behavior

@kulshekhar
Copy link
Owner

I've closed this for now but if you think this can be fixed here, this issue can be reopened.

@GeeWee
Copy link
Collaborator

GeeWee commented Jul 31, 2017

I think maybe we'll be able to patch the console the same way source-map support patches the error logs. At the minimum we need to document this somewhere.
I personally consider this one of the higher priority cases, considering how ubiquitous print debugging is.

@GeeWee GeeWee reopened this Jul 31, 2017
@kulshekhar
Copy link
Owner

@GeeWee I'm not sure a patch for this issue belongs in ts-jest. If we're doing this, it might be better to do it in a new project which can then be used from ts-jest. Thoughts?

As an aside, the last time I had checked (quite some time back), source-map-support only worked with nodejs that used V8

@GeeWee
Copy link
Collaborator

GeeWee commented Jul 31, 2017

That's definitely a good idea. Maybe source-map-support would be interested?

@GeeWee
Copy link
Collaborator

GeeWee commented Aug 1, 2017

I have raised the issue in evanw/node-source-map-support#186

@GeeWee
Copy link
Collaborator

GeeWee commented Aug 9, 2017

I have also raised the issue in the jest repo.

@pelotom
Copy link
Contributor

pelotom commented Aug 15, 2017

Thanks for pursuing this @GeeWee, this is a big annoyance!

@kulshekhar
Copy link
Owner

Closing as there's nothing we can do about this in ts-jest

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

4 participants