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

Uncaught DataCloneError: Failed to execute 'postMessage' on 'Window': An object could not be cloned. #12

Closed
bclinkinbeard opened this issue Apr 21, 2014 · 17 comments

Comments

@bclinkinbeard
Copy link
Contributor

I've not been able to isolate this to a reproducible scenario, but it seems to happen when async tests fail to end(). I also seem to encounter some false plan != count errors, not sure if that is related.

I will continue trying to isolate, but I figured I would report in case you have ideas on what could be the issue. Screen grab of console: http://cl.ly/image/2a392W0I3c3M

@bclinkinbeard
Copy link
Contributor Author

The browser based workflow just hangs if a test throws an Error. The following test properly reports a failure if run without the -b flag.

var test = require('prova')
var foo = {}

test('one', function (t) {
    foo.bar();

    t.ok(2+2, 4)
    t.end()
})

Run with -b the 'running' message stays in the browser and the DataCloneError is spit out to the console. Note that errors being thrown are common and necessary for tests involving promises.

@bclinkinbeard
Copy link
Contributor Author

Line 69 of browser-reporter.js, window.parent.postMessage(msg, document.location.origin) is what is throwing the DataCloneError.

@bclinkinbeard
Copy link
Contributor Author

OK, I've reached my limit of understanding now. :)

Based on some searching and StackOverflow answers, the DataCloneError is from trying to pass an object with methods to postMessage. Indeed, changing the line to window.parent.postMessage(JSON.parse(JSON.stringify(msg)), document.location.origin); does prevent the runner from hanging.

Unfortunately, uncaught errors still cause tests to fail, which makes testing promises impossible. Hopefully there is any easy fix, because I have to switch back to tape in the meantime.

@azer
Copy link
Owner

azer commented Apr 21, 2014

I'll look at this tonight

@bclinkinbeard
Copy link
Contributor Author

Cool. The thrown error actually seems to fail the test in tape now too, but I wasn't having this issue a week or so ago when using prova so I'm not sure what is going on. I will be around later so let me know if you need or want help debugging.

@azer
Copy link
Owner

azer commented Apr 21, 2014

We can fix the Tape version to something like 2.5 or earlier

@bclinkinbeard
Copy link
Contributor Author

This actually seems to be an issue with Angular's mock $httpBackend. Probably safe to ignore for now.

@bclinkinbeard
Copy link
Contributor Author

This wasn't prova's fault. Sorry 'bout that.

@joeybaker
Copy link
Contributor

I'm running into the same problem, but with a different cause. I've isolated the problem to:

var test = require('prova')
  , fn = function(){}

test('sample', function(t){
  t.equal(
    fn
    , 'object'
  )

  t.end()
})

I know this test doesn't do anything, but it does cause Prova to hang, when it should error.

@bclinkinbeard
Copy link
Contributor Author

Does modifying browser-reporter.js correct the behavior for you as well? #12 (comment)

@joeybaker
Copy link
Contributor

@bclinkinbeard silly me for just skimming! Yes, the prevents the hang, but returns a completely unhelpful error:


Browser: Chrome v34 Engine: WebKit v537.36 OS: Mac OS X v10.9.2

TypeError: undefined is not a function http://0.0.0.0:7559/assets/run.js
v
25082.     catch (err) {
25083.         this.error(err);
25084.         this._end();
^
Error: TypeError: undefined is not a function
at Test.assert [as _assert] (http://0.0.0.0:7559/assets/run.js:25202:54)
at Test.error.Test.ifError.Test.ifErr.Test.iferror (http://0.0.0.0:7559/assets/run.js:25310:10)
at Test.run (http://0.0.0.0:7559/assets/run.js:25083:14)
at next (http://0.0.0.0:7559/assets/run.js:24890:15)}

…which I wasn't able to quickly track down to a prova file.

@bclinkinbeard
Copy link
Contributor Author

Cool, yea, I just wanted to verify that that fixes the hang for you as well. Not sure if it is something that should be done "just in case" or if fixing the underlying issue would make it moot.

I remember seeing some of that Test.error.Test.ifError.Test.ifErr.Test.iferror stuff too, but my problems ended up being due to uncaught errors elsewhere. Doesn't look like anything in your code could be throwing errors.

@joeybaker
Copy link
Contributor

I'm weirded out by the fact that stringifying and then parsing the JSON would be a fix. That seems … not correct. Maybe there's a race condition somewhere?

@bclinkinbeard
Copy link
Contributor Author

Yea, it's just a hack to strip methods off of the passed object since that is what triggers the DataCloneError because postMessage won't relay objects with methods. Would definitely be better if fixing the root cause (whatever it is) meant not needing to worry about the passed objects.

@joeybaker
Copy link
Contributor

Ah! That makes sense. Thanks!

@azer
Copy link
Owner

azer commented May 12, 2014

I had same error today and just shipped the parse(stringify( fix as 1.7.3. It should be fixed now

@bclinkinbeard
Copy link
Contributor Author

Cool, thanks!

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

No branches or pull requests

3 participants