nathanboktae / mocha-phantomjs

:coffee: :ghost: Run client-side mocha tests in the command line through phantomjs
MIT License
954 stars 112 forks source link

Failed to start mocha. #1

Closed mrdevinmob closed 12 years ago

mrdevinmob commented 12 years ago

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_

metaskills commented 12 years ago

Hmmm, that should work, I bet it is your version of Mocha.js? I have only developed and tested this with version 1.4.2. Can you try that one and let me know?

mrdevinmob commented 12 years ago

I just tried 1.4.2 and I sitll get this error

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.
metaskills commented 12 years ago

Hmmm, so I was looking at my npm installed mocha and it appears that the mocha/mocha.js is different from mocha/lib/mocha.js. I wonder why?

mrdevinmob commented 12 years ago

odd, I see the smae thing but have no explanation, yet.

mrdevinmob commented 12 years ago

it is required in index.js

mrdevinmob commented 12 years ago

I am runing phantomjs mocha-phantomjs.coffee http://localhost:8080/test.html spec

from root and node_modulles/ is also in root with the mocha-phantomjs files

BUT

my test are in public/js/test/

could this be causing a problem ?

metaskills commented 12 years ago

That should be fine. I think the only issue is requiring the mocha.js which is build for the browser. It resides right next to mocha.css. Perhaps the mocha.js you put in your vendor folder could be swapped out?

mrdevinmob commented 12 years ago

Great thanks!

Worked like a charm.

metaskills commented 12 years ago

NP, thanks for taking the time too. I need to find out the differences between the two mocha.js files and make a note our documentation. I just made a issue for myself to followup on that in #2