-
Notifications
You must be signed in to change notification settings - Fork 106
iframe, embed, and objects intermittently fail, onLoadFinished gets called multiple times #144
Comments
I'm not really following what you're asking for. You want to have iframes with src attributes, but don't want them to load the src? Why not set all of the src URLs to a blank page on localhost? |
I've done poorly at describing this :) I've written a very small unit test that describes my situation: Codeindex.html<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Mocha Spec Runner</title>
<link rel="stylesheet" href="bower_components/mocha/mocha.css">
</head>
<body>
<div id="mocha"></div>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="bower_components/chai/chai.js"></script>
<script>
var assert = chai.assert;
var expect = chai.expect;
var should = chai.should();
</script>
<script src="spec/test.js"></script>
<script>
if (navigator.userAgent.indexOf('PhantomJS') < 0) {
mocha.run();
}
</script>
</body>
</html> spec/test.js'use strict';
(function() {
describe('loading content through html src\'s', function() {
it('should work just fine when tests end quickly', function() {
$('body').append('<embed src="https://www.youtube.com/v/VpXUIh7rlWI">');
});
it('should work just fine when tests end after a while', function(done) {
$('body').append('<embed src="https://www.youtube.com/v/VpXUIh7rlWI">');
setTimeout(done, 1000);
});
});
})(); Running grunt-contrib-connect and opening them in my browser (Chrome) passes the tests. Running grunt-contrib-connect and having grunt-mocha point at them using the urls parameter doesn't just fail the test, the whole suite crashes: output
The first test, when run alone, works just fine in all cases. The second test, when run alone, fails in all cases. These aren't the actual tests I'm wanting to run, just a stripped down version that illustrates the issue. I have some code I'm unit testing that affects only embeds/objects/iframes with specific values for their src, so setting them to localhost isn't really a usable substitute. |
Ah, I see. https://github.com/kmiyashiro/grunt-mocha/blob/master/tasks/mocha.js#L98-L103 All solutions to this I've seen online are hacks. One such hack is just to remove the |
I have a few tests that inject iframes, embeds, and/or objects. The more of these I have, the more likely my tests are to fail. However, they don't fail consistently. Running with debug, the tail end of the errors are:
[D] ["phantomjs","mocha.suite",{"title":"youtube-button-put-on-videos","fullTitle":"youtube-button-put-on-videos"}]
[D] ["phantomjs","mocha.suite",{"title":"embed","fullTitle":"youtube-button-put-on-videos embed"}]
[D] ["phantomjs","mocha.test",{"title":"should be on youtube embeds","fullTitle":"youtube-button-put-on-videos embed should be on youtube embeds"}]
[D] ["phantomjs","onResourceRequested","https://www.youtube.com/v/VpXUIh7rlWI"]
[D] ["phantomjs","mocha.pass",{"title":"should be on youtube embeds","fullTitle":"youtube-button-put-on-videos embed should be on youtube embeds","state":"passed","duration":7}]
[D] ["phantomjs","mocha.test end",{"title":"should be on youtube embeds","fullTitle":"youtube-button-put-on-videos embed should be on youtube embeds","state":"passed","duration":7}]
[D] ["phantomjs","onResourceError","https://www.youtube.com/v/VpXUIh7rlWI","Operation canceled"]
[D] ["phantomjs","onResourceReceived","https://www.youtube.com/v/VpXUIh7rlWI"]
[D] ["phantomjs","onLoadFinished","success"]
[D] ["phantomjs","onLoadFinished","success"]
[D] ["phantomjs","onLoadFinished","success"]
[D] ["phantomjs","onLoadFinished","success"]
[D] ["phantomjs","onLoadFinished","success"]
[D] ["phantomjs","onLoadFinished","fail"]
[D] ["phantomjs","fail.load","http://localhost:9500/index.html"]
onLoadFinished gets called multiple times. Is there a way to keep phantomjs from loading the iframes, embeds, and objects' sources? I need them to keep their src attributes for my tests.
The text was updated successfully, but these errors were encountered: