Giter Site home page Giter Site logo

mocha-phantomjs's Introduction

PhantomJS Runners for Mocha

Deprecated

Ariya Hidayat archived phantomjs on March 3rd, 2018. (See this tweet for more info). phantomjs served us all as great headless browser for years, but now with Electron and headless modes for both Chrome and Firefox, we have much better options. mocha-chrome is a project inspired by mocha-phantomjs, so migration should be easy, and you will be running your tests on the same browser that 50% of your users actually use! I highly recommend it.

I will accept pull requests still, but I won't be answering issues or doing feature work myself.

Summary

Mocha is a feature-rich JavaScript test framework running on node and the browser. Along with the Chai assertion library they make an impressive combo. PhantomJS is a headless WebKit with a JavaScript API.

Since 4.0, the phantomjs code now is in mocha-phantomjs-core. If you need full control over which phantomjs version to use and where to get it, including PhantomJS 2.0 and SlimerJS, or want to use it more programatically like a build system plugin, please use that package directly. This project is a node.js CLI around it.

Build Status

Key Features

Standard Out

Finally, process.stdout.write, done right. Mocha is primarily written for node, hence it relies on writing to standard out without trailing newline characters. This behavior is critical for reporters like the dot reporter. We make up for PhantomJS's lack of stream support by both customizing console.log and creating a process.stdout.write function to the current PhantomJS process. This technique combined with a handful of fancy ANSI cursor movement codes allows PhantomJS to support Mocha's diverse reporter options.

Exit Codes

Proper exit status codes from PhantomJS using Mocha's failures count. So in standard UNIX fashion, a 0 code means success. This means you can use mocha-phantomjs on your CI server of choice.

Mixed Mode Runs

You can use your existing Mocha HTML file reporters side by side with mocha-phantomjs. This gives you the option to run your tests both in a browser or with PhantomJS, with no changes needed to your existing test setup.

Installation

We distribute mocha-phantomjs as an npm package that is easy to install. Once done, you will have a mocha-phantomjs binary. See the next usage section for docs or use the -h flag.

Usage

  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
    -f, --file <filename>        specify the file to dump reporter output
    -t, --timeout <timeout>      specify the test startup timeout to use
    -g, --grep <pattern>         only run tests matching <pattern>
    -i, --invert                 invert --grep matches
    -b, --bail                   exit on the first test failure
    -A, --agent <userAgent>      specify the user agent to use
    -c, --cookies <Object>       phantomjs cookie object http://git.io/RmPxgA
    -h, --header <name>=<value>  specify custom header
    -k, --hooks <path>           path to hooks module
    -s, --setting <key>=<value>  specify specific phantom settings
    -v, --view <width>x<height>  specify phantom viewport size
    -C, --no-color               disable color escape codes
    -p, --path <path>            path to PhantomJS binary
    --ignore-resource-errors     ignore resource errors

  Any other options are passed to phantomjs (see `phantomjs --help`)

  Examples:

    $ mocha-phantomjs -R dot /test/file.html
    $ mocha-phantomjs https://testserver.com/file.html --ignore-ssl-errors=true
    $ mocha-phantomjs -p ~/bin/phantomjs /test/file.html

Now as an node package, using mocha-phantomjs has never been easier. The page argument can be either a local or fully qualified path or a http or file URL. --reporter may be a built-in reporter or a path to your own reporter (see below). See phantomjs WebPage settings for options that may be supplied to the --setting argument.

Since 4.0, you need no modifications to your test harness markup file to run. Here is an example test.html:

<html>
  <head>
    <meta charset="utf-8">
    <!-- encoding must be set for mocha's special characters to render properly -->
    <link rel="stylesheet" href="mocha.css" />
  </head>
  <body>
    <div id="mocha"></div>
    <script src="mocha.js"></script>
    <script src="chai.js"></script>
    <script>
      mocha.ui('bdd')
      expect = chai.expect
    </script>
    <script src="src/mycode.js"></script>
    <script src="test/mycode.js"></script>
    <script>
      mocha.run()
    </script>
  </body>
</html>

Screenshots

Mocha-phantomjs supports creating screenshots from your test code. For example, you could write a function like below into your test code.

function takeScreenshot() {
  if (window.callPhantom) {
    var date = new Date()
    var filename = "screenshots/" + date.getTime()
    console.log("Taking screenshot " + filename)
    callPhantom({'screenshot': filename})
  }
}

