gpt4 book ai didi

angularjs - 警告 [PhantomJS 1.9.8 (Mac OS X)] : Disconnected (1 times), 因为在 10000 毫秒内没有消息

转载 作者:行者123 更新时间:2023-12-04 16:09:08 25 4
gpt4 key购买 nike

我的项目是 ionic-angularjs-requirejs
我的环境是 Mac OS X 10.10.1, node v0.10.30

我想将 karma 测试集成到我的项目中,但是当我运行 grunt test 时这是错误的:

结果:

Running "karma:unit" (karma) task

INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket UhgMIttDejE4Xdm8I7mG with id 52208731
WARN [PhantomJS 1.9.8 (Mac OS X)]: Disconnected (1 times), because no message in 10000 ms.

Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

这是我的 package.json 中的依赖项:
"grunt-bower-requirejs": "^1.1.1",
"grunt-contrib-uglify": "^0.2.7",
"grunt-karma": "^0.9.0",
"karma": "^0.12.28",
"karma-jasmine": "^0.3.2",
"karma-phantomjs-launcher": "^0.1.4",
"karma-requirejs": "^0.2.2",
"requirejs": "^2.1.15"

这是我的 Gruntfile.js:
module.exports = function (grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
bower: {
target: {
rjsConfig: 'js/main.js'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'src/<%= pkg.name %>.js',
dest: 'build/<%= pkg.name %>.min.js'
},
},
karma: {
unit: {
options: {
frameworks: ['jasmine', 'requirejs'],
browsers: ['PhantomJS'],
autoWatch: true,
singleRun: true,
files: [
'lib/js/generated/angular/angular.js',
'lib/js/generated/angular-mocks/angular-mocks.js',
//'js/**/*.js',
//'templates/**/*.html',
'tests/*.tests.js'
],
exclude: [
'js/main.js'
]
}
}
}
});

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-bower-requirejs');
grunt.loadNpmTasks('grunt-karma');

// Tell Grunt what to do when we type "grunt" into the terminal
grunt.registerTask('default', [
'uglify',
'bower'
]);
grunt.registerTask('test', [
'karma'
]);

};

最佳答案

我使用 grunt-karma 插件的经验是,我花在调试插件上的时间比在我的实际站点上花费的时间多。我的解决方案是完全避免它并使用 grunt-exec 运行我的 karma 命令,或者只是不使用 grunt 并在新选项卡中手动运行 karma。

grunt.loadNpmTasks('grunt-exec');
var config =
{
exec: {
karma : 'karma start {path to your karma.conf.js file}'
// or
// karma : 'karma run {path to your karma.conf.js file}'
}
}

我知道这可能不是您正在寻找的答案,但我的经验使我明白,您从原始程序中获得的每一步都只是一个额外的程序,您必须调试它而不是您自己的程序。

话虽如此,
您的文件似乎没有被包含在内。

我通常将 karma 配置文件分解为单独的文件:

配置/files.js
module.exports = [
'public/lib/angular/angular.js',
'public/lib/lodash/dist/lodash.compat.js',
'public/lib/jquery/dist/jquery.js',
'public/lib/angular-ui-router/release/angular-ui-router.js',
'tests/test-main.js',
{pattern: 'public/js/**/*.js', included: true},
{pattern: 'tests/unit/**/*.js', included: true}
];

配置/common.conf.js
var files = require('./files.js');

module.exports = {

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../',

frameworks: ['jasmine', 'requirejs'],

// list of files / patterns to load in the browser
files: files,


// list of files to exclude
exclude: [
],

// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,

coverageReporter: {
type : 'html',
dir : './tests/coverage/',
subdir: function(browser) {
"use strict";
// normalization process to keep a consistent browser name accross different
// OS
return browser.toLowerCase().split(/[ /-]/)[0];
}
},

};

配置/karma.conf.js

var commonConfig = require('./common.conf.js');
module.exports = function(config) {
"use strict";
commonConfig.reporters = ['nyan', 'growl'];
commonConfig.browsers = ['PhantomJS'];
commonConfig.captureTimeout = 60000;
commonConfig.singleRun = false;
commonConfig.logLevel = config.LOG_DEBUG;


config.set(commonConfig);
};

// commonConfig.browsers = ['PhantomJS', 'Chrome']
// commonConfig.browsers = ['PhantomJS', 'Chrome', 'Safari', 'Firefox'],

配置/build.conf.js
var commonConfig = require('./common.conf.js');

module.exports = function(config) {
"use strict";
commonConfig.reporters = ['progress'];
commonConfig.browsers = ['PhantomJS'];
commonConfig.captureTimeout = 120000;
commonConfig.singleRun = true;
commonConfig.logLevel = config.LOG_DEBUG;
config.set(commonConfig);
};

配置/test.coverage.js
var commonConfig = require('./common.conf.js');

module.exports = function(config) {
"use strict";
commonConfig.reporters = ['progress','coverage'];
commonConfig.browsers = ['PhantomJS', 'Chrome', 'Safari', 'Firefox'];
commonConfig.captureTimeout = 120000;
commonConfig.singleRun = true;
commonConfig.logLevel = config.LOG_DEBUG;
commonConfig.preprocessors = {};
commonConfig.preprocessors['./public/js/*.js'] = ['coverage'];

config.set(commonConfig);
};

这样做允许我针对不同情况运行不同的 karma 配置。

在开发时我使用:
karma 启动配置/karma.conf.js

要在所有浏览器中获得我的测试覆盖率,我将运行:
karma 开始配置/test.coverage.js

并验证我的构建是否干净作为我运行的持续集成过程的一部分
karma 开始配置/build.conf.js

使用这种方法,我可以再次使用 grunt-exec 在适当的时间运行这些命令。

关于angularjs - 警告 [PhantomJS 1.9.8 (Mac OS X)] : Disconnected (1 times), 因为在 10000 毫秒内没有消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27310184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com