我正在使用AngularJS(1.5),并且几天以来,我在运行测试时始终遇到相同的错误:
PhantomJS 1.9.8(Linux 0.0.0):已执行266个已断开连接的0(10.002秒/ 0秒)
我已经在尝试避免添加超时:
// captureTimeout: 60000,
// browserDisconnectTolerance: 3,
// browserDisconnectTimeout : 60000,
// browserNoActivityTimeout : 60000,
它可以正常工作,但是我的所有测试都失败了(之前从未失败过),并且出现了相同的错误:
PhantomJS 1.9.8 (Linux 0.0.0): Executed 266 of 266 (266 FAILED) ERROR (1 min 14.714 secs / 16.051 secs)
TypeError: 'undefined' is not an object (evaluating 'rootScope.$new')
这很奇怪,因为以前从未失败过,而且我有一段时间没有触摸任何东西。我认为一定是版本问题。
这是我的package.json和我的karma.conf.js:
任何人都有类似的问题?
谢谢!
package.json:
{
"name": "appFront",
"version": "0.0.0",
"dependencies": {},
"scripts": {
"test": "gulp test",
"postinstall": "bower install"
},
"devDependencies": {
"browser-sync": "~2.9.11",
"browser-sync-spa": "~1.0.3",
"chalk": "~1.1.1",
"del": "~2.0.2",
"eslint-plugin-angular": "~0.12.0",
"estraverse": "~4.1.0",
"gulp": "~3.9.0",
"gulp-angular-filesort": "~1.1.1",
"gulp-angular-templatecache": "~1.8.0",
"gulp-autoprefixer": "~3.0.2",
"gulp-clip-empty-files": "^0.1.2",
"gulp-cssnano": "~2.1.1",
"gulp-eslint": "~1.0.0",
"gulp-filter": "~3.0.1",
"gulp-flatten": "~0.2.0",
"gulp-htmlmin": "~1.3.0",
"gulp-inject": "~3.0.0",
"gulp-load-plugins": "~0.10.0",
"gulp-ng-annotate": "~1.1.0",
"gulp-protractor": "~2.1.0",
"gulp-rename": "~1.2.2",
"gulp-replace": "~0.5.4",
"gulp-rev": "~6.0.1",
"gulp-rev-replace": "~0.4.2",
"gulp-sass": "~2.0.4",
"gulp-shell": "^0.5.2",
"gulp-size": "~2.0.0",
"gulp-sonar": "^3.0.0",
"gulp-sourcemaps": "~1.6.0",
"gulp-uglify": "~1.4.1",
"gulp-useref": "~3.0.3",
"gulp-util": "~3.0.8",
"gulp-zip": "^3.2.0",
"http-proxy-middleware": "^0.9.1",
"karma": "0.13.22",
"karma-angular-filesort": "1.0.2",
"karma-coverage": "0.5.5",
"karma-jasmine": "0.3.8",
"karma-ng-html2js-preprocessor": "0.2.2",
"karma-phantomjs-launcher": "0.2.3",
"karma-phantomjs-shim": "1.2.0",
"lodash": "~3.10.1",
"main-bower-files": "~2.9.0",
"nexus-deployer": "^0.1.6",
"orchestrator": "^0.3.8",
"phantomjs": "1.9.20",
"uglify-save-license": "~0.4.1",
"wiredep": "~2.2.2"
},
"engines": {
"node": ">=0.10.0"
}
}
karma.conf.js:
'use strict';
var path = require('path');
var conf = require('./gulp/conf');
var _ = require('lodash');
var wiredep = require('wiredep');
var pathSrcHtml = [
path.join(conf.paths.src, '/**/*.html')
];
function listFiles() {
var wiredepOptions = _.extend({}, conf.wiredep, {
dependencies: true,
devDependencies: true
});
var patterns = wiredep(wiredepOptions).js
.concat([
path.join(conf.paths.src, '/app/**/*.module.js'),
path.join(conf.paths.src, '/app/**/*.js'),
path.join(conf.paths.src, '/assets/**/*.js'),
path.join(conf.paths.src, '/**/*.spec.js'),
path.join(conf.paths.src, '/**/*.mock.js'),
])
.concat(pathSrcHtml);
var files = patterns.map(function(pattern) {
return {
pattern: pattern
};
});
files.push({
pattern: path.join(conf.paths.src, '/assets/**/*'),
included: false,
served: true,
watched: false
});
return files;
}
module.exports = function(config) {
var configuration = {
files: listFiles(),
singleRun: true,
autoWatch: false,
ngHtml2JsPreprocessor: {
stripPrefix: conf.paths.src + '/',
moduleName: 'appFront'
},
logLevel: 'WARN',
captureTimeout: 60000,
browserDisconnectTolerance: 3,
browserDisconnectTimeout : 60000,
browserNoActivityTimeout : 60000,
frameworks: ['phantomjs-shim', 'jasmine', 'angular-filesort'],
angularFilesort: {
whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')]
},
browsers : ['PhantomJS'],
plugins : [
'karma-phantomjs-launcher',
'karma-angular-filesort',
'karma-phantomjs-shim',
'karma-coverage',
'karma-jasmine',
'karma-ng-html2js-preprocessor'
],
coverageReporter: {
dir : 'test/unit/coverage',
reporters: [
{type: 'html', subdir: 'report-html'},
{type: 'lcov', subdir: 'report-lcov', includeAllSources: true }
]
},
reporters: ['progress'],
proxies: {
'/assets/': path.join('/base/', conf.paths.src, '/assets/')
}
};
// This is the default preprocessors configuration for a usage with Karma cli
// The coverage preprocessor is added in gulp/unit-test.js only for single tests
// It was not possible to do it there because karma doesn't let us now if we are
// running a single test or not
configuration.preprocessors = {};
pathSrcHtml.forEach(function(path) {
configuration.preprocessors[path] = ['ng-html2js'];
});
// This block is needed to execute Chrome on Travis
// If you ever plan to use Chrome and Travis, you can keep it
// If not, you can safely remove it
// https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076
if(configuration.browsers[0] === 'Chrome' && process.env.TRAVIS) {
configuration.customLaunchers = {
'chrome-travis-ci': {
base: 'Chrome',
flags: ['--no-sandbox']
}
};
configuration.browsers = ['chrome-travis-ci'];
}
config.set(configuration);
};