Comments (3)
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?
from grunt-mocha.
I've done poorly at describing this :)
I've written a very small unit test that describes my situation:
Code
index.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
$ grunt test --debug
Running "jshint:all" (jshint) task
[D] Task source: PATH_TO_PROJECT/node_modules/grunt-contrib-jshint/tasks/jshint.js
✔ No problems
Running "connect:test" (connect) task
[D] Task source: PATH_TO_PROJECT/node_modules/grunt-contrib-connect/tasks/connect.js
Started connect web server on http://localhost:9500
Running "mocha:all" (mocha) task
[D] Task source: PATH_TO_PROJECT/node_modules/grunt-mocha/tasks/mocha.js
Testing: http://localhost:9500/index.html
[D] ["PATH_TO_PROJECT/node_modules/grunt-mocha/phantomjs/main.js","/var/folders/ys/brqfgc211bn2d1_d5nwy24_00000gn/T/1425536366786.3347","http://localhost:9500/index.html","{\"timeout\":5000,\"inject\":\"PATH_TO_PROJECT/node_modules/grunt-mocha/phantomjs/bridge.js\",\"phantomScript\":\"PATH_TO_PROJECT/node_modules/grunt-mocha/phantomjs/main.js\",\"logErrors\":false,\"growlOnSuccess\":true,\"run\":true}"]
[D] ["phantomjs","private","version",{"major":1,"minor":9,"patch":8}]
[D] ["phantomjs","onResourceRequested","http://localhost:9500/index.html"]
[D] server GET /index.html 200 961 - 9 ms
[D] server GET /bower_components/mocha/mocha.css 200 4007 - 4 ms
[D] server GET /spec/test.js 200 493 - 2 ms
[D] server GET /bower_components/mocha/mocha.js 200 117185 - 5 ms
[D] server GET /bower_components/chai/chai.js 200 120817 - 4 ms
[D] server GET /bower_components/jquery/dist/jquery.js 200 247387 - 5 ms
[D] ["phantomjs","onUrlChanged","http://localhost:9500/index.html"]
[D] ["phantomjs","onResourceRequested","http://localhost:9500/bower_components/mocha/mocha.css"]
[D] ["phantomjs","onResourceRequested","http://localhost:9500/bower_components/jquery/dist/jquery.js"]
[D] ["phantomjs","onResourceRequested","http://localhost:9500/bower_components/mocha/mocha.js"]
[D] ["phantomjs","onResourceRequested","http://localhost:9500/bower_components/chai/chai.js"]
[D] ["phantomjs","onResourceRequested","http://localhost:9500/spec/test.js"]
[D] ["phantomjs","onResourceReceived","http://localhost:9500/index.html"]
[D] ["phantomjs","onResourceReceived","http://localhost:9500/bower_components/mocha/mocha.css"]
[D] ["phantomjs","onResourceReceived","http://localhost:9500/spec/test.js"]
[D] ["phantomjs","onResourceReceived","http://localhost:9500/bower_components/mocha/mocha.js"]
[D] ["phantomjs","onResourceReceived","http://localhost:9500/bower_components/chai/chai.js"]
[D] ["phantomjs","onResourceReceived","http://localhost:9500/bower_components/jquery/dist/jquery.js"]
[D] ["phantomjs","onInitialized"]
[D] ["phantomjs","onResourceRequested","http://localhost:35729/livereload.js?snipver=1"]
[D] ["phantomjs","onResourceError","http://localhost:35729/livereload.js?snipver=1","Connection refused"]
[D] ["phantomjs","onResourceReceived","http://localhost:35729/livereload.js?snipver=1"]
[D] ["phantomjs","inject","PATH_TO_PROJECT/node_modules/grunt-mocha/phantomjs/bridge.js"]
[D] ["phantomjs","mocha.start",{}]
[D] ["phantomjs","mocha.suite",{"title":"","fullTitle":""}]
[D] ["phantomjs","onLoadFinished","success"]
[D] ["phantomjs","mocha.suite",{"title":"loading content through html src's","fullTitle":"loading content through html src's"}]
[D] ["phantomjs","mocha.test",{"title":"should work just fine when tests end quickly","fullTitle":"loading content through html src's should work just fine when tests end quickly"}]
[D] ["phantomjs","onResourceRequested","https://www.youtube.com/v/VpXUIh7rlWI"]
[D] ["phantomjs","mocha.pass",{"title":"should work just fine when tests end quickly","fullTitle":"loading content through html src's should work just fine when tests end quickly","state":"passed","duration":3}]
[D] ["phantomjs","mocha.test end",{"title":"should work just fine when tests end quickly","fullTitle":"loading content through html src's should work just fine when tests end quickly","state":"passed","duration":3}]
[D] ["phantomjs","mocha.test",{"title":"should work just fine when tests end after a while","fullTitle":"loading content through html src's should work just fine when tests end after a while"}]
[D] ["phantomjs","onResourceRequested","https://www.youtube.com/v/VpXUIh7rlWI"]
[D] ["phantomjs","onLoadFinished","fail"]
[D] ["phantomjs","fail.load","http://localhost:9500/index.html"]
...ERROR
Warning: PhantomJS unable to load "http://localhost:9500/index.html" URI. Use --force to continue.
Aborted due to warnings.
Execution Time (2015-03-05 06:19:26 UTC)
jshint:all 194ms ▇▇▇▇▇▇▇▇▇▇▇▇▇ 10%
connect:test 32ms ▇▇ 2%
mocha:all 1.6s ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 88%
Total 1.9s
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.
from grunt-mocha.
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 fail.load
listener after the first success... I'd have to look into how grunt-lib-phantomjs attaches success events. You could do it too 😃
from grunt-mocha.
Related Issues (20)
- Source maps
- Is there a way to run this without phantomjs? HOT 1
- XUnit: invalid XML if running multiple suites HOT 4
- Ability to pass TZ parameter to Phantom HOT 1
- JSON reporter doesn't write output to file HOT 5
- Phantom JS Timing Out HOT 2
- option for mocha-clean HOT 5
- how to change filepath for html_table_reporter in reporter options HOT 1
- Support for --compilers option
- PhantomJS hangs around after tests HOT 2
- Support for --recursive flag HOT 1
- Mocha reporters don't have results HOT 1
- Bump grunt-lib-phantomjs to ^1.0.0 HOT 6
- [Request] Support for retry arg
- Update to Latest Grunt please? HOT 1
- mocha > 2.4.5 fails with reporter xunit HOT 10
- the mocha task results and the browser test results not the same HOT 1
- Please, add tag 1.02 HOT 1
- Does it make sense to archive this repository?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grunt-mocha.