我正在尝试安排我的 angular、karma、jasmine、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 install”输出的摘录,从 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 之前开火。有没有可能整合这些?* 我在脚本中对“角度”和其他对象的引用显然失败了。我不明白如何解决这个问题。