业力测试在本地通过但在 Angular 中使用 Travis CI 失败
karma tests passing in local but failing with Travis CI in Angular
我正在尝试将 Travis CI 用于我的 Angular 项目。我设置了一个在本地通过的单元测试,但我在 Travis CI 中失败了。
我不确定我在本地获取的 Travis 中是否缺少任何组件。由于在 Heroku 中部署,我需要使用一些使用 Bower 安装的组件。但是,我在 Travis 中调用 bower install,因此这些组件在测试时应该可用。
我已经研究过这个问题,但在 SO 或其他地方找不到任何类似的问题。
感谢任何帮助。
我的 package.json 的依赖项是:
"dependencies": {
"bower": "^1.7.9",
"express": "^4.13.4",
"http-server": "^0.9.0",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-chrome-launcher": "^1.0.1",
"karma-cli": "^1.0.0",
"karma-jasmine": "^1.0.2",
"protractor": "^3.3.0"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-protractor-runner": "^3.2.0",
"grunt-protractor-webdriver": "^0.2.5",
"karma": "^0.13.22",
"karma-firefox-launcher": "^1.0.0",
"karma-jasmine": "^1.0.2"
}
我在 bower.json 中的依赖项是:
"dependencies": {
"angular": "^1.5.5",
"angular-mocks": "^1.5.5",
"oauth-signature": "^1.3.1"
}
我的karma.conf.js文件如下:
module.exports = function(config){
config.set({
basePath: '../',
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/bower_components/angular-route/angular-route.js',
'app/env.js',
'app/js/app.js',
'app/js/**/*.js',
'test/unit/**/*.js',
],
singleRun: true,
autoWatch: true,
frameworks: ['jasmine'],
browsers: ['Firefox'],
plugins: [
'karma-firefox-launcher',
'karma-jasmine'
]
});
};
本地通过的测试是:
describe('resultsFactory', function() {
beforeEach(module('summerApp'));
var result;
beforeEach(inject(function(resultsFactory) {
result = new resultsFactory('location');
}));
it('location is available', function(){
expect(result.location).toEqual('location');
});
});
和我的.travis.yml如下:
language: node_js
node_js:
- "6"
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
install:
- npm install
- bower install
script:
- npm run test-single
package.json 中的脚本测试单是
karma start test/karma.conf.js --single-run
最后,我在 Travis CI 中得到的错误是:
> karma start test/karma.conf.js --single-run
11 06 2016 18:46:48.521:WARN [watcher]: Pattern "/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular-route/angular-route.js" does not match any file.
11 06 2016 18:46:48.566:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
11 06 2016 18:46:48.572:INFO [launcher]: Starting browser Firefox
11 06 2016 18:46:50.357:INFO [Firefox 31.0.0 (Linux 0.0.0)]: Connected on socket /#ebdoQGJ5-EkK88VnAAAA with id 72213403
Firefox 31.0.0 (Linux 0.0.0): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
Firefox 31.0.0 (Linux 0.0.0) resultsFactory location is available FAILED
minErr/<@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular/angular.js:68:5
loadModules/<@/home/travis/build/tigretoncio/I-know-what-you-will-do-this- summer/app/bower_components/angular/angular.js:4631:1
forEach@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular/angular.js:322:11
loadModules@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular/angular.js:4591:5
createInjector@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular/angular.js:4513:7
workFn@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular-mocks/angular-mocks.js:3060:9
TypeError: result is undefined in /home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/test/unit/resultsFactory.spec.js (line 12)
@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/test/unit/resultsFactory.spec.js:12:5
Firefox 31.0.0 (Linux 0.0.0): Executed 1 of 1 (1 FAILED) (0 secs / 0.019 secs)
(1 FAILED) ERROR (0.006 secs / 0.019 secs)
npm ERR! Linux 3.13.0-40-generic
npm ERR! argv "/home/travis/.nvm/versions/node/v6.2.1/bin/node" "/home/travis/.nvm/versions/node/v6.2.1/bin/npm" "run" "test-single"
npm ERR! node v6.2.1
npm ERR! npm v3.9.3
npm ERR! code ELIFECYCLE
npm ERR! summer@0.1.0 test-single: `karma start test/karma.conf.js --single-run`
npm ERR! Exit status 1
查看错误消息,Travis 无法找到 angular-route,因为它未作为依赖项包含在您的 bower.json 中。
我正在尝试将 Travis CI 用于我的 Angular 项目。我设置了一个在本地通过的单元测试,但我在 Travis CI 中失败了。
我不确定我在本地获取的 Travis 中是否缺少任何组件。由于在 Heroku 中部署,我需要使用一些使用 Bower 安装的组件。但是,我在 Travis 中调用 bower install,因此这些组件在测试时应该可用。
我已经研究过这个问题,但在 SO 或其他地方找不到任何类似的问题。
感谢任何帮助。
我的 package.json 的依赖项是:
"dependencies": {
"bower": "^1.7.9",
"express": "^4.13.4",
"http-server": "^0.9.0",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-chrome-launcher": "^1.0.1",
"karma-cli": "^1.0.0",
"karma-jasmine": "^1.0.2",
"protractor": "^3.3.0"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-protractor-runner": "^3.2.0",
"grunt-protractor-webdriver": "^0.2.5",
"karma": "^0.13.22",
"karma-firefox-launcher": "^1.0.0",
"karma-jasmine": "^1.0.2"
}
我在 bower.json 中的依赖项是:
"dependencies": {
"angular": "^1.5.5",
"angular-mocks": "^1.5.5",
"oauth-signature": "^1.3.1"
}
我的karma.conf.js文件如下:
module.exports = function(config){
config.set({
basePath: '../',
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/bower_components/angular-route/angular-route.js',
'app/env.js',
'app/js/app.js',
'app/js/**/*.js',
'test/unit/**/*.js',
],
singleRun: true,
autoWatch: true,
frameworks: ['jasmine'],
browsers: ['Firefox'],
plugins: [
'karma-firefox-launcher',
'karma-jasmine'
]
});
};
本地通过的测试是:
describe('resultsFactory', function() {
beforeEach(module('summerApp'));
var result;
beforeEach(inject(function(resultsFactory) {
result = new resultsFactory('location');
}));
it('location is available', function(){
expect(result.location).toEqual('location');
});
});
和我的.travis.yml如下:
language: node_js
node_js:
- "6"
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
install:
- npm install
- bower install
script:
- npm run test-single
package.json 中的脚本测试单是
karma start test/karma.conf.js --single-run
最后,我在 Travis CI 中得到的错误是:
> karma start test/karma.conf.js --single-run
11 06 2016 18:46:48.521:WARN [watcher]: Pattern "/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular-route/angular-route.js" does not match any file.
11 06 2016 18:46:48.566:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
11 06 2016 18:46:48.572:INFO [launcher]: Starting browser Firefox
11 06 2016 18:46:50.357:INFO [Firefox 31.0.0 (Linux 0.0.0)]: Connected on socket /#ebdoQGJ5-EkK88VnAAAA with id 72213403
Firefox 31.0.0 (Linux 0.0.0): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
Firefox 31.0.0 (Linux 0.0.0) resultsFactory location is available FAILED
minErr/<@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular/angular.js:68:5
loadModules/<@/home/travis/build/tigretoncio/I-know-what-you-will-do-this- summer/app/bower_components/angular/angular.js:4631:1
forEach@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular/angular.js:322:11
loadModules@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular/angular.js:4591:5
createInjector@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular/angular.js:4513:7
workFn@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/app/bower_components/angular-mocks/angular-mocks.js:3060:9
TypeError: result is undefined in /home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/test/unit/resultsFactory.spec.js (line 12)
@/home/travis/build/tigretoncio/I-know-what-you-will-do-this-summer/test/unit/resultsFactory.spec.js:12:5
Firefox 31.0.0 (Linux 0.0.0): Executed 1 of 1 (1 FAILED) (0 secs / 0.019 secs)
(1 FAILED) ERROR (0.006 secs / 0.019 secs)
npm ERR! Linux 3.13.0-40-generic
npm ERR! argv "/home/travis/.nvm/versions/node/v6.2.1/bin/node" "/home/travis/.nvm/versions/node/v6.2.1/bin/npm" "run" "test-single"
npm ERR! node v6.2.1
npm ERR! npm v3.9.3
npm ERR! code ELIFECYCLE
npm ERR! summer@0.1.0 test-single: `karma start test/karma.conf.js --single-run`
npm ERR! Exit status 1
查看错误消息,Travis 无法找到 angular-route,因为它未作为依赖项包含在您的 bower.json 中。