GithubHelp home page GithubHelp logo

jdcataldo / grunt-mocha-phantomjs Goto Github PK

View Code? Open in Web Editor NEW
70.0 70.0 40.0 100 KB

A simple grunt wrapper for mocha-phantomjs to allow for ci integration

License: MIT License

JavaScript 77.66% HTML 22.34%

grunt-mocha-phantomjs's People

Contributors

ade avatar jdcataldo avatar jmather avatar mnahkies avatar mrickard avatar okonet avatar sdemjanenko avatar shinnn 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

Watchers

 avatar  avatar

grunt-mocha-phantomjs's Issues

Cannot dynamically alter the watched files

I am trying to use the watch event triggered by grunt-contrib-watch to only run tests on the files that have been changed. Unfortunately grunt-mocha-phantomjs does not seem to pick up the new options.

Basically I am doing this :

    grunt.initConfig({
        mocha_phantomjs : {
            all     : ['develop/test/**/*.html']
        }
    );

    grunt.event.on('watch', function(action, filepath) {
        grunt.config('mocha_phantomjs.all', [filepath]);
    });

I can see the value changing, but the value is simply not being picked up after loading the task. Is there any way of making them be picked up?

Test failure with OS X (10.8.4)

When I run this project against my tests with Ubuntu 13.04, everything works fine. Running under OS X, I get

Running "mocha_phantomjs:test"
Warning: 8 tests failed Use --force to continue

Even if I deactivate all tests or change the test index.html in the GruntFile to an invalid address, I get this error :( I kind of stuck here, has anyone experience running this on OS X? Thx for any advice :)

Gruntfile extract:

    mocha_phantomjs: {
        cov : {
            options : {
                run : false,
                urls : [ 'http://localhost:<%= connect.options.port %>/test/index.html' ],
                reporter: 'xunit',
                output: 'app/test/cov/report/TEST-all.xml'
            }
        },
        test : {
            options : {
                run : false,
                urls : [ 'http://localhost:<%= connect.options.port %>/test/index.html' ],
                reporter: 'spec'
            }
        },
      },

...

grunt.registerTask('test', [ 
    'clean:dist', 
    'compass', 
    'connect:app', 
    'mocha_phantomjs:test' ]);

Failed to start mocha: Init timeout

I am getting the same error mentioned in this stackoverflow thread. Is there any workaround? I don't like the idea to downgrade my nodeJS :(
My code works with grunt-mocha but I like to use the report capabilities of this plugin. Therefore I doubt the error is in my code. If it helps, I will, of course, post snippets.

Thx in advance

edit

I just tried mocha-phantomjs only and it fails with the same error. :( I'll open up an issue there as well.

mocha-phantomjs -R dot http://localhost:9000/test/index.html
Failed to start mocha: Init timeout

Index.html:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Mocha Spec Runner</title>
    <link rel="stylesheet" href="../components/mocha/mocha.css">
    <script src="../components/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
    <script src="../components/sinon/index.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="../styles/aktionsmenue.css">
</head>
<body>
    <div id="mocha"></div>   
    <script type="text/javascript" src="../components/requirejs/require.js" data-main="runner/specRunner.js">            </script>
</body>
</html>

Move to mocha-phantomjs-core

The phantomjs code was separated out from the CLI in mocha-phantomjs in preparation for phantomjs2 and to give build plugin authors like you for grunt full control over what version of phantomjs you use, where you get it from, and how you call it. Full discussion is in nathanboktae/mocha-phantomjs#127, and will prevent issues like #36 .

The main difference is options except reporter and URL are passed as a JSON blob. See the documentation, as well as how gulp-mocha-phantomjs is already doing this

PhantomJS path not handling spaces on Windows

I'm running into an issue using this on Windows. When I try to run the task I get:

λ grunt mocha_phantomjs                                           
Running "mocha_phantomjs:all" (mocha_phantomjs) task              
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.                                   

It looks like this is a known issue with Spawn and is detailed a bit here: baudehlo/node-phantom-simple#142

v0.4.1 causes `write after end` error in WriteStream

When I run xunit tests using v0.4.1, I get the following error:

19-Feb-2014 08:38:26    <testcase classname="" name="&quot;after all&quot; hook" time="0" message="write after end"><failure classname="" name="&quot;after all&quot; hook" time="0" message="write after end"><![CDATA[Error: write after end
19-Feb-2014 08:38:26        at writeAfterEnd (_stream_writable.js:130:12)
19-Feb-2014 08:38:26        at WriteStream.Writable.write (_stream_writable.js:178:5)
19-Feb-2014 08:38:26        at Socket.ondata (stream.js:51:26)
19-Feb-2014 08:38:26        at Socket.EventEmitter.emit (events.js:117:20)
19-Feb-2014 08:38:26        at Socket.&lt;anonymous&gt; (_stream_readable.js:746:14)
19-Feb-2014 08:38:26        at Socket.EventEmitter.emit (events.js:92:17)
19-Feb-2014 08:38:26        at emitReadable_ (_stream_readable.js:408:10)
19-Feb-2014 08:38:26        at emitReadable (_stream_readable.js:404:5)
19-Feb-2014 08:38:26        at readableAddChunk (_stream_readable.js:165:9)
19-Feb-2014 08:38:26        at Socket.Readable.push (_stream_readable.js:127:10)]]></failure></testcase>
19-Feb-2014 08:38:26    </testsuite>

I then tried with v0.4.0 and everything runs just fine. The error could be related to this commit?

Here are some hopefully relevant bits of my Gruntfile:

            xunit: {
                src: ["js/test/**/*.html"],
                options: {
                    reporter: "xunit",
                    output: "xunit_results/phantomjs.xml"
                }
            }

Please let me know if there's any other info that would be helpful!

How do I configure mocha timeout

In our tests we pull in a lot of files and are experiencing mocha timeouts - possibly because the files take time to download.

What options do I use to configure the mocha timeout when using grunt-mocha-phantomjs plugin?

Thanks,
Kiran.

mocha-phantomjs dependencies

Now i have another trouble...
Module mocha-phnatomjs does not have phantomjs in dependencies... But when spawn phantom process path for binary resolved this way:

var phantomjs;
for (var i=0; i < module.paths.length; i++) {
  var bin = path.join(module.paths[i], '.bin/phantomjs');
  if (process.platform === 'win32') {
    bin += '.cmd';
  }
  if (exists(bin)) {
    phantomjs = spawn(bin, spawnArgs);
    break;
  }
}
if (phantomjs === undefined) { phantomjs = spawn('phantomjs', spawnArgs); }

Because grunt-mocha-phantomjs have phantom in package.json dependencies phantomjs spawn by last line... To resolve this issue i suggest remove phantomjs from dependencies and add notation on readme about need to include phantomjs in the list of dependencies in the project.

And one another thing: in cf1d867 commit resolving path should bubble from down to top level as in code above. Should i send pull request?

Doesn't find the binaries

Hi,

I have the issue that the installed dependencies do not work

  • on my machine (Mac OS X 10.8)
  • on travis

I now wrote a little task myself based on http://pastebin.com/Vy53zmTT

It uses the global dependencies installed by phantomjs and mocha-phantomjs

Please try to strip your module down so it doesn't install everything again.

Unable to open file 'spec'

Whenever I run the task with default options (only specifying the src), I get the following output (includes the --verbose flag):

Running "mocha_phantomjs:src" (mocha_phantomjs) task
Verifying property mocha_phantomjs.src exists in config...OK
Files: C:/testRunner.html -> src
Options: reporter="spec", urls=[]
Unable to open file 'spec'

Introducing an explicit reporter, such as dot, results in the same thing but with dot replacing spec in the error.

Here's my npm list output:

http://i.imgur.com/6UGHu0H.png

Anyone run into this?

URL only tests

If I define

mocha_phantomjs:{
    options: {
            'urls'      : [ 'http://localhost:1337/test/ajaxtests.html']
            }
        }

The grunt task runs with nothing done - as there are no "files" to run - but If only want to test a specific test script that runs on a webserver I cannot

Version of phantom installed

it seems that this module installs phantomjs. my question today is: how can I change the version of phantomjs that gets installed? at present it's 1.9.8 but that version is broken. see: ariya/phantomjs#12697

so I'd like to downgrade to 1.9.7 but having done:

# npm uninstall phantomjs
# npm install [email protected] --save-dev

in my project I still get 1.9.8 to run during tests because the version under grunt-mocha-hpantomjs didn't change. so how can I change it?

How to handle `onConfirm` in grunt-mocha-phantomjs?

Hi there, I was wondering if there is a grunt-mocha-phantomjs best practice for using the phantomjs onConfirm callback. I would like to test some things that trigger window.confirm. Maybe writing tests for window.confirm isn't really a thing.

Disabled output configuration causes crash

If you haven't specified an output file, this will cause the build to crash:

   Callback component
    with invalid callback
      ✓ should throw an error when ERROR port is not attached
      ✓ should transmit an Error when ERROR port is attached
    with valid callback
      ✓ should call the callback with the given data


  108 tests complete (1 seconds)

Fatal error: Unable to write "undefined" file (Error code: undefined).

Error on new version of mocha-phantom released today

npm i grunt-mocha-phantomjs

As of today, yields:

npm ERR! Darwin 14.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "i" "grunt-mocha-phantomjs"
npm ERR! node v0.12.7
npm ERR! npm  v2.11.3
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package phantomjs does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants [email protected] - 1.9.7-15

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/lmarkus/dev/scratch/t1/npm-debug.log

Not found error if PhantomJS not installed globally

node_modules/grunt-mocha-phantomjs/node_modules/mocha-phantomjs/node_modules/which/which.js:83
  throw new Error("not found: "+cmd)
        ^
Error: not found: phantomjs
    at Function.whichSync [as sync] (/Users/okonet/Projects/jetbrains/jing/webui/node_modules/grunt-mocha-phantomjs/node_modules/mocha-phantomjs/node_modules/which/which.js:83:9)
    at Object.<anonymous> (/Users/okonet/Projects/jetbrains/jing/webui/node_modules/grunt-mocha-phantomjs/node_modules/mocha-phantomjs/bin/mocha-phantomjs:97:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

Nyan Reporter not found

I am getting an error when adding 'reporter: "nyan"' to the options.

Doing a little research it looks like nyan is not on the list of reporters that are in coffeescript. Does it just need to be converted to coffeescript?

Multiple configurations

Grunt allows for multiple configurations ....something like:

grunt_task: {
   foo: {
      options: { test: true; }
   },
   bar: {
      options: { test:false; }
   }
}

...which can be called like grunt_task:foo or grunt_task:bar. I'm trying to setup something similar with grunt-mocha-phantomjs b/c I want to use different reporters depending on if I'm running dev tests or running tests in CI, but so far have not been successful.

Is this something you support in your plugin - or will support?

Filter App Debug Messages from reports

Hi,

When generating a Xunit report for example debugging messages from my app end up in the report. I could deactivate the debug messages for the test or filter them myself afterwards but I think it would be nice to have only the report being written into the output file, if that's possible. Thx for your help.

Combine output into one report when running multiple files?

More of a request than a bug -- and I may be interested and willing to contribute work if the idea seems cogent: when running grunt mocha_phantomjs on more than one HTML file, it'd be handy to have a custom reporter that compiles all the output into a single result.

As it stands right now, if it's running on, say, 20 files, and there's a test failure in the first test file, you have to scroll all the way back up through 20 sets of test results to read the error output, rather than a single concatenated set of results.

If the idea seems worth pursuing, a potential follow-up concept would be making it more performant on a large number of files by not starting a fresh Phantom process for each file. That may be more of a concern for the mocha-phantomjs project than this, though. I'm not intimate enough with the code of either project to know where that line is drawn.

Let me know your thoughts! Like I said, I'd be happy to contribute if you think the idea has merit.

What mocha options are supported

Are the only two pass-through options that are supported the list of urls and the reporter?

mocha-phantomjs supports quite a few other options, is there any way to just allow a pass-through via grunt so they are all supported?

Usage: mocha-phantomjs [options] page

  Options:

    -h, --help                   output usage information
    -V, --version                output the version number
    -R, --reporter <name>        specify the reporter to use
    -t, --timeout <timeout>      specify the test startup timeout to use
    -A, --agent <userAgent>      specify the user agent to use
    -c, --cookie <name>=<value>  specify cookie
    -h, --header <name>=<value>  specify custom header
    -s, --setting <key>=<value>  specify specific phantom settings
    -v, --view <width>x<height>  specify phantom viewport size
    -C, --no-color               disable color escape codes

Latest update broke tests

Hey @jdcataldo - the latest update isn't working for me anymore.

I see this in my console when I run my tests now:

>> Can't open 'node_modules/grunt-mocha-phantomjs/node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee'
>> Exited with code: 255.

Failed tests don't fail the build

Currently if you have failing tests, the Grunt build will still complete, which means CI environments like Travis think everything works.

✖ 1 of 106 tests failed:

1) Network with a simple graph should contain two nodes:
   TypeError: 'null' is not an object (evaluating 'n.processes')
    at file:///home/bergie/Projects/noflo/noflo/spec/Network.js:88
    at file:///home/bergie/Projects/noflo/noflo/node_modules/mocha/mocha.js:4039
    at file:///home/bergie/Projects/noflo/noflo/node_modules/mocha/mocha.js:4404
    at file:///home/bergie/Projects/noflo/noflo/node_modules/mocha/mocha.js:4463
    at next (file:///home/bergie/Projects/noflo/noflo/node_modules/mocha/mocha.js:4330)
    at file:///home/bergie/Projects/noflo/noflo/node_modules/mocha/mocha.js:4339
    at next (file:///home/bergie/Projects/noflo/noflo/node_modules/mocha/mocha.js:4287)
    at file:///home/bergie/Projects/noflo/noflo/node_modules/mocha/mocha.js:4307
    at timeslice (file:///home/bergie/Projects/noflo/noflo/node_modules/mocha/mocha.js:5279)

Done, without errors.

incorrect (zero) error status: when multiple urls are tested

when there are multiple url in mocha_phantomjs configuration, the run is always reported as successful; despite one (or multiple) url failing

is there an option to 'fail fast'? (or at least report non zero status when one of the urls is non-zero?)

here is an example, the test:full_testing will always succeed, but individual tests will fail

mocha_phantomjs: {
      options: {
        //'reporter': 'progress',
        'output': 'test/reports/' + (grunt.option('testname') || 'mocha/discovery')
      },

      local_testing: ['test/' + (grunt.option('testname') || 'mocha/discovery') + '.spec.html'],

      web_testing: {
        options: {
          urls: [
              'http://localhost:<%= local.port || 8000 %>/test/' + (grunt.option('testname') || 'mocha/discovery') + '.spec.html'
          ]
        }
      },

      full_testing: {
        options: {
          urls: [
            'http://localhost:<%= local.port || 8000 %>/test/mocha/discovery.spec.html',
            'http://localhost:<%= local.port || 8000 %>/test/mocha/discovery-ui.spec.html',
            'http://localhost:<%= local.port || 8000 %>/test/mocha/discovery-qb.spec.html'
          ]
        }
      }
    },

you can see it at work https://travis-ci.org/adsabs/bumblebee/jobs/33810821 - line 2400

Unsafe JavaScript attempt to access frame with URL about:blank

I get the notice Unsafe JavaScript attempt to access frame with URL about:blank when I run grunt_mochaphantomjs in my terminal.

My Gruntfile config looks like this:

mocha_phantomjs: {
  all: ['tests/**/*.html']
},

My tests.html file looks like this:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>Example Mocha Test</title>
    <link rel="stylesheet" href="../node_modules/mocha/mocha.css" type="text/css" charset="utf-8" />
</head>
<body>
    <!-- Required for browser reporter -->
    <div id="mocha"></div>

    <!-- mocha -->
    <script src="../node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">
        // This will be overridden by mocha-helper if you run with grunt
        mocha.setup('bdd');
    </script>

    <!-- Include your assertion lib of choice -->
    <script src="../node_modules/chai/chai.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8">
        // Setup chai
         var should = chai.Should();
    </script>

    <!-- Include anything you want to test -->
    <script src="../dist/app.js" type="text/javascript" charset="utf-8"></script>

    <!-- Spec files -->
    <script src="startGame.js" type="text/javascript" charset="utf-8"></script>

    <!-- run mocha -->
    <script type="text/javascript" charset="utf-8">
        // If tests run in a real browser
        // Can alternatively do a check on window.PHANTOMJS
        mocha.run();
    </script>
</body>
</html>

My test file looks like:

'use strict';

describe('Feature: Start Game', function() {

    context('Scenario 1: Given a game has started', function() {

        describe('When application is initatiated', function() {

            it('Should throw an error - Game has initiated', function() {
                app.should.throw(Error);
            });

        });

    });

    context('Scenario 2: Given no game has started', function() {

        describe('When application is initiating', function() {

            console.log(app);

            it('Should start the game', function() {
                app.game.should.be.an.instanceof(Game);
            });

        });

    });

});

The actual error I get only occurs in terminal, and not when I run the html directly in the browser:

Unsafe JavaScript attempt to access frame with URL about:blank from frame with U
RL file:///c:/workspace/projects/demo.battleship3/node_modules/grunt-mocha-phant
omjs/node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js. Domains, protoco
ls and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with U
RL file:///c:/workspace/projects/demo.battleship3/node_modules/grunt-mocha-phant
omjs/node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js. Domains, protoco
ls and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with U
RL file:///c:/workspace/projects/demo.battleship3/node_modules/grunt-mocha-phant
omjs/node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js. Domains, protoco
ls and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with U
RL file:///c:/workspace/projects/demo.battleship3/node_modules/grunt-mocha-phant
omjs/node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js. Domains, protoco
ls and ports must match.

Test coverage with Istanbul?

Hi, I have been trying to make this work but I haven't been able at all:

mocha_phantomjs: {
  all: './tests.html',
  options: {
    coverage: {
      reporter: 'istanbul'
    }
  }
}

The tests work perfectly, but there's no code coverage at all, which I'd love to have. Do you have any clue how to include it? I'd prefer using Istanbul since I've used it before for pure Node.js testing, but I'm having trouble integrating it with phantomjs. I have tried many different things, but none seem to help me getting closer to make a test coverage:

mocha_phantomjs: {
  all: './tests.html',
  options: {
    coverage: {
      htmlReport: 'coverage/html'
    }
  }
}

Error when trying to set the 'hooks' option

I need to use the 'hooks' option of mocha-phantomjs but I cannot set it correctly in Gruntfile.

The following instruction works correctly in terminal:

 mocha-phantomjs ./test/test.html --hooks ./test/phantom_hooks.js -R xunit -f test/results/result.xml

In my Gruntfile.js, I have put the following configuration:

grunt.initConfig({
    ...
    mocha_phantomjs: {
      options: {
        reporter: 'xunit',
        output: 'test/results/result.xml',
        config: {
          "hooks": './test/phantom_hooks.js'
        }
      },
      all: 'test/test.html'
    }
});

When I run grunt mocha_phantomjs I get the following error:

Error loading hooks: Cannot find module './test/phantom_hooks.js'

Am I doing something wrong or is this an issue of the plugin?

Reporter output always goes to stdout

I'm using mocha-lcov-reporter and grunt-mocha-phantomjs to generate code coverage data. It works great! But the reported data always gets dumped to stdout, even though I've configured an output in my Gruntfile.js:

mocha_phantomjs: {
  cov: {
    src: ['test/coverage.html'],
    options: {
      reporter: 'node_modules/mocha-lcov-reporter/lib/lcov.js',
      output: 'build/bundled.lcov'
    }
  }
}

Is this the desired behavior? Is there any way to force the reporter's output to just go to the file, rather than both to the file and stdout?

Report output contents get truncated

When I use the json-cov reporter and output to a file (like in the setting below) the contents of the file get truncated. It ends up being invalid json with missing data.

mocha_phantomjs: { coverage: { options: { reporter: 'json-cov', output: 'coverage.json', urls: ['http://url/to/index.html'] }, }, }

If I run mocha_phantomjs from the command line like so...

mocha-phantomjs -R json-cov http://url/to/index.html > coverage.json

... then I get a completely populated file. This leads me to believe it's either an issue with the grunt plugin or with grunt itself. If it matters, the truncated file ends up being about 648k and the fully-populated file is 965k.

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.