2

I try to run mocha-phantomjs and get this error:

$ npm run test-phantom

> selenium-test@0.0.5 test-phantom /path/to/project/
> mocha-phantomjs test/client.html

Error loading resource file:///path/to/project//test/mocha.css (203). Details: Error opening /path/to/project//test/mocha.css: No such file or directory
Error loading resource file:///path/to/project//test/mocha.js (203). Details: Error opening /path/to/project//test/mocha.js: No such file or directory
Error loading resource file:///path/to/project//test/chai.js (203). Details: Error opening /path/to/project//test/chai.js: No such file or directory
TypeError: 'undefined' is not a function (evaluating 'mocha.ui('bdd')')

  file:///path/to/project//test/client.html:11

npm ERR! Linux 3.16.3-1-ARCH
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "test-phantom"
npm ERR! node v0.10.32
npm ERR! npm  v2.1.1
npm ERR! code ELIFECYCLE
npm ERR! selenium-test@0.0.5 test-phantom: `mocha-phantomjs test/client.html`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the selenium-test@0.0.5 test-phantom script.
npm ERR! This is most likely a problem with the selenium-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     mocha-phantomjs test/client.html
npm ERR! You can get their info via:
npm ERR!     npm owner ls selenium-test
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /path/to/project/npm-debug.log

The test/client.html file is this:

<html>
  <head>
    <meta charset="utf-8">
    <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');
      mocha.reporter('html');
      assert = chai.assert;
    </script>
    <script>
      if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
      else { mocha.run(); }
    </script>
  </body>
</html>

Which is pretty much the example from the README. I see 3 possible solutions to this

  • run a local webserver to provide mocha and chai resources
  • somehow tell phantomjs to look in node_modules for the resources I ask for
  • Hardcode the paths of the resources in the test page which I find a bit ugly

I am probably getting something wrong about this...

fakedrake
  • 6,528
  • 8
  • 41
  • 64

1 Answers1

1

It's not too ugly to just do:

<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
...
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
Brandon Horst
  • 1,921
  • 16
  • 26
  • I ended up running a local server which fits well for other reasons but your solution is the best I can think of if I were to avoid the local server, so I am accepting it – fakedrake Dec 12 '14 at 09:17