2013-10-01 84 views
4

我想安排我的角,業力,茉莉花,phantomjs和maven的字母湯。我現在正在做一個玩具項目,爲準備融入真正的項目做準備。不能加載angular.js單元測試與業力,茉莉花,phantomjs和maven

下面是我的文件的有關名單:

./pom.xml 
./src/main/webapp/index.html 
./src/main/webapp/js/blog.js 
./src/test/webapp/js/blogSpec.js 
./src/test/webapp/js/karma.conf.js 
./src/test/webapp/js/libs/angular-mocks.js 
./src/test/webapp/js/libs/angular.js 

這裏是我的完整POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.att.cdits</groupId> 
    <artifactId>angularjsexp</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>com.kelveden</groupId> 
     <artifactId>maven-karma-plugin</artifactId> 
     <version>1.5</version> 
     <executions> 
      <execution> 
      <goals> 
       <goal>start</goal> 
      </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <configFile>${basedir}/src/test/webapp/js/karma.conf.js</configFile> 
      <browsers>PhantomJS</browsers> 
      <reporters>dots</reporters> 
      <colors>false</colors> 
      <autoWatch>false</autoWatch> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
    <dependencies> 
    <dependency> 
     <groupId>com.kelveden</groupId> 
     <artifactId>maven-karma-plugin</artifactId> 
     <version>1.5</version> 
    </dependency> 
    </dependencies> 
</project> 

而我的 「karma.conf.js」 文件:

module.exports = function(config) { 
    config.set({ 
    basePath: '', 
    frameworks: ['jasmine'], 
    files: [ 
     "../../../../src/test/webapp/js/libs/*.js", 
     "../../../../src/main/webapp/js/*.js", 
     "../../../../src/test/webapp/js/*.js" 
    ], 
    exclude: [], 
    reporters: ['dots'], 
    port: 9876, 
    colors: false, 
    logLevel: config.LOG_DEBUG, 
    autoWatch: false, 
    browsers: ['PhantomJS'], 
    captureTimeout: 60000, 
    singleRun: true 
    }); 
}; 

以下是從我的「mvn安裝」輸出摘錄,從Surefire執行開始:

