snap-shot icon indicating copy to clipboard operation
snap-shot copied to clipboard

Single promise stack trace is missing

Open bahmutov opened this issue 8 years ago • 1 comments

See src/async-spec.js test "promise to snapshot"

// async-spec.js
const snapshot = require('.')
it.only('promise to snapshot (does nothing!)', () => {
    // straight into snapshot comparison does not work
    return Promise.resolve(20)
      .then(snapshot)
})

The reported stack does not have "async-spec.js" at all, instead only has

  snap-shot [ { functionName: 'stackSites',
  snap-shot     filename: '/Users/irinakous/git/snap-shot/node_modules/stack-sites/src/index.js',
  snap-shot     line: 14,
  snap-shot     column: 13 },
  snap-shot   { functionName: 'snapshot',
  snap-shot     filename: '/Users/irinakous/git/snap-shot/src/index.js',
  snap-shot     line: 38,
  snap-shot     column: 17 } ] +0ms

bahmutov avatar Feb 20 '17 16:02 bahmutov

The code that gets the call site is in https://github.com/bahmutov/snap-shot/blob/57eb06e3b971c155a45e5b688bf7455bd5acea52/src/index.js#L37

function snapshot (what, update) {
  const sites = stackSites()
  if (sites.length < 3) {
    // hmm, maybe there is test (like we are inside Cypress)
    if (this && this.test && this.test.title) {
      debug('no callsite, but have test title "%s"', this.test.title)
      return this.test.title
    }
    debug(sites)
    const msg = 'Do not have caller function callsite'
    throw new Error(msg)
  }

where const stackSites = require('stack-sites') from https://github.com/bahmutov/stack-sites

bahmutov avatar Feb 20 '17 16:02 bahmutov