Experience-Monks / hihat

:tophat: local Node/Browser development with Chrome DevTools
MIT License
444 stars 19 forks source link

line numbers not maching #28

Open danielepolencic opened 9 years ago

danielepolencic commented 9 years ago

Hello,

I have the following snippet of code:

var test = require('tape');

test('true', function (t) {
  t.plan(1);
  t.equal(true, false);
});

When I run the script through node I get:

TAP version 13
# true
not ok 1 should be equal
  ---
    operator: equal
    expected: false
    actual:   true
    at: Test.<anonymous> (/Users/danielepolencic/Sites/platform/myaccount-core/src/main/registration/app/test/directives/test.js:6:5)
  ...

1..1
# tests 1
# pass  0
# fail  1

However when I run the same code in hihat I get:

default_stream.js:26 TAP version 13
default_stream.js:26 # true
default_stream.js:26 not ok 1 should be equal
default_stream.js:26   ---
default_stream.js:26     operator: equal
default_stream.js:26     expected: false
default_stream.js:26     actual:   true
default_stream.js:26     at: Test.assert (http://localhost:9541/app/test/directives/test.js:5424:17)
default_stream.js:26   ...
default_stream.js:26 
default_stream.js:26 1..1
default_stream.js:26 # tests 1
default_stream.js:26 # pass  0
default_stream.js:26 # fail  1

The error in the assert is pointing to tape and not the test. Line numbers are not matching either. Any idea how this could be fixed?

mattdesl commented 9 years ago

From what I understand this is an issue to do with source maps. It's probably not an easy fix.

Any insight / suggestions welcome, though. :smile:

danielepolencic commented 9 years ago

I borrowed the code from mattdesl/test-electron-source-maps and ran few tests.

When I run hihat test I can't get the source maps to work. When I run npm run electron, source map works fine (after the first attempt).

Is there any settings in hihat that may prevent source maps to work properly? Perhaps a race condition?

EDIT: I changed this line and hardcoded the index.html file generated in test-electron-source-maps:

    .listen(port, host, function () {
      var hostname = (host || 'localhost')
      var uri = 'http://' + hostname + ':' + port + '/'
      emitter.emit('connect', {
        uri: 'file:///Users/danielepolencic/Sites/test-electron-source-maps/index.html'
      })
    })

and the source map works just fine. I guess the issue could be somewhere between the watchify server and serving the file?

mattdesl commented 9 years ago

Thanks for looking into this. I'll have to take a closer look this week.

There are two outstanding bugs that are causing issues with source maps. https://github.com/Jam3/hihat/issues/17 https://github.com/Jam3/hihat/issues/18

You should be able to get around them by serving the bundle under a different name, eg:

hihat index.js --serve bundle.js

Then, make sure to refresh after the first run. Hopefully I can figure out why this is happening so it can be properly fixed. If you're experiencing a different issue, let me know. :smile:

danielepolencic commented 9 years ago

Just to recap: this bug is actually 2 bugs.

As for the latter, I found out why: https://github.com/substack/tape/issues/192

This has nothing to do with hihat.

If the sourcemap bug is already logged as another ticket, this issue can be closed as a duplicate.