bahmutov / snap-shot

Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
169 stars 3 forks source link

Unable to determine caller function callsite #46

Closed tivac closed 7 years ago

tivac commented 7 years ago

Trying a really simple test with snap-shot and it seems to always be unable to determine the calling function.

Using snap-shot@2.16.0, mocha@3.2.0, and node@7.7.2 on windows.

Test File

"use strict";

var snapshot = require("snap-shot");

it("should test using snapshots", () => {
    snapshot(42);
});

Output

> snapshot-testing@1.0.0 test
> mocha

  1) should test using snapshots

  0 passing (8ms)
  1 failing

  1)  should test using snapshots:
     Error: Do not have caller function callsite
      at snapshot (node_modules\snap-shot\src\index.js:63:11)
      at Context.it (test\snap-shot.test.js:6:5)

Am I doing something wrong here?

pygy commented 7 years ago

@tivac $ DEBUG=snap-shot npm run test would tell us more...

bahmutov commented 7 years ago

Yes, thanks @pygy for suggesting DEBUG constant. I suspect something bad happens due to Windows file system.

tivac commented 7 years ago

Added debug flag, no real change to the output.

C:\Users\pcavit\Desktop\snap-shot>set DEBUG=snap-shot

C:\Users\pcavit\Desktop\snap-shot>npm test

> snapshot-testing@1.0.0 test C:\Users\pcavit\Desktop\snap-shot
> mocha

  snap-shot [] +0ms
  1) should test using snapshots

  0 passing (8ms)
  1 failing

  1)  should test using snapshots:
     Error: Do not have caller function callsite
      at snapshot (node_modules\snap-shot\src\index.js:63:11)
      at Context.it (test\snap-shot.test.js:6:5)

npm ERR! Test failed.  See above for more details.

I guess I'll try to dig in. 😞

tivac commented 7 years ago

It's stack-sites

e.stack on Windows looks like this

Error: stack-sites
    at stackSites (c:\Users\pcavit\Desktop\snap-shot\node_modules\stack-sites\src\index.js:14:13)
    at snapshot (c:\Users\pcavit\Desktop\snap-shot\node_modules\snap-shot\src\index.js:54:17)
    at Context.it (c:\Users\pcavit\Desktop\snap-shot\test\snap-shot.test.js:6:5)
    at callFn (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runnable.js:345:21)
    at Test.Runnable.run (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runnable.js:337:7)
    at Runner.runTest (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:444:10)
    at c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:550:12
    at next (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:361:14)
    at c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:371:7
    at next (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:295:14)
    at Immediate.<anonymous> (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:339:5)
    at runCallback (timers.js:666:20)
    at tryOnImmediate (timers.js:639:5)
    at processImmediate [as _immediateCallback] (timers.js:611:5)

None of those lines contain (/ so they all get filtered out and dropped.

bahmutov commented 7 years ago

Haha I guess my check was really amateurish - thanks for digging and finding it!

Sent from my iPhone

On Mar 14, 2017, at 12:37, Pat Cavit notifications@github.com wrote:

It's stack-sites

e.stack on Windows looks like this

Error: stack-sites at stackSites (c:\Users\pcavit\Desktop\snap-shot\node_modules\stack-sites\src\index.js:14:13) at snapshot (c:\Users\pcavit\Desktop\snap-shot\node_modules\snap-shot\src\index.js:54:17) at Context.it (c:\Users\pcavit\Desktop\snap-shot\test\snap-shot.test.js:6:5) at callFn (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runnable.js:345:21) at Test.Runnable.run (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runnable.js:337:7) at Runner.runTest (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:444:10) at c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:550:12 at next (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:361:14) at c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:371:7 at next (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:295:14) at Immediate. (c:\Users\pcavit\Desktop\snap-shot\node_modules\mocha\lib\runner.js:339:5) at runCallback (timers.js:666:20) at tryOnImmediate (timers.js:639:5) at processImmediate [as _immediateCallback] (timers.js:611:5) None of those lines contain (/ so they all get filtered out and dropped.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

bahmutov commented 7 years ago

@tivac see if newly released version solves this, it has better stack parsing function

tivac commented 7 years ago

That fixed it, thanks for the quick turnaround @bahmutov!

tivac commented 7 years ago

@bahmutov I see that stack-sites got updated, since snap-shot doesn't use semver ranges for dependencies it looks like I'll have to manually shuffle around folders in /node_modules to get this working until a new version is published.

Any ETA on a new version of snap-shot being published to npm?

bahmutov commented 7 years ago

Found why it did not publish new version - it tested new code against project 'snap-shot-ava-test' and found that lines like are not handled properly :)

✔ sum › adds 1 + 2 to equal 3
foo
  ✖ sum › adds 1 + 2 to equal 3 snapshot Error: Could not parse stack line "    at Array.map (native)"
invalid number of parts (native) full line     at Array.map (native)
  ✖ sum-async › async concat strings Error: Could not parse stack line "    at next (native)"
invalid number of parts (native) full line     at next (native)

Opened https://github.com/bahmutov/stack-sites/issues/5 - when that one is fixed, will release.

bahmutov commented 7 years ago

ok, hope 2.16.1 is the charm!