Code Monkey home page Code Monkey logo

grunt-mocha's Introduction

Repo deprecated

Disqus has adopted this project and npm module, visit https://github.com/disqus/grunt-mocha for further updates.


grunt-mocha

Automatically run client-side mocha specs via grunt/mocha/PhantomJS

For a grunt task for server-side mocha tests, see grunt-mocha-test or grunt-simple-mocha

Getting Started

This plugin requires Grunt ~0.4.0. Use a 0.1.x tag of this plugin to use with Grunt ~0.3.0.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-mocha --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-mocha');

Mocha task

Run this task with the grunt mocha command.

Settings

files/src

Type: String|Array

This defines which HTML spec files to run using PhantomJS. These are the same files you would open to run tests in a browser.

There are a number of options available. Please review the minimatch options here.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
  },
},

dest

Type: String Default: undefined

Write reporter output to a file. Useful if you need a file to feed your CI bot.

Example:

mocha: {
  test: {
    options: {
      reporter: 'XUnit'
    },
    src: ['tests/**/*.html'],
    dest: './test/output/xunit.out',
  },
},

options.run

Type: Boolean Default: true

grunt-mocha injects a script into the PhantomJS instance that loads your HTML spec files. The file sets up a reporter and listeners so the output can be output in the command line. This option will call mocha.run() after the script is injected, ensuring that the proper listeners are setup.

You may want to set this to false if your files are loaded asynchronously via AMD and call mocha.run in your own callback.

In HTML spec:

<!-- run mocha after all test are loaded -->
<script type="text/javascript" charset="utf-8">
  // Only tests run in real browser, injected script run if options.run == true
  if (navigator.userAgent.indexOf('PhantomJS') < 0) {
    mocha.run();
  }
</script>

Gruntfile:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      run: true,
    },
  },
},

options.urls

Type: Array|String Default: []

Instead of files, hit these URLs. Usually used in conjunction with the connect task to spin up a server for testing.

connect: {
  server: {
    options: {
      port: 8888,
      base: '.',
    },
  },
},
mocha: {
  test: {
    options: {
      urls: [ 'http://localhost:8888/example/test/test2.html' ],
    },
  },
},

Then run:

grunt connect mocha

options.timeout

Type: Number Default: 5000

PhantomJS timeout in milliseconds. If nothing happens within 5 seconds, exit.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      timeout: 10000,
    },
  },
},

options.bail

Type: Boolean Default: false

Call grunt.warn and exit the grunt task on the first failed test. This only calls grunt.warn after the entire spec file is finished.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      bail: true,
    },
  },
},

options.growlOnSuccess

Type: Boolean Default: true

Display a Growl notification when all tests successfully pass.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      growlOnSuccess: false,
    },
  },
},

options.log

Type: Boolean Default: false

Print any console.log calls from PhantomJS to the command line. Only used for very quick and dirty debugging. It is highly recommended that you open the failing spec file in a browser so you can use much richer debugging tools.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      log: true,
    },
  },
},

options.logErrors

Type: Boolean Default: false

Fail and output script errors.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      logErrors: true,
    },
  },
},

options.mocha

Type: Object

A mocha options simple object. Very few options are currently supported. Actually, I think grep is the only one.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      mocha: {
        grep: 'router*'
      }
    }
  },
},

options.reporter

Type: String Default: 'Dot'

The reporter to use. Note: XUnit and those types of reporters should probably use the dest option.

Example:

mocha: {
  test: {
    files: ['tests/**/*.html'],
    options: {
      reporter: 'Nyan',
    }
  },
},

Custom reporter example: Example:

mocha: {
  test: {
    files: ['tests/**/*.html'],
    options {
      reporter: './path/to/custom/reporter', // included via require
    },
  },
},

options.page

Type: Object

Set properties in the PhantomJS webpage instance used for tests, see http://phantomjs.org/api/webpage/

Example:

mocha: {
  test: {
    options: {
      page: {
        settings: {
          webSecurityEnabled: false,  // disable cors checks in phantomjs
        },  
      },
    },
  },
},

Hacks

The PhantomJS -> Grunt superdimensional conduit uses alert. If you have disabled or aliased alert in your app, this won't work. I have conveniently set a global PHANTOMJS on window so you can conditionally override alert in your app.

Examples

Vanilla JS

