Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Tests just don't seem to run at all in grunt serve #219

Open
jtmkrueger opened this issue Feb 20, 2014 · 8 comments
Open

Tests just don't seem to run at all in grunt serve #219

jtmkrueger opened this issue Feb 20, 2014 · 8 comments

Comments

@jtmkrueger
Copy link
Contributor

I'm going to apologize beforehand, because I think I must be doing something obviously wrong, and I probably don't understand the underlying code enough to pinpoint it.

First off, Here's my Gruntfile.js. The only real modifications I've made are including sass.

Whenever I change a test file, I just see

Running "mocha:all" (mocha) task
>> 0 passed! (0.00s)

fly by, even if I put obvious errors in the generated test files that should throw SyntaxErrors.

Is there something else I need to add to the gruntfile, or do I need to make changes to my test/index.html (here)?

UPDATE
So until I get this figured out, I just started testing in the browser by loading up test/index.html. I updated the gist above to reflect where I'm at now, and this is working fine for me, but obviously I'd prefer to be using the cli interface.

@gilbarbara
Copy link
Contributor

@jtmkrueger edit your gruntfile and replace src with urls in the mocha task.

@generalov
Copy link

I create new yo backbone project with:

$ yo backbone --test-framework=mocha --template-framework=handlebars

When I run grunt serve, and I open test/spec/test.js in the editor and save it
Then I see in console a Warning: PhantomJS unable to load "http://localhost:9001/index.html" URI.

$ grunt serve
...
>> File "test/spec/test.js" changed.
Running "test:true" (test) task
Running "clean:server" (clean) task
Cleaning .tmp...OK
Running "coffee:dist" (coffee) task
Running "coffee:test" (coffee) task
Running "createDefaultTemplate" task
Running "handlebars:compile" (handlebars) task
File ".tmp/scripts/templates.js" created.
Running "mocha:all" (mocha) task
Testing: http://localhost:9001/index.html
...ERROR
Warning: PhantomJS unable to load "http://localhost:9001/index.html" URI.
... Reload test/spec/test.js ...
... Reload .tmp/scripts/templates.js ...
... Reload test/spec/test.js ...
... Reload .tmp/scripts/templates.js ...
... Reload test/spec/test.js ...
... Reload .tmp/scripts/templates.js ...
... Reload test/spec/test.js ...
... Reload test/spec/test.js ...
... Reload test/spec/test.js ...
>> 0 passed! (NaNs)
Running "watch" task
Waiting...

Tests are works when I run grunt test, but I can't to run grunt serve and grunt test at the same time (is this an another issue?):

$ grunt serve
# and in other console
$ grunt test
...
Running "mocha:all" (mocha) task
Testing: http://localhost:9001/index.html
  ․
  1 passing (3ms)
>> 1 passed! (0.00s)
Running "watch:test" (watch) task
Waiting...Fatal error: Port 35729 is already in use by another process.

@debajyotimahanta
Copy link

did any fix this or found a solution to this. I am having the same issue workins on grunt test, but when i do grunt serve or grunt watch it fails with PhantomJS unable to load .....

@debajyotimahanta
Copy link

figured out the issue had to run grunt test and not grunt watch because thats the task registered in gruntfile.js

@lesterzone
Copy link

From this awesome post: http://puigcerber.wordpress.com/2013/12/23/using-grunt-to-run-mocha-tests-with-backbone-js-and-requirejs/ and some changes.

Gruntfile.js

mocha: {
    all: {
        options: {
            run: true,
            log: true,
            reporter: 'Spec',
            // reporter: 'Nyan', Nyan? Seriously ? Yeah! :)
            // reporter: 'Progress',
            timeout: 10000,
            // src property used by default, which doesn't work
            // src: ['http://localhost:<%= connect.test.options.port %>/index.html']
            urls: ['http://localhost:<%= connect.test.options.port %>/index.html']
        }
    }
},

tests/index.html

<body>
    <script src="bower_components/jquery/dist/jquery.js"></script>
    <script src="bower_components/underscore/underscore.js"></script>
    <script src="bower_components/backbone/backbone.js"></script>

    <div id="mocha"></div>
    <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>

    <!-- include source files here... -->
    <script src="scripts/main.js"></script>

    <!-- you need this file for templates -->
    <script src='scripts/templates.js'></script>

    <!-- models, collections and views ORDER MATTERS  -->
    <script src="scripts/models/YOUR-MODEL.js"></script>

    <!-- your test files -->
    <script src="test/models/model.js"></script>
    ...

    <!-- include spec files here... -->
    <script src="spec/test.js"></script>
    ...

    <script>
        mocha.run();
    </script>
</body>
</html>

Run CLI:

grunt test

Run browser

grunt serve:test

@barbagallo
Copy link

@lesterzone Thanks man, this worked for me, has anyone submitted a patch to fix the src/urls issue in the Gruntfile?

@gilbarbara
Copy link
Contributor

I have submitted a fix a few MONTHS ago.

@davidham
Copy link

I am still seeing this issue. 'grunt serve' initiates a watch task, which does its usual thing whenever I save a file. However, when it runs the mocha:all task, PhantomJS can't load the test runner file. Here's my output:

$ grunt serve
Running "serve" task

Running "clean:server" (clean) task
>> 1 path cleaned.

Running "createDefaultTemplate" task

Running "jst:compile" (jst) task
>> Destination not written because compiled files were empty.

Running "compass:server" (compass) task
directory .tmp/styles
    write .tmp/styles/main.css (0.003s)

Running "connect:livereload" (connect) task
Started connect web server on http://localhost:9000

Running "open:server" (open) task

Running "watch" task
Waiting...
>> File "test/spec/test.js" changed.

Running "test:true" (test) task

Running "clean:server" (clean) task
>> 1 path cleaned.

Running "createDefaultTemplate" task

Running "jst:compile" (jst) task
>> Destination not written because compiled files were empty.

Running "compass:dist" (compass) task
directory .tmp/styles
    write .tmp/styles/main.css (0.002s)

Running "compass:server" (compass) task

Running "mocha:all" (mocha) task
Testing: http://localhost:9001/index.html
...ERROR
Warning: PhantomJS unable to load "http://localhost:9001/index.html" URI.
>> 0 passed! (NaNs)

Running "watch" task
Waiting...

I'd love it to run my tests as part of 'watch', is this the intended behavior?

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

No branches or pull requests

7 participants