If you want to generate a screenshot for each test failure you could add the following into your test code.

  afterEach(function () {
    if (this.currentTest.state == 'failed') {
      takeScreenshot()
    }
  })

Supported Reporters

mocha-phantomjs works by piping Mocha.process.stdout to PhantomJS's stdout. Any reporter that can work in the browser works with mocha-phantomjs.

Bundled and tested reporters include:

spec (default)
dot
tap
min
nyan
list
doc
teamcity
json
json-cov
xunit
progress
landing
markdown

When using the dot reporter, the PhantomJS process has no way of knowing anything about your console window's width. So we default the width to 75 columns. However, if you set the COLUMNS environment variable, it will pick that up and adjust to your current terminal width. For example, using the $COLUMNS variable like so.

env COLUMNS=$COLUMNS phantomjs mocha-phantomjs.coffee URL dot

Third Party Reporters

Mocha has support for custom 3rd party reporters, and mocha-phantomjs does support 3rd party reporters, but keep in mind - the reporter does not run in Node.js, but in the browser, and node modules can't be required. You need to only use basic, vanilla JavaScript when using third party reporters. However, some things are available:

  • require: You can only require other reporters, like require('./base') to build off of the BaseReporter
  • exports, module: Export your reporter class as normal
  • process: use process.stdout.write preferrably to support the --file option over console.log (see #114)

Also, no compilers are supported currently, so please provide JavaScript only for your reporters.

Testing

Simple! Just clone the repo, then run npm install and the various node development dependencies will install to the node_modules directory of the project. If you have not done so, it is typically a good idea to add /node_modules/.bin to your $PATH so these modules bins are used. Now run npm test to start off the test suite.

We also use Travis CI to run our tests too. The current build status:

Build Status

License

Released under the MIT license. Copyright (c) 2015 Ken Collins, Nathan Black, and many generous GitHub Contributors.

mocha-phantomjs's People

Contributors

alexeykuzmin avatar alexgorbatchev avatar andreialecu avatar andreypopp avatar arian avatar astorije avatar chafnan avatar codeofficer avatar daanwissing avatar erikvold avatar filirom1 avatar hokaccha avatar j0tunn avatar janza avatar jednano avatar joelleibow avatar jschementi avatar julesbou avatar kpdecker avatar mattrobenolt avatar metaskills avatar midripps avatar nathanboktae avatar nqbao avatar r4d1n avatar raimohanska avatar romario333 avatar sheldonh avatar uliedberg avatar vestride 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mocha-phantomjs's Issues

Cannot get --setting to work (to enable CORS)

I can't seem to get --setting to work for my script, or perhaps I don't understand how it works. Is it supposed to be a collection of settings like the ones for the PhantomJS command line (as documented here?)

I'm trying to allow my test script to run cross-domain (CORS) requests as part of my test. The options I think I need are --web-security=false and --local-to-remote-url-access=true but no permutations of those options passed to mocha-phantomjs seem to work. I've tried renaming the params to webSecurity and webSecurityEnabled but it's just not working.

If I modify mocha-phantomjs bin to adjust spawnArgs, I get some different results, but it breaks mocha-phantomjs.coffee since it's expecting a specific set of params.

Thanks!

Using console.log breaks output

I'd like to use the JSON reporter but my project sometimes has stray console.log messages for debugging. These messages get mixed in with the reporter output and thus results in broken JSON. There needs to be an option to output console.log to stderr or suppressed entirely so as not to break the reporter output.

Local installation

Why can't I run mocha-phantomjs with a local installation without -g?

Tests hanging after running

First of all thanks again for your help and the effort that you have put into this project.

My test are hanging after successfully running with errors.
Basically I expected to be returned to the command prompt and I am not.

it seems that the end event is not being triggered.

ref

runner: (reporter) ->
    try
      mocha.setup reporter: reporter
      mocha.phantomjs = failures: 0, ended: false, run: false
      mocha.phantomjs.runner = mocha.run()
      if mocha.phantomjs.runner
        mocha.phantomjs.runner.on 'end', ->
          mocha.phantomjs.failures = @failures
          mocha.phantomjs.ended = true
    catch error
      false

am I supposed to be triggering this event somewhere.

thanks again for your help.

Tests break with iframes and phantomjs 1.8.0

Hi, this might be old news, bust still wanted to create a report, telling that the tests are failing for the spec

"does not fail when an iframe is used"

Osx 10.8.2 / PhantomJS 1.8.0

running from a cakefile

When I run my tests from the console (i.e. mocha-phantomjs -R dot /test/test.html) it works well.
But when I do the same from my cakefile:

exec "mocha-phantomjs -R spec test/test.html", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr

I get:

Error: Command failed:
at ChildProcess.exithandler (child_process.js:540:15)
at ChildProcess.EventEmitter.emit (events.js:99:17)
at maybeClose (child_process.js:638:16)
at Process._handle.onexit (child_process.js:680:5)

mocha-phantomjs does not use the -p option

program
  .version(JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8')).version)
  .usage('[options] page')
  .option('-R, --reporter <name>',       'specify the reporter to use', 'spec')
  .option('-t, --timeout <timeout>',     'specify the test startup timeout to use', parseInt, 6000)
  .option('-A, --agent <userAgent>',     'specify the user agent to use')
  .option('-c, --cookies <Object>',      'phantomjs cookie object http://git.io/RmPxgA', cookiesParser) // http://git.io/RmPxgA
  .option('-h, --header <name>=<value>', 'specify custom header', header)
  .option('-s, --setting <key>=<value>', 'specify specific phantom settings', setting)
  .option('-v, --view <width>x<height>', 'specify phantom viewport size', viewport)
  .option('-C, --no-color',              'disable color escape codes');

program.on('--help', function(){
  console.log('  Examples:');
  console.log('');
  console.log('    $ mocha-phantomjs -R dot /test/file.html');
  console.log('    $ mocha-phantomjs http://testserver.com/file.html');
  console.log('');
});

No longer takes the -p option. Even in the code itself,

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;
  }
}

