2014-09-30 69 views
2

我尝试运行mocha-phantomjs和得到这个错误:摩卡phantomjs错误加载资源mocha.js

$ npm run test-phantom 

> [email protected] 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! [email protected] test-phantom: `mocha-phantomjs test/client.html` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] 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 

test/client.html文件是这样的:

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

这是相当多的来自例子README。我看到这个

  • 运行3个可能的解决方案的本地网络服务器提供摩卡和柴资源
  • 莫名其妙地告诉phantomjs在node_modules寻找我在问
  • 硬编码资源的路径资源测试页我觉得这有点难看

我可能得到的东西不好呢......

回答

1

这不是太丑陋只是做:

<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> 
+0

我最终运行的非常适合用于其他原因,但你的解决方案是我能想到的,如果我是为了避免本地服务器的最佳本地服务器,所以我接受它 – fakedrake 2014-12-12 09:17:58