Code Monkey home page Code Monkey logo

Comments (3)

kmiyashiro avatar kmiyashiro commented on June 2, 2024

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.

saiichihashimoto avatar saiichihashimoto commented on June 2, 2024

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.

kmiyashiro avatar kmiyashiro commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.