It's cycling through the node_modules paths. I need the -p to specify where phantomjs is since I don't have it in a normal place and the -p was there at one point.

Make it easier to plug in custom reporters

I'd rather not have to fork the repo to add a reporter class. Mocha itself makes this pretty straightforward, see eg. https://github.com/visionmedia/mocha/wiki/Third-party-reporters
but mocha-phantomjs doesn't because it defines the reporter classes in the same file that parses the command line and instantiates a reporter.

It would be really cool if vanilla Mocha third-party reporters could just be dropped in somehow, but I don't know what that would entail ... generate a wrapper class on the fly or something?

json-cov works, but html-cov gives "Failed to start mocha."

I saw your commit 3 days ago and was very excited to see support for json-cov and html-cov, awesome!

I tested it today, and json-cov seems to work perfectly:

$ phantomjs components/mocha-phantomjs/lib/mocha-phantomjs.coffee test.html json-cov
{
  "instrumentation": "node-jscoverage",
  "sloc": 396,
  "hits": 223,
  "misses": 173,
  "coverage": 56.313131313131315,
  "files": [
    {
      "filename": "Class.js",
      "coverage": 63.63636363636363,

However, html-cov doesn't:

$ phantomjs components/mocha-phantomjs/lib/mocha-phantomjs.coffee test.html html-cov
Failed to start mocha.

Fails on travis

I'm trying to run my mocha-phantomjs tests on Travis CI but only get

Failed to start mocha.

The same can be successfully run on my own machine.

Any experiences on running mocha-phantomjs tests on Travis CI?

Here's an example failed build

Growl support?

Didn't see an option for that. Is there any reason I can't just pass through valid mocha options directly through?

Possible EventEmitter memory leak detected (in TravisCI)

Maybe it'd be nice to rise up this max listeners property?

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at process.EventEmitter.addListener (events.js:175:15)
    at process.startup.processSignalHandlers.process.on.process.addListener (node.js:482:29)
    at Object.exports.install (/home/travis/build/serpentem/polvo/node_modules/source-map-support/source-map-support.js:146:13)
    at Object.<anonymous> (../../../src/polvo/core/tree.coffee:1)

In this case I have a class that is instantiated many times, so I guess each instance sets up a listener. Opening this up for a bunch of files in a folder, it can be huge.

Results here.

Any other thoughts about it?

npm module?

Looks pretty good so far. Any idea when we'll have an npm module ready?

Getting the Error: spawn ENOENT on Windows7 x64. with node v0.10.5

Hi,

Our mocha tests ran fine on OSX using mocha-phantomjs (latest version) using node v0.10.5 but on Windows7 (x64) i get the following error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:975:11)
    at Process.ChildProcess._handle.onexit (child_process.js:766:34)

I've setup test files to reproduce the error at https://gist.github.com/theanimal666/5538827

Here the details of my environment:

  • Windows7 x64 (fully patched)
  • Node.Js 0.10.5
  • PhantomJS 1.9.0
  • mocha 1.9.0

I also tried different shells (git bash, cmd, powershell), the error is always the same. In Chrome the tests run fine.

regards,
Chris

OSX Garbled output chars

Instead of the snazzy checkmarks and X'es I get garbled characters.

â—¦ is a test that passes:
✓ is a test that passes
â—¦ is a test that fails:

  1. is a test that fails

screen shot 2013-04-29 at 6 42 05 pm

could be something in my .bashrc.. but my terminal is set to UTF-8 and changing it to anything else just makes it worse.

support and documentation for programmatic use as a Node.JS module

My current project has a test suite Node.JS app that fires up a simple HTTP server and uses https://github.com/sgentle/phantomjs-node and bridge-code I wrote myself to programmatically start PhantomJS, point it at my browser test URLs, collect the results, and then include them in the results collected from the pure Node.JS tests.

Anyhow, I'm looking to replace phantomjs-node, as it looks like it is now unmaintained and is broken with PhantomJS 1.7.

I am not trying to pit your project against the other one, that would be silly. I would, however, prefer to be able to control the PhantomJS instance programmatically with your project in a similar fashion to the other project.

Failed to start mocha.

hi, I really like the idea of your lib but can't get it to work right.

my Html Looks like this:(/public/test.html)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Apollo Dashboard Mocha Tests</title>
    <link rel="stylesheet" href="css/mocha.css" />
    <script src="js/vendor/require.js" type="text/javascript"></script>
    <script>
        requirejs.config({
          baseUrl: 'js/',
          paths: {
            jquery: 'vendor/jquery.min',
            underscore: 'vendor/underscore',
            backbone: 'vendor/backbone',
            handlebars: 'vendor/handlebars',
            text: 'vendor/require-text',
            json: 'vendor/require-json',
            chaplin: 'vendor/chaplin',
            mocha: 'vendor/mocha',
            chai: 'vendor/chai',
            sinon: 'vendor/sinon',
            moment: 'vendor/moment'
          },
          shim: {
            backbone: {
              deps: ['underscore', 'jquery'],
              exports: 'Backbone'
            },
            underscore: {
              exports: '_'
            }
          }
        });
    </script>
</head>
<body>
    <div id="mocha"></div>
    <script type="text/javascript">
        require(['require', 'vendor/chai', 'vendor/mocha', 'vendor/sinon'], function(require, chai) {

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

            mocha.setup({
                ui: 'bdd',
                ignoreLeaks: true
            });
            var specs = [
                // lib
                'test/lib/collection_json/collection_json',
                'test/lib/utils',
                // models
                'test/models/base/model',
                'test/models/base/collection',
                // 'test/models/campaigns',
                // form fields
                'test/views/input/input',
                'test/views/input/text',
                'test/views/input/textarea',
                'test/views/input/checkbox',
                'test/views/input/email',
                'test/views/input/password',
                'test/views/input/button',
                'test/views/input/submit_button',
                'test/views/input/reset_button',
                'test/views/input/number',
                // 'test/views/input/select',
                'test/views/input/date_time',
                'test/views/input/date',
                // form
                'test/views/form'
            ];
            require(specs, function() {
                if (!window.mochaPhantomJS) { mocha.run(); }
            })
        })
    </script>
</body>
</html>

I have the mocha-phantomjs.coffee and mocha-phantomjs.coffee
in the root dir

when i run phantomjs mocha-phantomjs.coffee http://localhost:8080/test.html spec i get on of the following responses.

ReferenceError: Can't find variable: process

  mocha-phantomjs/core_extensions.js:21
  mocha-phantomjs/core_extensions.js:82
ReferenceError: Can't find variable: process

  phantomjs://webpage.evaluate():2
  phantomjs://webpage.evaluate():8
  phantomjs://webpage.evaluate():8
ReferenceError: Can't find variable: process

  phantomjs://webpage.evaluate():3
  phantomjs://webpage.evaluate():17
  phantomjs://webpage.evaluate():17
Failed to start mocha.

or

Failed to start mocha.

Am I missing something, did i forget a ste?

Oh and I did do npm install before trying to run the script

my npm version is _1.1.59_
my node version _v0.8.8_
my phantom js version _1.6.1_

mocha process

Hi,

I tried using latest mocha-phantomjs, phantomjs and mocha and got the error ReferenceError: Can't find variable: process.

Now I read:

Since version 3.0 of mocha-phantomjs, you must use PhantomJS 1.9.1 or higher.
As of now Mocha 1.10.x is unsupported. We must lobby Mocha.js for a Mocha.process hook.

on the Readme... What does this actually mean? How do I get the tests to run properly?

Watch file changes

I would love a feature to run mocha-phantomjs in watch-mode, such that it automatically runs all the tests when I save a file.

Mocha has this functionality built in with the -w parameter, but of course this does not work with mocha tests in a html harness.

console.log

not sure how weird it would be to wire up console.log output for the term but it would be great!

Emulating resize events

Is it possible to expose an API in the browser for resizing the window? I'm trying to test some media query stuff

Cannot Run on CLI (process variable undefined errors)

I can't seem to get mocha-phantomjs to run on the CLI. (below is my console output)

This occurs regardless of whether I use the NPM-installed version or the official download of PhantomJS. I've also tried downgrading mocha-phantomjs to previous versions to try and resolve, to no avail.

In addition, I know it's not mocha itself because even if I remove all my scripts from the page itself, the first 3 ReferenceErrors still occur exactly the same.

fwiw, I'm using Component.js to build my JS/CSS for the page, so I'm using the correct mocha script. (as mentioned in #8) In addition, my tests work completely fine in a full browser.

./node_modules/.bin/mocha-phantomjs test/test.html
ReferenceError: Can't find variable: process

  mocha-phantomjs/core_extensions.js:21
  mocha-phantomjs/core_extensions.js:82
ReferenceError: Can't find variable: process

  phantomjs://webpage.evaluate():2
  phantomjs://webpage.evaluate():8
  phantomjs://webpage.evaluate():8
ReferenceError: Can't find variable: process

  phantomjs://webpage.evaluate():3
  phantomjs://webpage.evaluate():17
  phantomjs://webpage.evaluate():17
%s%s  
%s%s    $.nh.durationspinner
%s%s      #stepUp()
TypeError: 'undefined' is not a function (evaluating 'process.stdout.write('\u001b[2K')')

  :1771
  :1779
  :3534
  :521
  :4250
  :4267
  :4300
  :4043
  :4303 in next
  :4307
  :5279 in timeslice

Improved installation docs

Hi,

I know this isn't awfully constructive (and I apologise in advance), but I'm finding the README.md lacks one important part: setup requirements.

I've got phantomJS setup (and it was running fine with node-phantomjs previously), but running mocha-phantomjs http://my.dev/tests/mixed.html doesn't output anything.

Can't set cookie

Trying to set cookie with --cookie. But server shows that there is no suck header Cookie in request. For some reason page.addCookie in mocha-phantomjs.coffee doen't work. Probably something wrong with phantomjs, don't know.

To fix this I'm using phantom.addCookie limpbrains@e173ca0
But this is bad idea, This will works only with localhost.

I've tried last mocha-phantiomjs from git and phantomjs 1.7.
Also I'm using ubuntu

using without binary

it'd be nice to have the ability to:

var mocha = require('mocha-phantomjs')
mocha.set(myoption, true)
mocha.run('./test.html', function (/* ... */) {
  // ...
})

rather than relying on the binary:

$ mocha-phantomjs --my-option true test.html

i know this would be a complete refactor, but it's something to think about...

--globals support (from mocha)

Is there a way to list my safe globals with mocha-phantomjs? I'm getting "global leaks detected" warnings that are making my tests fail.

vague error

mocha-phantomjs test/index.html
Failed to start mocha.

not sure what to think that it might be haha

Can't perform remote ajax calls

Hi, some of our mocha tests hit an API server (e.g. not localhost). When we run those tests in the browser, they pass. However, running the tests using mocha-phantomjs, they fail. I can see that the phantomjs api has a "local to remote url access" flag which can be set.

I've set this flag using the new -s option (e.g. mocha-phantomjs public/mocha/runner.html -s localToRemoteUrlAccessEnabled=true -s webSecurityEnabled=false) but the tests still fail.

Then I tried editing the mocha-phantomjs/bin/mocha-phantomjs program (line 87: var phantomjs = spawn('phantomjs', ['--local-to-remote-url-access=yes', script, page, reporter, JSON.stringify(config)]);) and it still doesn't work.

Any guidance is very much welcomed.

sometimes it breakes.

hello!

i really enjoy your work, but it breaks sometimes :)
its not the best, when its not reliable...
i use the following tools an plugins:

requirejs loads (via config.js):

  • chai
  • sinon,
  • mocha
  • my app (and it as its requirements: jquery, handlebars, ember (&data))
  • the specs

and sometimes i get my specs done, and when not i get this message:

ReferenceError: Can't find variable: process

  mocha-phantomjs/core_extensions.js:21
  mocha-phantomjs/core_extensions.js:82
ReferenceError: Can't find variable: process

  phantomjs://webpage.evaluate():2
  phantomjs://webpage.evaluate():8
  phantomjs://webpage.evaluate():8
ReferenceError: Can't find variable: process

  phantomjs://webpage.evaluate():3
  phantomjs://webpage.evaluate():17
  phantomjs://webpage.evaluate():17

seems to me, that sometime node don't come up right or sth like it. but when i do loop sth like

if (process) {
    console.log(0);
} else {
    console.log(1);
}

i dont get failures.. any ideas?

Error if phantomjs is not installed

If you install mocha-phantomjs without phantomjs installed, the program immediately exits with no output ($? is 127). It would be useful to print an error message like "you must install phantomjs to run mocha-phantomjs". As an alternative, you might document this requirement in the installation section of the docs.

Thanks! Very useful software.

Broken characters in output on Windows

Everything works fine for me except broken output on Windows (7). I've tried default and dot reporter with same result.

Example:

←[0m ency.Operation.EncyFeature←[0m
←[0m #getCategoryFromId(id)←[0m
←[90m ? should return category for given id: ←[0m
←[32m ?←[0m←[90m should return category for given id ←[0m

Maybe I'm missing something in phantomjs setup or ...

Error: spawn ENOENT with node v0.10.2

hey,

i have a testsuite that works on mac os box with node v0.8.20 . my box is archlinux with node v0.10.2 a it fails. even this simple example does not work:

$ ./bin/mocha-phantomjs ./test/bad.html

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:948:11)
    at Process.ChildProcess._handle.onexit (child_process.js:739:34)

it looks like i am not the only one [1], who gets error like this

[1] http://net.tutsplus.com/tutorials/javascript-ajax/testing-javascript-with-phantomjs/#comment-829198059

maybe it is connected to some node internals [2], but i am not sure..

[2] nodejs/node-v0.x-archive#4674

mocha-phantomjs fails to catch error on async tests, thus corrupting xml/json output

Hey there,

when given

<!doctype html>
<html>
    <head>
        <title> Tests </title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf8">
        <link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
    </head>
    <body class="enyo-unselectable">
        <div id="mocha"></div>
        <script src="../../node_modules/mocha/mocha.js"></script>
        <script src="../../node_modules/expect.js/expect.js"></script>
        <script>
            mocha.ui('bdd');
            mocha.reporter('html');

            it("asyn test", function(done){
                setTimeout(function(){
                    expect(true).to.be(false);
                    done();
                },1);
            })

            setTimeout(function(){
                if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
                else { mocha.run(); }
            }, 1000)
        </script>
    </body>
</html>

mocha-phantomjs produces

$ mocha-phantomjs index.html


  1) asyn test
Error: expected true to equal false

  file://node_modules/expect.js/expect.js:99
  file://node_modules/expect.js/expect.js:203
  file://node_modules/expect.js/expect.js:73
  file://phantomjs-test/index.html:18

  ✖ 1 of 1 test failed:

  1)  asyn test:
     Error: expected true to equal false (file://node_modules/expect.js/expect.js:99)

(notice the first thrown error directly below "1) asyn test") while the same mocha test

$ cat test/test.js 
var expect = require("expect.js");
it("asyn test", function(done){
    setTimeout(function(){
        expect(true).to.be(false);
        done();
    },1);
})

produces

$ mocha -R spec


  1) asyn test

  ✖ 1 of 1 test failed:

  1)  asyn test:
     Error: expected true to equal false
      at Assertion.assert (node_modules/expect.js/expect.js:99:13)
      at Assertion.equal (node_modules/expect.js/expect.js:200:10)
      at Assertion.be (node_modules/expect.js/expect.js:73:24)
      at Object._onTimeout (test/test.js:4:19)
      at Timer.ontimeout (timers.js:94:19)

This breaks JSON and XML output and doesn't seem to be covered by the tests for mocha-phantomjs.

I'm using phantomJS 1.8.1.

Add html-cov reporter

Hi, thanks for the great tool.

Can you add support of html-cov/json-cov reporters from mocha.

Thanks

Feature Request: Data Sharing with Test Script

Hey there, I've been racking my brain trying to figure out how to share some data with my test page. Namely, I came across this article (... tl;dr test different jquery versions by dynamically injecting script tags depending on the version needed for that test) and I am trying to implement the same thing with mocha-phantomjs.

Specifically, I want to be able to pass some sort of variable(s) into the global scope of the page requested. In my case, I want to specify a version of jquery and jquery-ui to load in order to make sure my tests still pass using various versions of the aforementioned libraries.

Can that be done now? If not, then consider this a feature request :)

Tests broken on Travis CI

Anyone getting erros while running tests in Travis CI?

Everything was working fine till about 2 weeks ago, now I got this error:

TypeError: 'undefined' is not an object (evaluating '_ref.length')

  ../../node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee:82
  ../../node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee:37
  ../../node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee:472
  ../../node_modules/mocha-phantomjs/lib/mocha-phantomjs.coffee:478

No output has been received in the last 10 minutes, this potentially indicates a stalled build or something wrong with the build itself.

The build has been terminated

Complete stack:
https://travis-ci.org/serpentem/polvo/builds/7437776

I'm using chai for assertions.

Thanks

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?

glitches in spec reporter output

It seems like the ANSI cursor codes are not working or somethign, because intermediate output is remaining on screen. Best shown by example. Here's a sample of output that I see locally:

  Util
    ◦ #id: 
    ✓ #id 
    ◦ #trueObj: 
    ✓ #trueObj 
    ◦ #friendlyName: 
    ✓ #friendlyName 

And here's how it comes out on travis: https://travis-ci.org/systemed/iD/builds/3497867/#L270

It should come out like:

  Util
    ✓ #id 
    ✓ #trueObj 
    ✓ #friendlyName 

This is for this spec (please excuse the poor style).

Paths searched for phantom is wrong on windows 8

> npm install -g phantomjs
> npm install -g mocha-phantomjs
> mocha-phantomjs http://localhost:8080/run-tests.html
Perhaps phantomjs is not installed?

The paths searched are

C:\Users\George\AppData\Roaming\npm\node_modules\mocha-phantomjs\bin\node_modules\.bin\phantomjs.cmd
C:\Users\George\AppData\Roaming\npm\node_modules\mocha-phantomjs\node_modules\.bin\phantomjs.cmd
C:\Users\George\AppData\Roaming\npm\node_modules\.bin\phantomjs.cmd
C:\Users\George\AppData\Roaming\node_modules\.bin\phantomjs.cmd
C:\Users\George\AppData\node_modules\.bin\phantomjs.cmd
C:\Users\George\node_modules\.bin\phantomjs.cmd
C:\Users\node_modules\.bin\phantomjs.cmd
C:\node_modules\.bin\phantomjs.cmd

but phantomjs is in

C:\Users\George\AppData\Roaming\npm\phantomjs.cmd

As a matter of fact, looking through all possible folders that MIGHT have been the intended target there seem to be no phantomjs target in any.

C:\Users\George\AppData\Roaming\npm\node_modules\mocha-phantomjs> ls . -inc .bin -rec | ls


    Directory: C:\Users\George\AppData\Roaming\npm\node_modules\mocha-phantomjs\node_modules\.bin


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          2/6/2013  10:33 PM        270 mocha
-a---          2/6/2013  10:33 PM        179 mocha.cmd
-a---          2/6/2013  10:33 PM        272 _mocha
-a---          2/6/2013  10:33 PM        181 _mocha.cmd


    Directory: C:\Users\George\AppData\Roaming\npm\node_modules\mocha-phantomjs\node_modules\mocha\node_modules\.bin


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          2/6/2013  10:33 PM        266 jade
-a---          2/6/2013  10:33 PM        175 jade.cmd

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.