Option 1 (recommended)

  • Write mocha task description in grunt config using and specify run: true option (see this task's Gruntfile.js for details);
  • Check for PhantomJS userAgent in a test html file and run tests only in a real browser (see test2.html for details).

In this case you shouldn't include bridge.js (it will be included automatically) and tests will be run from bridge.js.

Option 2

Alternatively, include bridge.js from tasks/phantomjs after you include mocha.js and run mocha.setup in your HTML file. The helper will override mocha.setup if it detects PhantomJS. See test.html.

AMD

Mocha must be included via script tag in the header. There is no need to load Mocha via AMD. You may load other testing libs via AMD if that gives you a fuzzy feeling.

Example setup with AMD (advanced): https://gist.github.com/2655876

License

Copyright (c) 2013 Kelly Miyashiro Licensed under the MIT license.

grunt-mocha's People

Contributors

ambar avatar bartvds avatar bitwiseman avatar bmac avatar byk avatar chrisabrams avatar e7h4n avatar gamtiq avatar hakatashi avatar iammerrick avatar jonotron avatar juriejan avatar kmiyashiro avatar lemieux avatar michaelxavier avatar naganowl avatar nschonni avatar pangratz avatar paulirish avatar puigcerber avatar rayshih avatar rmurphey avatar rohni avatar sboudrias avatar sessio avatar sindresorhus avatar studiomohawk avatar tokrsen avatar tony avatar vseventer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-mocha's Issues

Not catching test failures when it() included directly in first describe() block

Using the latest version of grunt-mocha (0.1.7), when running against a HTML file that includes a test file such as:

describe('window.location', function() {
  // The following causes mocha-grunt to not catch failures in the next test script!
  it('should be defined', function() {
    expect(window).to.have.property('location');
  });

  describe('location', function() {
    it('should have hash', function() {
      expect(window.location).to.have.property('hash');
    });
  });
});

Followed by a test file such as:

describe('window.navigator', function() {
  describe('user agent', function() {
    it('should have james bond', function() {
      expect(window.navigator).to.have.property('jamesBond');
    });
  });
});

Results in:

$ grunt mocha
Running "mocha:cui" (mocha) task
Testing index.html.OK
>> 3 assertions passed (0.11s)

Which is incorrect. It doesn't matter what failing assertion is inside of the block in the second file, it is never caught by grunt-mocha.

However, when index.html is opened in the browser, the window.navigator.jamesBond test fails, as it should.

Workaround:
Removing the statement from the first test it('should be defined') causes the problem to go away.

Here is the gist:
https://gist.github.com/3900997

Refactor to remove `phantomjs/main.js`

Hi,

I don't have a specific solution but I think that the current organization of grunt-mocha leaves something to be desired.

Should there be a separate copy of phantomjs/main.js within grunt-mocha? I know you made a modification to it, but I feel like it would be better to see if we could just pass in the required grunt-mocha options into the existing grunt-lib-phantomjs/phantomjs/main.js file.

Thoughts?

v0.2.0 PhantomJS always times out

I've had this same problem with older versions too, so maybe I'm just crazy...

  1. Installed grunt v0.4.0a
  2. Installed the latest tag of grunt-mocha via npm (npm install grunt-mocha@https://github.com/kmiyashiro/grunt-mocha/archive/0.2.0.tar.gz)
  3. cd node_modules/grunt-mocha
  4. grunt mocha
Running "mocha:all" (mocha) task
Testing test.html
Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.

Aborted due to warnings.

XUnit and TAP reporter doesn't work with grunt-mocha

Thanks for the update, I just updated to 0.3.0 but I found a couple of issues though:

Tried using XUnit reporter but I got:

Running "mocha:all" (mocha) task
Testing: http://localhost:3301/test/tests

Fatal error: Cannot call method 'fullTitle' of undefined

Then i tried TAP:

Running "mocha:all" (mocha) task
Testing: http://localhost:3301/test/tests
Fatal error: Object # has no method 'grepTotal'

The Spec, Dot, Nyan, JSON, List, Progress reporters seem to work though.
Any ideas?

Also, assuming this gets working, is there an easy way to get integrated with other reporters installed separately (namely https://github.com/peerigon/xunit-file for jenkins?)

No error when zero tests ran due to missing HTML file

A grunt.js such as:

/*global module:false*/
module.exports = function(grunt) {

  // External tasks
  grunt.loadNpmTasks('grunt-mocha');

  grunt.initConfig({
    // Configure
    mocha: {
      cui: {
        run: true,

        src: [
          'thisFileDefinitelyDoesNotExist.html'
        ]
      }
    }
  });

  // Default task
  grunt.registerTask('default', 'mocha');
};

Results in:

$ grunt mocha
Running "mocha:cui" (mocha) task
>> 0 assertions passed (0s)

It should be expected to error because the test file was not found and no tests were ran.

Weird --globals behavior for my own global settings

Hello guys

mocha is behaving weird with my own global settings. When I add settings to --globals then no test is run.

How to reproduce?

In test/mocha.opts I have this:

--ui tdd
--reporter spec
--check-leaks
--globals utile, settings

in my express app I have this somewhere in my app code:

global.settings = app.settings;

so, when I run make test I get this:

> make test


  0 tests complete (3 ms)

Weird! And when I remove settings from --globals and run make test again, then it says that a global leak has been detected:

> make test
test


  pages
    index
      1) "before each" hook
      โœ“ http results (335ms)
    faq
      โœ“ http results 
    versions
      โœ“ http results 
    clean
      โœ“ http results (354ms)
    pages gone
      โœ“ http results (102ms)
    non existing pages
      โœ“ http results 


  โœ– 1 of 6 tests failed:

  1) pages "before each" hook:
     Error: global leak detected: settings
      at Runner.checkGlobals (/opt/node-0.10.3/lib/node_modules/mocha/lib/runner.js:177:21)
      at Runner.<anonymous> (/opt/node-0.10.3/lib/node_modules/mocha/lib/runner.js:58:44)
      at Runner.EventEmitter.emit (events.js:95:17)
      at /opt/node-0.10.3/lib/node_modules/mocha/lib/runner.js:248:12
      at Hook.Runnable.run (/opt/node-0.10.3/lib/node_modules/mocha/lib/runnable.js:215:5)
      at next (/opt/node-0.10.3/lib/node_modules/mocha/lib/runner.js:243:10)
      at Object._onImmediate (/opt/node-0.10.3/lib/node_modules/mocha/lib/runner.js:254:5)
      at processImmediate [as _immediateCallback] (timers.js:317:15)

can anyone explain this?

cheers
michael

Verbose | Debug mode

Hi Kelly,

Great project grunt-mocha, exactly what I was looking for, thanks!

I've been able to setup it without much hassle, however 50% of my test suite fails, while it works on a real browser, so I'm guessing phantomjs doesn't like something in the runner. However the message I get for tests failing is not very helpful:

Message: 'undefined' is not a function

Is there a Debug mode or a way to know more about what's going on?

Thanks, cheers
Miguel

Linux Breaks - OSX Works

The same code, the same version of PhantomJS (v1.6.1), same version of Node.js (v0.8.9), same version of Mocha.js (1.4.2) and the same version of grunt (v0.3.15). However the tests work terrific on OSX! However, when I run the same tests on the CI server which I have tried Ubuntu and Mint, I recieve the following error:

xwing@bourne:/opt/teamcity/buildAgent/work/app/work/layout: document$ ./node_modules/.bin/grunt test -d
Running "mocha:index" (mocha) task
Testing index.html[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/index.html
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/vendor/chai.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/require.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/vendor/mocha.css
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/vendor/mocha.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/index.html
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/vendor/chai.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/require.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/vendor/mocha.css
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/vendor/mocha.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/main.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/main.js
[D] phantomjs inject /opt/teamcity/buildAgent/work/app/work/layout: document/node_modules/grunt-mocha/tasks/mocha/mocha-helper.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/config.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/config.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/bits/framework/ViewTests.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/bits/framework/LimitedStackCollectionTests.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/bits/framework/ViewTests.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/jstest/new/bits/framework/LimitedStackCollectionTests.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/jquery-1.7.2.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/underscore.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/framework/View.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/framework/LimitedStackCollection.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/jquery-1.7.2.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/underscore.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/framework/View.js
[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/framework/LimitedStackCollection.js
[D] phantomjs onResourceRequested file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/backbone.js
[D] phantomjs Page error: Error: Script error
http://requirejs.org/docs/errors.html#scripterror
  file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/require.js:1818
  file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/require.js:539
  file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/require.js:1713

[D] phantomjs onResourceReceived file:///opt/teamcity/buildAgent/work/app/work/layout: document/public/javascripts/bits/vendor/backbone.js

Has anyone else had problems with running grunt-mocha on Linux with RequireJS? Any ideas? I'm really at a loss, the only software variables seem to be the operating system!

code coverage

Is there a way to tie in code coverage?

Also, I'd like to tie both into jenkins and be able to fail builds if tests fail or if certain amount of lines aren't covered... Any ideas on the best way to do this?

Output looks strange in Travis

It seems that when a test is running, it has the โ—ฆ symbol in front of it, and when it's complete, it has the โœ“ symbol swapped in place.

On TravisCI, instead of swapping, the spec description gets repeated a second time like so:

  Backbone.Geppetto
    when loading Geppetto
      โ—ฆ should be defined as an AMD module:   โœ“ should be defined as an AMD module 
      โ—ฆ should be defined as a property on the Backbone object:   โœ“ should be defined as a property on the Backbone object 
    when binding a context
      โ—ฆ should bind the context instance to the view:   โœ“ should bind the context instance to the view 

See: https://travis-ci.org/ModelN/backbone.geppetto/builds/9711973

Note that I am using a forked version of your project to get code coverage and CI integration working.

Error Should Be Thrown If No Files Were Found

This took me a while to debug. I accidentally put the urls array in the wrong object and didn't understand why it wasn't working. It'll be nice if a warning is shown if zero html files were run!

grunt-mocha install failing on phantomjs extraction

I've had a hunt around the issues but can't find an answer to this one.

I'm trying to install grunt-mocha in a project, but when I run npm install grunt-mocha I get the following error at the end and the install fails:

Extracting zip contents
Renaming extracted folder phantomjs-1.9.0-macosx  -> phantom
Temporary files not renamed, maybe zip extraction failed.
npm ERR! [email protected] install: `node install.js`
npm ERR! `sh "-c" "node install.js"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the phantomjs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node install.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls phantomjs
npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 12.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "grunt-mocha"
npm ERR! cwd /Volumes/hd3-case-sensitive/sites/gpmd-new/branding
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /Volumes/hd3-case-sensitive/sites/gpmd-new/branding/npm-debug.log
npm ERR! not ok code 0

I had a look in the folder where the phantomjs zip file is located and it looks like it has been extracted ok.

Any suggestions?

Growl support?

Does growl support work? I saw some artifacts in the repo for it, and some mention about it in another issue being taken out. I'm using 0.3.1 from npm -- is growl integration there, and if so, how to configure it? I tried adding growl: true to the options but it does not work. I do have growl installed, and it works with stock mocha.

Wrong exit code when tests fails

This was working in version 0.3.1, but now using grunt version 0.4.1 and grunt-mocha 0.3.3 I'm facing an issue that when my test fails, the exit code is still 0. The expected exit code is something above 0.

Using following grunt test task:

  grunt.registerTask('test', [
      'clean:server',
      'coffee',
      'connect:test',
      'mocha'
    ]);

And when running simple test.coffee:

define ['chai-helper'], (expect) ->
  describe 'failing test', ->
    it 'should give correct exit code', ->
      expect(false).to.be.true
$ grunt test
...
...

  1) failing test should give correct exit code:
     expected false to be true
      at http://localhost:9000/lib/chai.js?bust=1370242625429:243
      at http://localhost:9000/lib/chai.js?bust=1370242625429:464
      at http://localhost:9000/lib/chai.js?bust=1370242625429:2766


>> 1/1 tests failed (0.00s)
$ echo $?
0

The expected output and error code is (This was produced using grunt-mocha version 0.3.1):

$ grunt test
...
...
  1) failing test should give correct exit code:
     expected false to be true
      at http://localhost:9000/lib/chai.js?bust=1370242798387:243
      at http://localhost:9000/lib/chai.js?bust=1370242798387:464
      at http://localhost:9000/lib/chai.js?bust=1370242798387:2766


Warning: 1/1 tests failed (2ms) Use --force to continue.

Aborted due to warnings.
$ echo $?
6

v0.1.7 PhantomJS always times out

I've installed grunt-mocha v0.1.7 using NPM: npm install grunt-mocha. I'm using grunt v0.3.17.

When I run grunt mocha this happens:

$ grunt mocha
path.existsSync is now called `fs.existsSync`.
Running "mocha:all" (mocha) task
Testing index.html
<WARN> PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue. </WARN>

Aborted due to warnings.

My spec is definitely not the problem, when I run it in the browser I don't see any failed assertions or errors in the console error log.

The mocha part of my Gruntfile looks like this:

mocha: {
    all: 'tests/index.html',
    run: true
}

Like the grunt-mocha readme suggests, mocha.run is not called when the tests are run in PhantomJS:

$(function () {
    if (navigator.userAgent.indexOf('PhantomJS') < 0) {
        mocha.run();
    }
});

You can find the important files here:

Doesn't fail the build

The build is not failing even if there is unsuccessful tests. I can see only a 'F' if something wrong but the final verdict is 'Done, without errors.' and the build process continues.

Running "mocha:all" (mocha) task
Testing testRunner.html..F..OK
>> 5 assertions passed (0.07s)

Done, without errors.

update grunt-mocha to allow URL's in grunt .4

96359322 fixed support for files in the latest grunt, but removal of file.expandFileURLs broke our support for URLs.

Removed file.expandFileURLs method. Don't specify URLs where files should be specified (eg. the qunit task now allows for a urls option). - https://github.com/gruntjs/grunt/wiki/Upgrading-from-0.3-to-0.4

https://github.com/gruntjs/grunt-contrib-qunit/blob/master/tasks/qunit.js#L138 has an implementation of using urls: [] to accept urls.

mocha-helper is being injected after `mocha.run` is called

Hi there,

I've been playing a bit with grunt-mocha and wasn't able to get it working.

I'm using the latest mocha (1.2.2), and got the typical timeout error.

After a bit of investigation, I managed to get it working but it required some changes to how the runner is hooked in the grunt / phantomjs system. I may also very well miss something simple.

I wasn't able to find any information on the mocha version grunt-mocha was designed to work for. Should I use the latest? Should I use a specific version?

It may be handy to write down this information somewhere. Also, maybe that a working example directly from within the repo might help a lot new users getting started quickly (as a reference, even though your gist is there and great to get a better idea).

Anyway, thanks for creating this plugin! It has been of great help.

Fatal error: listen EADDRNOTAVAIL on $ grunt

Hi, when I run the following commands with Yeoman 1.0 and Grunt 0.4

$ yo webapp
$ npm install
$ bower install
$ grunt

I get the following error:

Running "mocha:all" (mocha) task
Testing index.htmlFatal error: listen EADDRNOTAVAIL

Tried running the mocha test separately which works fine. I'm guessing some of my system dependancies are wrong. Any ideas?

Is this related? http://stackoverflow.com/questions/6829563/nodejs-error-eaddrnotavail-cannot-assign-requested-address

Do not bail on error

Is there a necessary reason to call grunt.warn on test failure? Seems to me the mocha reporter is already supplying the necessary test failure info, and grunt.warn breaks regarde watching unless used with the --force flag (which I don't think is ideal).

Timeout Warning

I receive the following error when running my test file through phantomjs using grunt-mocha:

PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.

I am using PhantomJS 1.6.1 and grunt-jasmine works great. I have tried manually including the helper even though I'm using AMD with Require.js. The tests run great if pulling the file up in the browser. Any ideas?

Task will not run due to removal of .srcRaw

Grunt removed .srcRaw so that this task gives me an error:
Warning: Cannot read property 'srcRaw' of undefined Use --force to continue.

I have fixed the problem by replacing with
var urls = grunt.file.expandFileURLs(this.file.srcRaw);
this line to
var urls = this.filesSrc;

I'm not sure if this is the good way to fix.
By the way, Thanks for making this plugin!

How do I configure grunt-mocha to report global leaks?

I asked this question on StackOverflow but got no answers.

I'm trying to us grunt-mocha 0.1.7 with grunt 0.3.17 and mocha 1.8.1. I have some intentional global leaks in my code. When I use mocha through a browser, I see these leaks reported. However, no leaks are reported when I run mocha via grunt.

I tried several grunt configuration variations similar to

mocha: {
   all: {
     src: ['test/**/*.html'],
     options: {
       ignoreLeaks: false
    }
  }

based on information on the GitHub project page, samples I found on the web, and by looking through the source. I also tried to compare the source to the "spec" test reporter in the mocha source to see if there was something obvious that suggested that it wouldn't work. I didn't see anything, although I must admit I'm still fairly new to JavaScript so I may have missed something.

Could you provide guidance on how to properly configure grunt-mocha to report global leaks? Browser testing is fine for now, but I'd like to ultimately use a continuous integration server.

Thanks in advance.

Trevor

PhantomJS timeout issue with 0.2.3

I am trying to upgrade this plugin https://github.com/addyosmani/backbone.paginator to use Grunt-0.4.0 and i am getting PhantomJS timeout:

Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue

grunt mocha -v --debug

Running tasks: mocha

Running "mocha" task
[D] Task source: /Users/reds-dev/github/skusunam/backbone.paginator/node_modules/grunt-mocha/tasks/mocha.js

Running "mocha:all" (mocha) task
[D] Task source: /Users/reds-dev/github/skusunam/backbone.paginator/node_modules/grunt-mocha/tasks/mocha.js
Verifying property mocha.all exists in config...OK
Files: test/test.html -> all
Additional configuration: {"timeout":5000,"inject":"/Users/reds-dev/github/skusunam/backbone.paginator/node_modules/grunt-mocha/phantomjs/bridge.js","phantomScript":"/Users/reds-dev/github/skusunam/backbone.paginator/node_modules/grunt-mocha/phantomjs/main.js","urls":[]}

Testing test.html
[D] ["/Users/reds-dev/github/skusunam/backbone.paginator/node_modules/grunt-mocha/phantomjs/main.js","/var/folders/gr/8yf0645d3xbcvqt7pkc5_2zc0000gq/T/1362244112590.0913","test/test.html","{"timeout":5000,"inject":"/Users/reds-dev/github/skusunam/backbone.paginator/node_modules/grunt-mocha/phantomjs/bridge.js","phantomScript":"/Users/reds-dev/github/skusunam/backbone.paginator/node_modules/grunt-mocha/phantomjs/main.js","urls":[]}"]
[D] ["phantomjs","private","version",{"major":1,"minor":8,"patch":1}]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/test.html"]
[D] ["phantomjs","onUrlChanged","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/test.html"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/css/mocha.css"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/js/jquery.js"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/js/underscore.js"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/js/backbone.js"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/js/mocha.js"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/phantomjs/bridge.js"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/js/chai.js"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/js/sinon.js"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/lib/backbone.paginator.js"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/backbone.paginator.requestPager_test.js"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/backbone.paginator.clientPager_test.js"]
[D] ["phantomjs","onResourceReceived","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/test.html"]
[D] ["phantomjs","onResourceRequested","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/test.html?callback=jQuery182038564301072619855_1362244114093&=1362244115583"]
[D] ["phantomjs","onResourceReceived","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/test.html?callback=jQuery182038564301072619855_1362244114092&
=1362244115582"]
[D] ["phantomjs","onResourceReceived","file:///Users/reds-dev/github/skusunam/backbone.paginator/test/test.html?callback=jQuery182038564301072619855_1362244114093&_=1362244115583"]
[D] ["phantomjs","fail.timeout"]

Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.

phantomJS doesn't find mocha events when Mocha is loaded through requireJS

When a test page is loading mocha through requireJS then phantomJS in grunt-mocha doesn't register those events.

(Specifically it's not finding events here: https://github.com/kmiyashiro/grunt-mocha/blob/master/tasks/mocha.js#L46 )

This may not be a bug with grunt-mocha, but I do need help figuring out how to expose mocha to phantomjs.

You can reproduce this here: https://github.com/pconerly/requirejs-mocha-chai-bootstrap

You can see the other bug report here: https://github.com/karlbright/requirejs-mocha-chai-bootstrap/issues/1

Mocha times out with in v2.0

I'm finding that Mocha always times out after moving to grunt v0.4. Everything seems to work fine as long as you change package.json to pull the most recent changes to grunt-lib-phantomjs (which include your pull request), but the listed version in package.json grunt-lib-phantomjs: "~0.1".

ReferenceError: Can't find variable: Mocha

if i run my tests with: grunt mocha --debug, I get the following warning.

PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.

and the following errors (summary):
[D] phantomjs onResourceRequested /mercurial/super-system/modules/client2/libs/backbone.js
[D] phantomjs onResourceReceived /mercurial/super-system/modules/client2/libs/backbone.js
[D] phantomjs Page error: ReferenceError: Can't find variable: Mocha
/mercurial/super-system/modules/client2/node_modules/grunt-mocha/tasks/mocha/mocha-helper.js:21

If I change the line in mocha-helper.js:
var reporters = Mocha.reporters || mocha.reporters;
in:
mocha.reporters;

the tests pass.

$ node --version
v0.6.20
$ mocha version
1.4.2

I don't know if I make a mistake or there is a bug in mocha-helper.js

Way to run server-side tests

I'm working on a project that has both a client-side and a server-side piece, with tests written in mocha. Would love to be able to run them both through grunt. Found this gist but having trouble getting it to work. Thanks!

Leaves phantomjs process running after done

I'm running on Windows 7 with a tiny test suite.

The task works fine. It reports tests passing. However, when it finishes the phantomjs process does not exit. I discovered this after running tests a few hundred times, leaking around 8 GB of memory.

I attempted to debug. It appears that phantom-mocha-runner's sendMessage is not fully working as intended. In particular, the fs.write for the done message never returns. Thus, the done test branch never executes and phantom.exit() is not called.

Or, at least, that's the best that I could tell by inserting a bunch of sending of console messages.

This is not the whole problem. I moved the done check to be before the write and the proces still did not exit. I did, however, then see all the console messages.

Replace referal to grunt-simple-mocha with grunt-mocha-test

I noticed the README.md refers to grunt-simple-mocha for Node.js based mocha testing in grunt.

Maybe it's a good idea to change to or mention grunt-mocha-test? As grunt-simple-mocha is an extremely minimal module while grunt-mocha-test has extensive self-test coverage and improved features, and is a bit less.. simple.

phantomjs compatibility

not sure if my issue is about grunt mocha but i'd be glad if you help me.
when i build "yo webapp" i noticed these lines below;

Renaming extracted folder phantomjs-1.9.0-macosx  -> phantom
Fixing file permissions
Done. Phantomjs binary available at /Users/emreiair/web/crox/node_modules/grunt-mocha/node_modules/grunt-lib-phantomjs/node_modules/phantomjs/lib/phantom/bin/phantomjs

PhantomJS & AMD Testing

I'm trying to setup my mocha testing as follows. All of our code is in AMD modules and we load it using RequireJS.

<!-- runner.html -->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <title>Test Common Modules</title>
        <link rel="stylesheet" href="/Content/css/mocha.css" type="text/css" charset="utf-8" />

        <script type="text/javascript" src="/Scripts/Vendor/mocha.js"></script>
        <script type="text/javascript">
            // Mocha
            mocha.setup({
                ui: 'bdd',
                ignoreLeaks: true
            });
        </script>
    </head>
    <body>
        <h1>Common Module Tests</h1>
        <!-- Required for browser reporter -->
        <div id="mocha"></div>

        <script type="text/javascript" src="/Scripts/Vendor/require.js" data-main="runner.js"></script>
    </body>
</html>
// runner.js
// Configure RequireJS
require.config({
    baseUrl: '/Scripts/App',
    urlArgs: "v=" + (new Date()).getTime(),
    paths: {
        'jquery': '../Vendor/jquery-1.7.1.min',
        'chai': '../Vendor/chai',
    }
});

// Require libraries
require(['chai'], function (chai) {

    // Chai
    assert = chai.assert;
    should = chai.should();
    expect = chai.expect;

    var specPath = function(spec) {
        return "Common/Test/Spec/" + spec;
    };

    // Require base tests before starting
    require([specPath('helpers-spec')], function () {
        // Start runner
        mocha.run();
    });

});

Everything works as expected in the browser. It's a nice setup. Here's my grunt.js mocha config:

mocha: {
            // runs all html files in the test dir
            // In this example, there's only one, but you can add as many as
            // you want. You can split them up into different groups here
            // ex: admin: [ 'test/admin.html' ]
            // all: [appFolder + '*/test/**/*.html']
            all: {
                src: ["http://quotecenter.net/Scripts/Common/test/runner.html"],
                run: false
            }
        },

Notice how I'm telling it to test an actual url, and not a file in the file system. This helps with file paths and makes things less confusing.

When I go to run my tests grunt.cmd mocha, PhantomJS attempts to inject the mocha-helper.js file. Problem is, it's injecting it somewhere before mocha is defined by mocha.js. Why isn't it injecting it in the right location? How do I set things up properly to test AMD modules both in the browser and through the CLI?

Phantomjs timeout with AMD

Hi, I've tried to make this plugin work to run my Mochas test, but I always fall on Phantomjs timeout error with the notice about mocha.run().

I'm using AMD inside my test and I've look closely to your example setup gist and to the documentation but nothing seemed to work.

Been testing both run: true option and phantomjs detection. Everything run fine in a normal browser, but I always get the timeout via the command line.

I'm on windows BTW, and I've tested both 0.2 version with Grunt 0.3, and the lastest with grunt 0.4.

Any idea?

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.