[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ angularjsexp --- 
[INFO] Surefire report directory: myhome\workspace6\angularjsexp\target\surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 

Results : 

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 

[INFO] 
[INFO] --- maven-karma-plugin:1.5:start (default) @ angularjsexp --- 
cmd /C karma start myhome\workspace6\angularjsexp\src\test\webapp\js\karma.conf.js --browsers PhantomJS --reporters dots --single-run --no-auto-watch --colors false 
DEBUG [plugin]: Loading karma-* from myhome\AppData\Roaming\npm\node_modules 
DEBUG [plugin]: Loading plugin myhome\AppData\Roaming\npm\node_modules/karma-chrome-launcher. 
DEBUG [plugin]: Loading plugin myhome\AppData\Roaming\npm\node_modules/karma-coffee-preprocessor. 
DEBUG [plugin]: Loading plugin myhome\AppData\Roaming\npm\node_modules/karma-firefox-launcher. 
DEBUG [plugin]: Loading plugin myhome\AppData\Roaming\npm\node_modules/karma-html2js-preprocessor. 
DEBUG [plugin]: Loading plugin myhome\AppData\Roaming\npm\node_modules/karma-jasmine. 
DEBUG [plugin]: Loading plugin myhome\AppData\Roaming\npm\node_modules/karma-phantomjs-launcher. 
DEBUG [plugin]: Loading plugin myhome\AppData\Roaming\npm\node_modules/karma-requirejs. 
DEBUG [plugin]: Loading plugin myhome\AppData\Roaming\npm\node_modules/karma-script-launcher. 
DEBUG [plugin]: Loading inlined plugin (defining). 
INFO [karma]: Karma v0.10.2 server started at http://localhost:9876/ 
INFO [launcher]: Starting browser PhantomJS 
DEBUG [launcher]: Creating temp dir at C:\Cygwin\tmp\karma-77302282 
DEBUG [launcher]: myhome\AppData\Roaming\npm\node_modules\karma-phantomjs-launcher\node_modules\phantomjs\lib\phantom\phantomjs.exe C:\Cygwin\tmp\karma-77302282/capture.js 
DEBUG [watcher]: Excluded file "myhome/workspace6/angularjsexp/src/test/webapp/js/karma.conf.js" 
DEBUG [watcher]: Resolved files: 
    myhome/AppData/Roaming/npm/node_modules/karma-jasmine/lib/jasmine.js 
    myhome/AppData/Roaming/npm/node_modules/karma-jasmine/lib/adapter.js 
    myhome/workspace6/angularjsexp/src/test/webapp/js/libs/angular-mocks.js 
    myhome/workspace6/angularjsexp/src/test/webapp/js/libs/angular.js 
    myhome/workspace6/angularjsexp/src/main/webapp/js/blog.js 
    myhome/workspace6/angularjsexp/src/main/webapp/js/checkbox-array.js 
    myhome/workspace6/angularjsexp/src/main/webapp/js/my-include.js 
    myhome/workspace6/angularjsexp/src/test/webapp/js/blogSpec.js 
DEBUG [web-server]: serving: myhome\AppData\Roaming\npm\node_modules\karma\static/client.html 
DEBUG [web-server]: serving: myhome\AppData\Roaming\npm\node_modules\karma\static/karma.js 
DEBUG [karma]: A browser has connected on socket LI1NDCsuY-0i0Uxwkhs_ 
INFO [PhantomJS 1.9.2 (Windows 7)]: Connected on socket LI1NDCsuY-0i0Uxwkhs_ 
DEBUG [karma]: All browsers are ready, executing 
DEBUG [web-server]: serving: myhome\AppData\Roaming\npm\node_modules\karma\static/context.html 
DEBUG [web-server]: serving: myhome/AppData/Roaming/npm/node_modules/karma-jasmine/lib/adapter.js 
DEBUG [web-server]: serving: myhome/AppData/Roaming/npm/node_modules/karma-jasmine/lib/jasmine.js 
DEBUG [web-server]: serving: myhome/workspace6/angularjsexp/src/test/webapp/js/libs/angular.js 
DEBUG [web-server]: serving: myhome/workspace6/angularjsexp/src/main/webapp/js/checkbox-array.js 
DEBUG [web-server]: serving: myhome/workspace6/angularjsexp/src/main/webapp/js/blog.js 
DEBUG [web-server]: serving: myhome/workspace6/angularjsexp/src/main/webapp/js/my-include.js 
DEBUG [web-server]: serving: myhome/workspace6/angularjsexp/src/test/webapp/js/blogSpec.js 
DEBUG [web-server]: serving: myhome/workspace6/angularjsexp/src/test/webapp/js/libs/angular-mocks.js 
PhantomJS 1.9.2 (Windows 7) ERROR 
    ReferenceError: Can't find variable: angular 
    at myhome/workspace6/angularjsexp/src/test/webapp/js/libs/angular-mocks.js:16 
PhantomJS 1.9.2 (Windows 7) ERROR 
    ReferenceError: Can't find variable: myApp 
    at myhome/workspace6/angularjsexp/src/main/webapp/js/checkbox-array.js:1 
PhantomJS 1.9.2 (Windows 7) ERROR 
    ReferenceError: Can't find variable: myApp 
    at myhome/workspace6/angularjsexp/src/main/webapp/js/my-include.js:1 
PhantomJS 1.9.2 (Windows 7) ERROR 
    ReferenceError: Can't find variable: module 
    at myhome/workspace6/angularjsexp/src/test/webapp/js/blogSpec.js:5 
PhantomJS 1.9.2 (Windows 7): Executed 0 of 0 ERROR (0.273 secs/0 secs) 

我有以下問題,到目前爲止,一些煩惱,一些受體阻滯劑: *這很奇怪的是業力解析相對於在那裏找到了我的conf文件的文件路徑的引用,我希望我能重寫。 *看起來,Surefire在Karma之前開火。是否有可能整合這些? *我對腳本中的「angular」和其他對象的引用顯然是失敗的。我不明白如何解決這個問題。

回答

12

感謝有關karma-users討論組的人,我發現從「文件」加載的文件必須按正確的順序加載。例如,我需要指定「../../../../src/test/webapp/js/libs/angular.js」,然後是「../../../../src/test/webapp/js/libs/angular-mocks.js」,而不是「../../../../src/test/webapp/js/libs/*.js」。

我仍然必須弄清楚如何正確整合Surefire,但我會單獨詢問。

7

我一直在測試Angular與Karma和Jasmine,最後它的工作原理!我的例子比你的簡單得多,但也許它可以幫助你。我有角的兩個文件的應用程序:

  • controllers.js
  • application.js

而對角以下文件:

  • angular.js
  • angular-mocks.js
  • angular-route.js

我已經編輯手動karma.config.js,我已經把路線的文件,而不是因爲它在一個具體的順序,因此最後的噶有序文件列表是:

// list of files/patterns to load in the browser 
files: [ 
    'js/libs/angular.js', 
    'js/libs/angular-mocks.js', 
    'js/libs/angular-route.js', 
    'js/controllers.js', 
    'js/application.js', 
    'spec/*.spec.js' 
], 

// list of files to exclude 
exclude: [ 
    'karma.config.js' 
], 

我的目錄樹:

  • karma.config.js
  • /JS
    • 申請。JS
    • controllers.js
    • /庫
      • angular.js
      • 角mocks.js
      • 角route.js
  • /規格
    • application.spec.js

而且我測試根文件夾中的Karma與$ karma start karma.config.js

希望這會有所幫助