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

getting AssertionError stack traces in server code #147

Open
welelay opened this issue Dec 16, 2015 · 4 comments
Open

getting AssertionError stack traces in server code #147

welelay opened this issue Dec 16, 2015 · 4 comments

Comments

@welelay
Copy link

welelay commented Dec 16, 2015

Hi,
I'm writing server-side tests by calling

server.execute(function(){
 var a = doSomething();
 expect(a).to.exist;
 var b = doSomethingWithA(a);
 expect(b).to.exist;
});

Guess what ? I get an AssertionError "expected undefined should exist"
What's the culprit: var a= or var b= ?
No way to tell.

So I've dug in the gagarin codebase and added

chai.Assertion.includeStack = true;

at backdoor.js:15

and

  console.log("COMPILED", code);

to the compile() function also in backdoor.js.

Now I get:

server  COMPILED function (chai, Fiber, expect, assert, either) {
 server    return function () {
 server      'use strict';
 server      return (function (userFunc, getClosure, action) {
 server        try {
 server          console.log(action);
 server          return action(userFunc, getClosure);
 server        } catch (err) {
 server          console.error('ERR', err);
 server          return { error: err.message, stack: err.stack, closure: getClosure() };
 server        }
 server      })(
 server        function () {
server                var a = doSomething();
server                expect(a).to.exist;
server                var b = doSomethingWithA(a);
server                expect(b).to.exist;       },
 server        function () {
 server          return {  };
 server        },
 server        arguments[arguments.length-1]
 server      );
 server    }
 server  }

and

AssertionError: expected undefined to exist\n    at [object Object].<anonymous> (...chai/core/assertions.js:340:10)\n    at [object Object].Object.defineProperty.get (..chai/utils/addProperty.js:35:29)\n    at Object.<anonymous> (evalmachine.<anonymous>:15:32)\n    at packages/anti_gagarin/meteor/backdoor.js:44:1\n    at userId (evalmachine.<anonymous>:7:16)\n    at Object.<anonymous> (evalmachine.<anonymous>:12:7)\n    at [object Object].Meteor.methods./gagarin/execute (packages/anti_gagarin/meteor/backdoor.js:42:1)\n    at [object Object].methodMap.(anonymous function) (packages/meteorhacks_kadira/lib/hijack/wrap_session.js:164:1)\n    at maybeAuditArgumentChecks (livedata_server.js:1698:12)\n    at livedata_server.js:708:19

So I can count lines and deduce that the line in error is var b=.
How can I automate this?

@welelay
Copy link
Author

welelay commented Dec 16, 2015

I've hacked something in #137.
I'll test it some more...

@apendua
Copy link
Member

apendua commented Dec 16, 2015

It's a very important problem you are pointing out here. I've been working on this some time ago and eventually gave up because it turned out stack traces are totally unpredictable in browsers when it comes to evaluating dynamically included code like in our case. So I gave up, but it's probably something that will need to be solved eventually. Please let me know about the results of your research.

@welelay
Copy link
Author

welelay commented Dec 16, 2015

Good to know.
I've not tackled the browser.execute() stacktraces yet.
The latest commit in the PR is for server.execute(), though.
Maybe it's more reliable...

@apendua
Copy link
Member

apendua commented Dec 21, 2015

Issue #52 is related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants