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

findTestCaller fail to wrap the test function

Open livingmine opened this issue 7 years ago • 3 comments

if (node.loc.start.line < line &&
          node.loc.end.line > line)

evaluating each variables at that line of code resulting in:

node.loc.start.line -> 19
line -> 23
node.loc.end.line -> 22

when in my test file, this test

test('todo promise', async function (t) {
  var todo = await generateP();
  schemaShot(todo);
});
//# sourceMappingURL=test-bundle.js.map

starts from line 19 and ends at line 22. This results in the above expressions equal to false which makes specName assignment inside the if statement not executed. Hence this error

TypeError {
          message: 'Cannot read property \'filename\' of undefined',

Any idea why is this happening? Thanks!

livingmine avatar May 23 '18 12:05 livingmine

So removing the //# sourceMappingURL=test-bundle.js.map seems to fix the issue. Not sure why though, maybe it has something to do with how stack-sites works.

livingmine avatar May 23 '18 13:05 livingmine

hmm, might be bug with parsing async / await functions. What test framework are you using? Because now I mostly use snap-shot-it which registers beforeEach callback to "know" the current test accurately

bahmutov avatar May 23 '18 19:05 bahmutov

Inspired by your blog post, i'm using AVA as the test runner.

livingmine avatar May 24 '18 03:05 livingmine